Skip to content

Commit e8a7194

Browse files
authored
[CLEANUP]: Detach python binding code to individual repo (#284)
* [CLEANUP]: Detach python binding code to individual repo * Refine LRU plugin example * Add dist info in examples using synthetic reader
1 parent 4a2627d commit e8a7194

33 files changed

Lines changed: 39 additions & 5531 deletions

.github/workflows/pypi-release.yml

Lines changed: 0 additions & 149 deletions
This file was deleted.

.github/workflows/python.yml

Lines changed: 0 additions & 41 deletions
This file was deleted.

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,6 @@ else()
255255
message(STATUS "Building without test")
256256
endif()
257257

258-
# Export variables for scikit-build -> build/export_vars.cmake
259-
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/libCacheSim-python/export)
260-
261258
# libCacheSim unified library compilation and installation
262259
# Create a single library that combines all modular libraries
263260
add_library(${PROJECT_NAME} STATIC

README.md

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 +291,16 @@ If you are not extremely sensitive to the performance, our python binding can of
291291
pip install libcachesim
292292
```
293293

294+
295+
294296
### Simulation with python
295297

296298
```python
297-
import libcachesim as lcs
299+
from libcachesim import SyntheticReader, TraceReader, FIFO
298300

299-
reader = lcs.create_zipf_requests(num_objects=1000, num_requests=10000) # synthetic trace
300-
# reader = lcs.open_trace("./data/cloudPhysicsIO.oracleGeneral.bin") # real trace
301-
cache = lcs.FIFO(cache_size=1024*1024)
301+
reader = SyntheticReader(num_objects=1000, num_of_req=10000, alpha=1.0, dist="zipf") # synthetic trace
302+
# reader = TraceReader("./data/cloudPhysicsIO.oracleGeneral.bin") # real trace
303+
cache = FIFO(cache_size=1024*1024)
302304
obj_miss_ratio, byte_miss_ratio = cache.process_trace(reader)
303305
print(f"Obj miss ratio: {obj_miss_ratio:.4f}, byte miss ratio: {byte_miss_ratio:.4f}")
304306
```
@@ -310,42 +312,51 @@ 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
315+
from collections import OrderedDict
316+
from typing import Any
317+
318+
from libcachesim import PluginCache, LRU, CommonCacheParams, Request
316319

317-
cache = lcs.PythonHookCachePolicy(cache_size=1024, cache_name="CustomFIFO")
320+
def init_hook(_: CommonCacheParams) -> Any:
321+
return OrderedDict()
318322

319-
def init_hook(cache_size):
320-
return deque() # Use deque for FIFO order
323+
def hit_hook(data: Any, req: Request) -> None:
324+
data.move_to_end(req.obj_id, last=True)
321325

322-
def hit_hook(fifo_queue, obj_id, obj_size):
323-
pass # FIFO doesn't reorder on hit
326+
def miss_hook(data: Any, req: Request) -> None:
327+
data.__setitem__(req.obj_id, req.obj_size)
324328

325-
def miss_hook(fifo_queue, obj_id, obj_size):
326-
fifo_queue.append(obj_id) # Add to end of queue
329+
def eviction_hook(data: Any, _: Request) -> int:
330+
return data.popitem(last=False)[0]
327331

328-
def eviction_hook(fifo_queue, obj_id, obj_size):
329-
return fifo_queue[0] # Return first item (oldest)
332+
def remove_hook(data: Any, obj_id: int) -> None:
333+
data.pop(obj_id, None)
330334

331-
def remove_hook(fifo_queue, obj_id):
332-
with suppress(ValueError):
333-
fifo_queue.remove(obj_id)
335+
def free_hook(data: Any) -> None:
336+
data.clear()
334337

335-
# Set the hooks and test
336-
cache.set_hooks(init_hook, hit_hook, miss_hook, eviction_hook, remove_hook)
337338

338-
reader = lcs.open_trace(
339-
trace_path="./data/cloudPhysicsIO.oracleGeneral.bin",
340-
params=lcs.ReaderInitParam(ignore_obj_size=True)
339+
plugin_lru_cache = PluginCache(
340+
cache_size=128,
341+
cache_init_hook=init_hook,
342+
cache_hit_hook=hit_hook,
343+
cache_miss_hook=miss_hook,
344+
cache_eviction_hook=eviction_hook,
345+
cache_remove_hook=remove_hook,
346+
cache_free_hook=free_hook,
347+
cache_name="Plugin_LRU",
341348
)
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}")
349+
350+
reader = lcs.SyntheticReader(num_objects=1000, num_of_req=10000, obj_size=1, alpha=1.0, dist="zipf")
351+
req_miss_ratio, byte_miss_ratio = plugin_lru_cache.process_trace(reader)
352+
ref_req_miss_ratio, ref_byte_miss_ratio = LRU(128).process_trace(reader)
353+
print(f"plugin req miss ratio {req_miss_ratio}, ref req miss ratio {ref_req_miss_ratio}")
354+
print(f"plugin byte miss ratio {byte_miss_ratio}, ref byte miss ratio {ref_byte_miss_ratio}")
344355
```
345356

346357
</details>
347358

348-
See more information in [README.md](./libCacheSim-python/README.md) of the Python binding.
359+
See more information in [README.md](https://github.com/cacheMon/libCacheSim-python) of the Python binding.
349360

350361
---
351362
## Open source cache traces

libCacheSim-python/.gitignore

Lines changed: 0 additions & 59 deletions
This file was deleted.

0 commit comments

Comments
 (0)