- Node.js v22.0.0 (recommended)
pnpm install
# or
npm install
You can configure environment variables by creating a .env
file or passing environment variable parameters directly in the command line.
Variable Name | Description | Default Value |
---|---|---|
GRPC_URL_1 |
First gRPC service URL | https://solana-yellowstone-grpc.publicnode.com:443 |
GRPC_NAME_1 |
First gRPC service name | GRPC_1 |
GRPC_TOKEN_1 |
First gRPC service token | None |
GRPC_URL_2 |
Second gRPC service URL | https://solana-yellowstone-grpc.publicnode.com:443 |
GRPC_NAME_2 |
Second gRPC service name | GRPC_2 |
GRPC_TOKEN_2 |
Second gRPC service token | None |
GRPC_COMPARISON_DURATION_SEC |
Test duration (seconds) | 30 |
Create a .env
file and add the following content:
GRPC_URL_1=https://solana-yellowstone-grpc.publicnode.com:443
GRPC_URL_2=https://your-grpc-server.com:443
GRPC_TOKEN_2=your_x_token_here
GRPC_COMPARISON_DURATION_SEC=30
You can configure multiple gRPC endpoints for comparison testing through environment variables. The environment variable naming format is GRPC_URL_[SUFFIX]
, where [SUFFIX]
can be any custom identifier (not limited to numbers). You can also set custom names using GRPC_NAME_[SUFFIX]
for better identification. For example:
GRPC_URL_MAINNET=https://grpc1.example.com:443
GRPC_URL_TESTNET=https://grpc2.example.com:443
GRPC_TOKEN_TESTNET=your_x_token_here
GRPC_URL_DEVNET=https://grpc3.example.com:443
The program will automatically detect all configured endpoints and perform performance comparison. If only one endpoint is configured, the program can still run but will only output the time that endpoint receives slots, without comparison analysis.
The tool supports connecting to gRPC services that require authentication using X-Token authentication (such as Shyft, etc.). Simply set the corresponding GRPC_TOKEN_[SUFFIX]
in the environment variables. For example:
GRPC_URL_SHYFT=https://grpc.shyft.to
GRPC_TOKEN_SHYFT=your_shyft_x_token_here
For gRPC services that don't require authentication, you can skip setting the token.
The tool evaluates gRPC service performance by comparing how quickly multiple gRPC services receive the same slot data. Since slot data from gRPC streams doesn't include precise timestamps, this comparative approach provides the most accurate way to measure relative gRPC latency by using client-side timing.
- Average latency when behind: Refers to the average value of a service's delay relative to other services when that service is slower than others among multiple gRPC services. The denominator is the number of times that service is slower than others.
- Overall average latency: Refers to the average latency of all gRPC services receiving the same slot, with the denominator being the total number of times each gRPC receives slots. This latency is relative to the service with the smallest latency among all gRPC services in this test. For example, in a test, GRPC_1 receives slot 123456 fastest, GRPC_2 receives slot 123456 with a 12.38ms delay, then GRPC_1's overall average latency is 0ms, and GRPC_2's overall average latency is 12.38ms.
Currently, one of the most commonly available free gRPC services is https://solana-yellowstone-grpc.publicnode.com:443
. This service has different regional loads behind it (such as US, Germany), so test results may vary significantly each time and should not be used as an absolute benchmark.
npx tsx src/grpc-bench/grpc-comparison.ts
# Using environment variables directly
GRPC_URL_1=https://solana-yellowstone-grpc.publicnode.com:443 \
GRPC_URL_2=https://your-grpc-server.com:443 \
GRPC_TOKEN_2=your_x_token_here \
GRPC_COMPARISON_DURATION_SEC=30 \
npx tsx src/grpc-bench/grpc-comparison.ts
[15:07:52.884] INFO: Starting gRPC service performance comparison...
[15:07:52.884] INFO: Test duration: 30 seconds
[15:07:52.884] INFO: Test endpoints: GRPC_2, GRPC_1
[15:07:52.885] INFO: Connecting to GRPC_2: https://solana-yellowstone-grpc.publicnode.com:443
[15:07:52.967] INFO: Connecting to GRPC_1: https://solana-yellowstone-grpc.publicnode.com:443
[15:07:54.332] INFO: GRPC_2 successfully received first slot 349707353, confirmed as available endpoint
[15:07:54.567] INFO: GRPC_1 successfully received first slot 349707354, confirmed as available endpoint
[15:07:54.567] INFO: All endpoints have received data, starting formal statistics...
[15:07:54.837] INFO: GRPC_1 received slot 349707354: first to receive
[15:07:54.837] INFO: GRPC_2 received slot 349707354: latency 269.61ms (relative to GRPC_1)
[15:07:55.180] INFO: GRPC_1 received slot 349707355: first to receive
[15:07:55.180] INFO: GRPC_2 received slot 349707355: latency 254.95ms (relative to GRPC_1)
[15:07:55.579] INFO: GRPC_1 received slot 349707356: first to receive
[15:07:55.579] INFO: GRPC_2 received slot 349707356: latency 110.55ms (relative to GRPC_1)
...
[15:07:57.978] INFO: ===== Test Progress: 16% [5/30s] - Remaining: 25s =====
...
[15:08:02.983] INFO: ===== Test Progress: 33% [10/30s] - Remaining: 20s =====
...
[15:08:17.997] INFO: ===== Test Progress: 83% [25/30s] - Remaining: 5s =====
...
[15:08:23.002] INFO: ===== Test Progress: 100% [30/30s] - Remaining: 0s =====
[15:08:23.005] INFO: Test completed, analyzing results...
[15:08:23.005] INFO: ===== GRPC_2 Performance Analysis =====
[15:08:23.005] INFO: Total blocks received: 74
[15:08:23.005] INFO: First to receive blocks: 3 (4.05%)
[15:08:23.005] INFO: Latency statistics (relative to fastest endpoint):
[15:08:23.005] INFO: Average latency: 154.29ms
[15:08:23.005] INFO: Minimum latency: 0.22ms
[15:08:23.005] INFO: Maximum latency: 494.81ms
[15:08:23.005] INFO: Sample count: 71
[15:08:23.005] INFO: ===== GRPC_1 Performance Analysis =====
[15:08:23.005] INFO: Total blocks received: 74
[15:08:23.005] INFO: First to receive blocks: 71 (95.95%)
[15:08:23.005] INFO: Latency statistics (relative to fastest endpoint):
[15:08:23.005] INFO: Average latency: 1.61ms
[15:08:23.005] INFO: Minimum latency: 0.22ms
[15:08:23.005] INFO: Maximum latency: 4.25ms
[15:08:23.005] INFO: Sample count: 3
[15:08:23.005] INFO: ===== Endpoint Performance Comparison =====
[15:08:23.005] INFO: GRPC_1 : First to receive 95.95%, avg latency when behind 1.61ms, overall avg latency 0.07ms
[15:08:23.005] INFO: GRPC_2 : First to receive 4.05%, avg latency when behind 154.29ms, overall avg latency 148.04ms
[15:08:23.005] INFO: Test completed, closing connections...
[15:08:23.005] INFO: All connections closed, test ended
Telegram: @bloxflux