Skip to content

Commit ef10981

Browse files
committed
Update docs for data loading
1 parent 0db2e16 commit ef10981

File tree

3 files changed

+57
-50
lines changed

3 files changed

+57
-50
lines changed

README.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,33 +54,34 @@ With libcachesim installed, you can start cache simulation for some eviction alg
5454
```python
5555
import libcachesim as lcs
5656

57-
# Step 1: Get one trace from S3 bucket
58-
URI = "cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
59-
dl = lcs.DataLoader()
60-
dl.load(URI)
61-
62-
# Step 2: Open trace and process efficiently
57+
# Step 1: Open a trace hosted on S3 (find more via https://github.com/cacheMon/cache_dataset)
58+
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
6359
reader = lcs.TraceReader(
64-
trace = dl.get_cache_path(URI),
60+
trace = URI,
6561
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
6662
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
6763
)
6864

69-
# Step 3: Initialize cache
70-
cache = lcs.S3FIFO(cache_size=1024*1024)
65+
# Step 2: Initialize cache
66+
cache = lcs.S3FIFO(
67+
cache_size=1024*1024,
68+
# Cache specific parameters
69+
small_size_ratio=0.2,
70+
ghost_size_ratio=0.8,
71+
move_to_main_threshold=2,
72+
)
7173

72-
# Step 4: Process entire trace efficiently (C++ backend)
73-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
74-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
74+
# Step 3: Process entire trace efficiently (C++ backend)
75+
req_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
76+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
7577

76-
# Step 4.1: Process with limited number of requests
77-
cache = lcs.S3FIFO(cache_size=1024*1024)
78-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(
78+
# Step 3.1: Further process the first 1000 requests again
79+
req_miss_ratio, byte_miss_ratio = cache.process_trace(
7980
reader,
8081
start_req=0,
8182
max_req=1000
8283
)
83-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
84+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
8485
```
8586

8687
## Plugin System

docs/src/en/getting_started/quickstart.md

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,33 +56,34 @@ With libcachesim installed, you can start cache simulation for some eviction alg
5656
```python
5757
import libcachesim as lcs
5858

59-
# Step 1: Get one trace from S3 bucket
60-
URI = "cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
61-
dl = lcs.DataLoader()
62-
dl.load(URI)
63-
64-
# Step 2: Open trace and process efficiently
59+
# Step 1: Open a trace hosted on S3 (find more via https://github.com/cacheMon/cache_dataset)
60+
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
6561
reader = lcs.TraceReader(
66-
trace = dl.get_cache_path(URI),
62+
trace = URI,
6763
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
6864
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
6965
)
7066

71-
# Step 3: Initialize cache
72-
cache = lcs.S3FIFO(cache_size=1024*1024)
67+
# Step 2: Initialize cache
68+
cache = lcs.S3FIFO(
69+
cache_size=1024*1024,
70+
# Cache specific parameters
71+
small_size_ratio=0.2,
72+
ghost_size_ratio=0.8,
73+
move_to_main_threshold=2,
74+
)
7375

74-
# Step 4: Process entire trace efficiently (C++ backend)
75-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
76-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
76+
# Step 3: Process entire trace efficiently (C++ backend)
77+
req_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
78+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
7779

78-
# Step 4.1: Process with limited number of requests
79-
cache = lcs.S3FIFO(cache_size=1024*1024)
80-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(
80+
# Step 3.1: Further process the first 1000 requests again
81+
req_miss_ratio, byte_miss_ratio = cache.process_trace(
8182
reader,
8283
start_req=0,
8384
max_req=1000
8485
)
85-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
86+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
8687
```
8788

8889
The above example demonstrates the basic workflow of using `libcachesim` for cache simulation:

examples/basic_usage.py

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,30 @@
11
import libcachesim as lcs
22

3-
# Step 1: Get one trace from S3 bucket
4-
URI = "cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
5-
dl = lcs.DataLoader()
6-
dl.load(URI)
7-
8-
# Step 2: Open trace and process efficiently
3+
# Step 1: Open a trace hosted on S3 (find more via https://github.com/cacheMon/cache_dataset)
4+
URI = "s3://cache-datasets/cache_dataset_oracleGeneral/2007_msr/msr_hm_0.oracleGeneral.zst"
95
reader = lcs.TraceReader(
10-
trace=dl.get_cache_path(URI),
11-
trace_type=lcs.TraceType.ORACLE_GENERAL_TRACE,
12-
reader_init_params=lcs.ReaderInitParam(ignore_obj_size=False),
6+
trace = URI,
7+
trace_type = lcs.TraceType.ORACLE_GENERAL_TRACE,
8+
reader_init_params = lcs.ReaderInitParam(ignore_obj_size=False)
139
)
1410

15-
# Step 3: Initialize cache
16-
cache = lcs.S3FIFO(cache_size=1024 * 1024)
11+
# Step 2: Initialize cache
12+
cache = lcs.S3FIFO(
13+
cache_size=1024*1024,
14+
# Cache specific parameters
15+
small_size_ratio=0.2,
16+
ghost_size_ratio=0.8,
17+
move_to_main_threshold=2,
18+
)
1719

18-
# Step 4: Process entire trace efficiently (C++ backend)
19-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
20-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
20+
# Step 3: Process entire trace efficiently (C++ backend)
21+
req_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
22+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
2123

22-
# Step 4.1: Process with limited number of requests
23-
cache = lcs.S3FIFO(cache_size=1024 * 1024)
24-
obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader, start_req=0, max_req=1000)
25-
print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
24+
# Step 3.1: Further process the first 1000 requests again
25+
req_miss_ratio, byte_miss_ratio = cache.process_trace(
26+
reader,
27+
start_req=0,
28+
max_req=1000
29+
)
30+
print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")

0 commit comments

Comments
 (0)