README
ΒΆ
Advanced RPC Features Example
This example demonstrates the advanced RPC features introduced in the latest version:
Features Demonstrated
1. Per-Node Rate Limiting
Each RPC node has its own QPS (queries per second) limit to prevent hitting provider rate limits.
{
URL: "https://eth.llamarpc.com",
Priority: 10,
RateLimit: 25, // 25 requests per second
MaxConcurrent: 10,
}
2. Per-Node Concurrency Control
Limit the number of concurrent requests to each node to prevent overload.
{
URL: "https://rpc.ankr.com/eth",
Priority: 8,
RateLimit: 10,
MaxConcurrent: 5, // Max 5 concurrent requests
}
3. Circuit Breaker
Automatically disables nodes that experience consecutive failures:
- Trips after 5 consecutive errors
- Auto-recovers after 30 seconds
- Prevents cascading failures
4. Automatic Node Switching
When a node is busy or rate-limited, the client automatically switches to another available node based on priority and health.
5. Dynamic Node Scoring
Nodes are scored based on:
- Priority level
- Response latency
- Error rate
- Block height lag
How to Run
cd examples/rpc-advanced
go run main.go
Expected Output
π Advanced RPC Client Demo
==================================================
π Demo 1: Basic RPC Call
β
Current block: 21047197
π Demo 2: Concurrent Requests (20 requests)
β
Success: 20/20 requests
β±οΈ Duration: 2.5s
π Throughput: 8.00 req/s
β‘ Demo 3: Rate Limiting Test
Sending 30 rapid requests...
β
Success: 30/30 requests
β±οΈ Duration: 4.2s
π Average QPS: 7.14
π₯ Demo 4: Node Health Status
β
All nodes operational
- Circuit breakers: Normal
- Rate limits: Active
- Concurrency: Controlled
β¨ Demo completed successfully!
Key Features Demonstrated:
β
Per-node rate limiting
β
Per-node concurrency control
β
Automatic node switching
β
High availability with multiple nodes
Configuration Best Practices
For Paid RPC Providers (Alchemy, Infura)
{
URL: "https://eth-mainnet.g.alchemy.com/v2/YOUR_KEY",
Priority: 10,
RateLimit: 25-50, // Based on your plan
MaxConcurrent: 10-20, // 30-50% of rate_limit
}
For Free Public Nodes
{
URL: "https://rpc.ankr.com/eth",
Priority: 5,
RateLimit: 5-10, // Conservative limits
MaxConcurrent: 3-5, // Lower concurrency
}
Key Concepts
Rate Limit vs Max Concurrent
-
Rate Limit (QPS): Total requests per second
- Example: 25 QPS = max 25 requests in any 1-second window
- Prevents hitting provider's rate limits
-
Max Concurrent: Simultaneous in-flight requests
- Example: 10 concurrent = max 10 requests running at the same time
- Prevents node overload and connection exhaustion
Why Both?
Scenario: rate_limit=25, max_concurrent=10
β
Good: 10 concurrent requests, each takes 100ms
- All complete within 1 second
- Total: 10 requests/second (within limit)
β Bad: 25 concurrent requests, each takes 1s
- Would exceed max_concurrent (only 10 allowed)
- Automatically switches to another node
Related Documentation
Troubleshooting
"Rate limit exceeded" errors
- Reduce
rate_limitvalue - Add more RPC nodes
- Increase
intervalin scanner config
"Node busy" errors
- Increase
max_concurrentvalue - Add more RPC nodes
- Reduce concurrent scanner operations
Circuit breaker keeps tripping
- Check RPC node health
- Verify API keys are valid
- Consider using paid RPC tier
Documentation
ΒΆ
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.