@@ -56,33 +56,37 @@ 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)
73-
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}")
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+ )
7775
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(
81- reader,
82- start_req=0,
83- max_req=1000
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}")
79+
80+ # Step 3.1: Further process the first 1000 requests again
81+ cache = lcs.S3FIFO(
82+ cache_size=1024 * 1024,
83+ # Cache specific parameters
84+ small_size_ratio=0.2,
85+ ghost_size_ratio=0.8,
86+ move_to_main_threshold=2,
8487 )
85- print(f"Object miss ratio: {obj_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
88+ req_miss_ratio, byte_miss_ratio = cache.process_trace(reader, start_req=0, max_req=1000)
89+ print(f"Request miss ratio: {req_miss_ratio:.4f}, Byte miss ratio: {byte_miss_ratio:.4f}")
8690 ```
8791
8892The above example demonstrates the basic workflow of using ` libcachesim ` for cache simulation:
0 commit comments