|
| 1 | +# K6 benchmarking for Filecoin JSON-RPC |
| 2 | + |
| 3 | +Implementation-agnostic benchmark for RPC |
| 4 | + |
| 5 | +## Requirements |
| 6 | + |
| 7 | +This benchmarking suite requires [k6](https://grafana.com/docs/k6/latest/) installed on the host. Follow the instructions for your operating system. Alternatively, you can run them via Docker. |
| 8 | + |
| 9 | +## Local benchmarks |
| 10 | + |
| 11 | +You can run the benchmarks fully locally. To do so, you will need a running Filecoin node; ensure it's synced. |
| 12 | + |
| 13 | +Sample benchmark run: |
| 14 | + |
| 15 | +```bash |
| 16 | +k6 run -e K6_TEST_URL=http://localhost:2345/rpc/v1 tests/all.js --duration 30s --vus 20 |
| 17 | +``` |
| 18 | + |
| 19 | +## Upload benchmarks to Grafana Cloud |
| 20 | + |
| 21 | +You can create a free account on Grafana Cloud (the free tier should suffice if you run the tests locally). Login with `k6 cloud login --token <token>`. Now, you can run the benchmarks locally but have them uploaded to your Grafana Cloud for visual inspection and comparisons. |
| 22 | + |
| 23 | +```bash |
| 24 | +k6 cloud run -e K6_TEST_URL=http://localhost:2345/rpc/v1 --local-execution tests/top5.js |
| 25 | +``` |
| 26 | + |
| 27 | +## Configuring benchmarks |
| 28 | + |
| 29 | +Read about [k6 options](https://grafana.com/docs/k6/latest/using-k6/k6-options/). |
| 30 | + |
| 31 | +## Environment variables |
| 32 | + |
| 33 | +| Name | Description | Type | Default | |
| 34 | +| --------------- | --------------------------- | ---- | ------------------------------ | |
| 35 | +| `K6_TEST_URL` | Node RPC endpoint | URL | `http://localhost:2345/rpc/v1` | |
| 36 | +| `K6_TEST_DEBUG` | Print additional debug info | bool | false | |
| 37 | + |
| 38 | +## Pitfalls |
| 39 | + |
| 40 | +- Don't run the benchmarks in a environment with shared CPU, e.g., on a VPS. The results will vary depending on the load on that CPU. |
| 41 | +- Don't run the node in a virtualized environment, e.g., Docker for Mac. Use a native build. |
| 42 | +- Ensure your test parameters match your hardware. Ensure your machine is not saturated, e.g., `k6` itself using most of the resources and leaving the node with too little CPU/RAM. If need be, run the test on separate machines. `k6` and the node could also be limited, e.g., via Docker. |
| 43 | + |
| 44 | +## Potential improvements |
| 45 | + |
| 46 | +- [ ] include more methods |
| 47 | +- [ ] rewrite in TypeScript |
| 48 | +- [ ] visualize results locally |
0 commit comments