@@ -11,7 +11,7 @@ A high-performance library for building and running cache simulations
1111---
1212
1313[ ![ build] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/build.yml/badge.svg )] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/build.yml )
14- [ ![ Python Release] ( https://github.com/1a1a11a /libCacheSim/actions/workflows/pypi-release.yml/badge.svg )] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/pypi-release.yml )
14+ [ ![ Python Release] ( https://github.com/cacheMon /libCacheSim-python /actions/workflows/pypi-release.yml/badge.svg )] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/pypi-release.yml )
1515[ ![ NPM Release] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/npm-release.yml/badge.svg )] ( https://github.com/1a1a11a/libCacheSim/actions/workflows/npm-release.yml )
1616[ ![ OpenSSF Scorecard] ( https://api.scorecard.dev/projects/github.com/1a1a11a/libCacheSim/badge )] ( https://scorecard.dev/viewer/?uri=github.com/1a1a11a/libCacheSim )
1717
@@ -291,12 +291,14 @@ If you are not extremely sensitive to the performance, our python binding can of
291291pip install libcachesim
292292```
293293
294+
295+
294296### Simulation with python
295297
296298``` python
297299import libcachesim as lcs
298300
299- reader = lcs.create_zipf_requests (num_objects = 1000 , num_requests = 10000 ) # synthetic trace
301+ reader = lcs.SyntheticReader (num_objects = 1000 , num_of_req = 10000 ) # synthetic trace
300302# reader = lcs.open_trace("./data/cloudPhysicsIO.oracleGeneral.bin") # real trace
301303cache = lcs.FIFO(cache_size = 1024 * 1024 )
302304obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
@@ -310,42 +312,30 @@ With python package, you can extend new algorithm to test your own eviction desi
310312<summary > See an example below </summary >
311313
312314``` python
313- import libcachesim as lcs
314- from collections import deque
315- from contextlib import suppress
316-
317- cache = lcs.PythonHookCachePolicy(cache_size = 1024 , cache_name = " CustomFIFO" )
318-
319- def init_hook (cache_size ):
320- return deque() # Use deque for FIFO order
321-
322- def hit_hook (fifo_queue , obj_id , obj_size ):
323- pass # FIFO doesn't reorder on hit
324-
325- def miss_hook (fifo_queue , obj_id , obj_size ):
326- fifo_queue.append(obj_id) # Add to end of queue
327-
328- def eviction_hook (fifo_queue , obj_id , obj_size ):
329- return fifo_queue[0 ] # Return first item (oldest)
330-
331- def remove_hook (fifo_queue , obj_id ):
332- with suppress(ValueError ):
333- fifo_queue.remove(obj_id)
334-
335- # Set the hooks and test
336- cache.set_hooks(init_hook, hit_hook, miss_hook, eviction_hook, remove_hook)
337-
338- reader = lcs.open_trace(
339- trace_path = " ./data/cloudPhysicsIO.oracleGeneral.bin" ,
340- params = lcs.ReaderInitParam(ignore_obj_size = True )
315+ from collections import OrderedDict
316+ from libcachesim import PluginCache, LRU
317+
318+ plugin_lru_cache = PluginCache(
319+ cache_size = 128 ,
320+ cache_name = " LRU" ,
321+ cache_init_hook = lambda _ : OrderedDict(),
322+ cache_hit_hook = lambda data , req : data.move_to_end(req.obj_id, last = True ) if req.obj_id in data else None ,
323+ cache_miss_hook = lambda data , req : data.__setitem__ (req.obj_id, req.obj_size),
324+ cache_eviction_hook = lambda data , _ : data.popitem(last = False )[0 ],
325+ cache_remove_hook = lambda data , obj_id : data.pop(obj_id, None ),
326+ cache_free_hook = lambda data : data.clear(),
341327)
342- obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
343- print (f " Obj miss ratio: { obj_miss_ratio:.4f } , byte miss ratio: { byte_miss_ratio:.4f } " )
328+
329+ reader = lcs.SyntheticReader(num_objects = 1000 , num_of_req = 10000 , obj_size = 1 )
330+ req_miss_ratio, byte_miss_ratio = plugin_lru_cache.process_trace(reader)
331+ ref_req_miss_ratio, ref_byte_miss_ratio = LRU(128 ).process_trace(reader)
332+ print (f " plugin req miss ratio { req_miss_ratio} , ref req miss ratio { ref_req_miss_ratio} " )
333+ print (f " plugin byte miss ratio { byte_miss_ratio} , ref byte miss ratio { ref_byte_miss_ratio} " )
344334```
345335
346336</details >
347337
348- See more information in [ README.md] ( ./ libCacheSim-python/README.md ) of the Python binding.
338+ See more information in [ README.md] ( https://github.com/cacheMon/ libCacheSim-python) of the Python binding.
349339
350340---
351341## Open source cache traces
0 commit comments