|
| 1 | +# libCacheSim Node.js Bindings |
| 2 | + |
| 3 | +Node.js bindings for libCacheSim - A high-performance cache simulator and analysis library supporting LRU, FIFO, S3-FIFO, Sieve and other caching algorithms. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **High Performance**: Built on the optimized libCacheSim C library |
| 8 | +- **Multiple Algorithms**: Support for LRU, FIFO, LFU, ARC, Clock, S3-FIFO, Sieve, and more |
| 9 | +- **Various Trace Types**: Support for vscsi, csv, txt, binary, and oracle trace formats |
| 10 | +- **Pre-compiled Binaries**: Fast installation with no build tools required |
| 11 | +- **Cross-platform**: Support for Linux (x64) and macOS (x64, ARM64) |
| 12 | + |
| 13 | +## Installation |
| 14 | + |
| 15 | +```bash |
| 16 | +npm install libcachesim-node |
| 17 | +``` |
| 18 | + |
| 19 | +The package includes pre-compiled binaries for supported platforms. No additional build tools or dependencies are required for end users. |
| 20 | + |
| 21 | +### Supported Platforms |
| 22 | + |
| 23 | +- **Linux**: x64 (Ubuntu 18.04+, other distributions with compatible glibc) |
| 24 | +- **macOS**: x64 (Intel) and ARM64 (Apple Silicon) |
| 25 | + |
| 26 | +If pre-compiled binaries are not available for your platform, please check the releases page for updates or submit an issue. |
| 27 | + |
| 28 | +## Quick Start |
| 29 | + |
| 30 | +```javascript |
| 31 | +const { runSimulation, getSupportedAlgorithms } = require('libcachesim-node'); |
| 32 | + |
| 33 | +// Get supported algorithms |
| 34 | +console.log('Supported algorithms:', getSupportedAlgorithms()); |
| 35 | + |
| 36 | +// Run a cache simulation |
| 37 | +const result = runSimulation( |
| 38 | + '/path/to/trace.vscsi', // Path to trace file |
| 39 | + 'vscsi', // Trace type |
| 40 | + 's3fifo', // Cache algorithm |
| 41 | + '1mb' // Cache size |
| 42 | +); |
| 43 | + |
| 44 | +console.log('Simulation results:', result); |
| 45 | +``` |
| 46 | + |
| 47 | +## API Reference |
| 48 | + |
| 49 | +### `runSimulation(tracePath, traceType, algorithm, cacheSize)` |
| 50 | + |
| 51 | +Run a cache simulation with specified parameters. |
| 52 | + |
| 53 | +**Parameters:** |
| 54 | +- `tracePath` (string): Path to the trace file |
| 55 | +- `traceType` (string): Type of trace file ('vscsi', 'csv', 'txt', 'binary', 'oracle') |
| 56 | +- `algorithm` (string): Cache replacement algorithm |
| 57 | +- `cacheSize` (string): Cache size (e.g., '1mb', '512kb', '2gb') |
| 58 | + |
| 59 | +**Returns:** Object containing simulation results including hit rate, miss count, etc. |
| 60 | + |
| 61 | +### `getSupportedAlgorithms()` |
| 62 | + |
| 63 | +Get a list of supported cache algorithms. |
| 64 | + |
| 65 | +**Returns:** Array of algorithm names |
| 66 | + |
| 67 | +### `getSupportedTraceTypes()` |
| 68 | + |
| 69 | +Get a list of supported trace file types. |
| 70 | + |
| 71 | +**Returns:** Array of trace type names |
| 72 | + |
| 73 | +## Cache Algorithms |
| 74 | + |
| 75 | +The following cache replacement algorithms are supported: |
| 76 | + |
| 77 | +- **LRU** (Least Recently Used) |
| 78 | +- **FIFO** (First In, First Out) |
| 79 | +- **LFU** (Least Frequently Used) |
| 80 | +- **ARC** (Adaptive Replacement Cache) |
| 81 | +- **Clock** (Clock/Second Chance) |
| 82 | +- **S3-FIFO** (Simple, Scalable, Scan-resistant FIFO) |
| 83 | +- **Sieve** (Eviction algorithm with lazy promotion) |
| 84 | + |
| 85 | +## Trace File Formats |
| 86 | + |
| 87 | +- **vscsi**: VMware vSCSI trace format |
| 88 | +- **csv**: Comma-separated values format |
| 89 | +- **txt**: Plain text format |
| 90 | +- **binary**: Binary trace format |
| 91 | +- **oracle**: Oracle optimal algorithm simulation |
| 92 | + |
| 93 | +## Command Line Interface |
| 94 | + |
| 95 | +The package includes a command-line interface: |
| 96 | + |
| 97 | +```bash |
| 98 | +# Install globally for CLI access |
| 99 | +npm install -g libcachesim-node |
| 100 | + |
| 101 | +# Run simulation from command line |
| 102 | +cachesim-js --trace /path/to/trace.vscsi --algorithm s3fifo --size 1mb |
| 103 | +``` |
| 104 | + |
| 105 | +## Development |
| 106 | + |
| 107 | +### Building from Source |
| 108 | + |
| 109 | +If you need to build from source or contribute to development: |
| 110 | + |
| 111 | +```bash |
| 112 | +# Clone the repository |
| 113 | +git clone https://github.com/1a1a11a/libCacheSim.git |
| 114 | +cd libCacheSim/libCacheSim-node |
| 115 | + |
| 116 | +# Install dependencies |
| 117 | +npm install |
| 118 | + |
| 119 | +# Build from source (requires cmake, build tools) |
| 120 | +npm run build-from-source |
| 121 | + |
| 122 | +# Run tests |
| 123 | +npm test |
| 124 | +``` |
| 125 | + |
| 126 | +### Requirements for Building from Source |
| 127 | + |
| 128 | +- Node.js 14+ |
| 129 | +- CMake 3.10+ |
| 130 | +- C/C++ compiler (GCC, Clang, or MSVC) |
| 131 | +- System dependencies: |
| 132 | + - Linux: `build-essential cmake libglib2.0-dev libzstd-dev` |
| 133 | + - macOS: `cmake glib zstd` (via Homebrew) |
| 134 | + |
| 135 | +## Architecture |
| 136 | + |
| 137 | +This package uses `prebuild-install` for binary distribution: |
| 138 | + |
| 139 | +1. **Pre-compiled Binaries**: Automatically downloaded from GitHub releases during installation |
| 140 | +2. **Automated Building**: GitHub Actions automatically builds binaries for all supported platforms |
| 141 | +3. **Standard Tooling**: Uses industry-standard `prebuild` and `prebuild-install` packages |
| 142 | + |
| 143 | +## Troubleshooting |
| 144 | + |
| 145 | +### Installation Issues |
| 146 | + |
| 147 | +If installation fails, try the following: |
| 148 | + |
| 149 | +```bash |
| 150 | +# Clear npm cache |
| 151 | +npm cache clean --force |
| 152 | + |
| 153 | +# Reinstall with verbose logging |
| 154 | +npm install libcachesim-node --verbose |
| 155 | + |
| 156 | +# Force source compilation |
| 157 | +npm install libcachesim-node --build-from-source |
| 158 | +``` |
| 159 | + |
| 160 | +### Binary Loading Issues |
| 161 | + |
| 162 | +If you see binary loading errors: |
| 163 | + |
| 164 | +1. Ensure your platform is supported |
| 165 | +2. Check that the `prebuilds` directory exists and contains your platform's binary |
| 166 | +3. Try reinstalling the package |
| 167 | +4. Check Node.js version compatibility (requires Node.js 14+) |
| 168 | + |
| 169 | +### Build from Source Issues |
| 170 | + |
| 171 | +If source compilation fails: |
| 172 | + |
| 173 | +1. Install required system dependencies |
| 174 | +2. Ensure CMake 3.10+ is available |
| 175 | +3. Check that libCacheSim builds successfully: `cd .. && mkdir _build && cd _build && cmake .. && make` |
| 176 | + |
| 177 | +## Contributing |
| 178 | + |
| 179 | +Contributions are welcome! Please see the main [libCacheSim repository](https://github.com/1a1a11a/libCacheSim) for contribution guidelines. |
| 180 | + |
| 181 | +## License |
| 182 | + |
| 183 | +MIT License - see the LICENSE file for details. |
| 184 | + |
| 185 | +## Related Projects |
| 186 | + |
| 187 | +- [libCacheSim](https://github.com/1a1a11a/libCacheSim) - The core C library |
| 188 | +- [libCacheSim Python bindings](https://github.com/1a1a11a/libCacheSim/tree/develop/libCacheSim/pyBindings) - Python interface |
| 189 | + |
| 190 | +## Citation |
| 191 | + |
| 192 | +If you use libCacheSim in your research, please cite: |
| 193 | + |
| 194 | +```bibtex |
| 195 | +@misc{libcachesim, |
| 196 | + title={libCacheSim: A High-Performance Cache Simulator}, |
| 197 | + author={Tian, Murphy and others}, |
| 198 | + year={2023}, |
| 199 | + url={https://github.com/1a1a11a/libCacheSim} |
| 200 | +} |
| 201 | +``` |
0 commit comments