Skip to content

Commit 2843ec7

Browse files
Merge pull request #2 from ChainSafe/use-requests-builder
Use requests builder
2 parents 2ed231b + 843fbd1 commit 2843ec7

File tree

14 files changed

+215
-217
lines changed

14 files changed

+215
-217
lines changed

.gitignore

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,11 @@
1-
.yarn
2-
node_modules
1+
.pnp.*
2+
.yarn/*
3+
!.yarn/patches
4+
!.yarn/plugins
5+
!.yarn/releases
6+
!.yarn/sdks
7+
!.yarn/versions
8+
9+
node_modules
10+
11+
methods/requests.json

Makefile

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
all-forest-cloud:
2-
k6 cloud run -e K6_TEST_URL=http://localhost:2345/rpc/v1 --local-execution tests/all.js
2+
k6 cloud run -e K6_RPC_URL=http://localhost:2345/rpc/v1 --local-execution tests/all.js
33

44
all-lotus-cloud:
5-
k6 cloud run -e K6_TEST_URL=http://localhost:1234/rpc/v1 --local-execution tests/all.js
5+
k6 cloud run -e K6_RPC_URL=http://localhost:1234/rpc/v1 --local-execution tests/all.js
66

77
all-forest-local:
8-
k6 run -e K6_TEST_URL=http://localhost:2345/rpc/v1 tests/all.js
8+
k6 run -e K6_RPC_URL=http://localhost:2345/rpc/v1 tests/all.js
99

1010
all-lotus-local:
11-
k6 run -e K6_TEST_URL=http://localhost:1234/rpc/v1 tests/all.js
11+
k6 run -e K6_RPC_URL=http://localhost:1234/rpc/v1 tests/all.js
1212

13-
.PHONY: all-forest-cloud all-lotus-cloud all-forest-local all-lotus-local
13+
build-requests:
14+
yarn build-requests
15+
16+
.PHONY: all-forest-cloud all-lotus-cloud all-forest-local all-lotus-local build-requests

README.md

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,39 @@ Implementation-agnostic benchmark for RPC
66

77
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.
88

9+
## Methods Definitions
10+
11+
Before running benchmarks, generate method definitions using the command:
12+
13+
```bash
14+
K6_RPC_URL=http://localhost:2345/rpc/v1 yarn build-requests
15+
```
16+
17+
It will generate real Filecoin and Ethereum JSON-RPC method definitions with up-to-date parameters from live chain state and will store them in the `methods/requests.json` file.
18+
Feel free to adjust parameters manually.
19+
920
## Local benchmarks
1021

1122
You can run the benchmarks fully locally. To do so, you will need a running Filecoin node; ensure it's synced.
1223

13-
Sample benchmark run:
24+
Benchmark all supported methods:
25+
26+
```bash
27+
k6 run -e K6_RPC_URL=http://localhost:2345/rpc/v1 tests/all.js --duration 30s --vus 20
28+
```
29+
30+
Single method benchmark:
1431

1532
```bash
16-
k6 run -e K6_TEST_URL=http://localhost:2345/rpc/v1 tests/all.js --duration 30s --vus 20
33+
k6 run -e K6_RPC_URL=http://localhost:2345/rpc/v1 K6_METHOD=eth_gasPrice tests/single_method.js --duration 30s --vus 20
1734
```
1835

1936
## Upload benchmarks to Grafana Cloud
2037

2138
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.
2239

2340
```bash
24-
k6 cloud run -e K6_TEST_URL=http://localhost:2345/rpc/v1 --local-execution tests/top5.js
41+
k6 cloud run -e K6_RPC_URL=http://localhost:2345/rpc/v1 --local-execution tests/all.js
2542
```
2643

2744
## Configuring benchmarks
@@ -30,10 +47,11 @@ Read about [k6 options](https://grafana.com/docs/k6/latest/using-k6/k6-options/)
3047

3148
## Environment variables
3249

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 |
50+
| Name | Description | Type | Default |
51+
| --------------- | --------------------------- | ------ | ------------------------------ |
52+
| `K6_RPC_URL` | Node RPC endpoint | URL | `http://localhost:2345/rpc/v1` |
53+
| `K6_METHOD` | Method to benchmark | string | 'eth_gasPrice' |
54+
| `K6_TEST_DEBUG` | Print additional debug info | bool | false |
3755

3856
## Pitfalls
3957

methods/.keep

Whitespace-only changes.

methods/index.js

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

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
"scripts": {
55
"js-lint": "eslint '**/*.js'",
66
"js-fmt": "prettier --write '**/*.js'",
7-
"js-fmt-check": "prettier --check '**/*.js'"
7+
"js-fmt-check": "prettier --check '**/*.js'",
8+
"build-requests": "node ./scripts/build_requests.js"
89
},
910
"keywords": [],
11+
"type": "module",
1012
"author": "",
1113
"license": "MIT",
1214
"description": "",
1315
"devDependencies": {
16+
"@chainsafe/filecoin-requests-builder": "^0.1.0",
1417
"@eslint/js": "^9.22.0",
1518
"@types/k6": "^0.57.1",
1619
"eslint": "^9.22.0",

scripts/build_requests.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { buildRequests, fetchRpcContext } from '@chainsafe/filecoin-requests-builder';
2+
import fs from 'fs';
3+
4+
const url = process.env.K6_RPC_URL || "http://localhost:2345/rpc/v1";
5+
6+
try {
7+
const context = await fetchRpcContext(url);
8+
const requests = buildRequests(context);
9+
10+
fs.writeFileSync('methods/requests.json', JSON.stringify(requests, null, 2));
11+
console.log('Successfully generated methods/requests.json');
12+
} catch (error) {
13+
console.error('Failed to generate requests:', error.message);
14+
process.exit(1);
15+
}

tests/all.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
import http from "k6/http";
2-
3-
import { allMethods } from "../methods/index.js";
41
import { sendRpcRequest, assertSuccess } from "../utils/rpc.js";
52
import { regularBenchmarkParams } from "../utils/benchmark_params.js";
3+
import { loadRequests } from '../utils/loadRequests.js';
64

7-
const url = __ENV.K6_TEST_URL || "http://localhost:2345/rpc/v1";
5+
const url = __ENV.K6_RPC_URL || "http://localhost:2345/rpc/v1";
86

97
export let options = regularBenchmarkParams;
8+
const requests = loadRequests();
109

1110
// the function that will be executed for each VU (virtual user)
1211
export default function () {
13-
for (const method of allMethods) {
14-
const response = sendRpcRequest(url, method);
15-
assertSuccess(response);
12+
try {
13+
for (const [method, { params }] of Object.entries(requests)) {
14+
const response = sendRpcRequest(url, method, params);
15+
assertSuccess(response);
16+
}
17+
} catch (error) {
18+
console.error('Error processing requests:', error.message);
19+
throw error;
1620
}
1721
}

tests/gas_price.js

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

tests/single_method.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { assertSuccess, sendRpcRequest } from "../utils/rpc.js";
2+
import { regularBenchmarkParams } from "../utils/benchmark_params.js";
3+
import { loadRequests } from '../utils/loadRequests.js';
4+
5+
const url = __ENV.K6_RPC_URL || "http://localhost:2345/rpc/v1";
6+
const method = __ENV.K6_METHOD || "eth_gasPrice";
7+
8+
export let options = regularBenchmarkParams;
9+
const requests = loadRequests();
10+
11+
// the function that will be executed for each VU (virtual user)
12+
export default function () {
13+
try {
14+
if (!requests[method]) {
15+
throw new Error(`Method ${method} is not supported`);
16+
}
17+
18+
const response = sendRpcRequest(url, method, requests[method].params);
19+
assertSuccess(response);
20+
} catch (error) {
21+
console.error('Error processing requests:', error.message);
22+
throw error;
23+
}
24+
}

0 commit comments

Comments
 (0)