rpc-load-balancer
v1.0.1
Published
<h1 align="center">Welcome to rpc-load-balancer 👋</h1> <p> <a href="https://www.npmjs.com/package/rpc-balancer" target="_blank"> <img alt="Version" src="https://img.shields.io/npm/v/rpc-balancer.svg"> </a> <a href="https://github.com/sk1122/rpc
Downloads
5
Readme
Load Balance RPC Calls between multiple RPC Providers
✨ Demo
Install
yarn add rpc-balancer
Usage
We've used 2 different algorithms to load balance rpc calls, so you can use any algorithm based on your needs, they are
- Round Robin
- Switch RPC Provider after certain amount of responses
- Dynamic Load Balancing
- Switch RPC Providers based on certain parameters like
avgResponse
,connections
,responses
etc
- Switch RPC Providers based on certain parameters like
This package can also cache requests for certain amount of time and retry if request fails, you can configure all these options in the constructor.
maxConnections
- No of max active connections allowed for a RPCmaxResponses
- No of max responses for a connection before switching it outmaxRetries
- No of max retries allowed for a failed requestcache
- Cache Optionscaching
- True or FalsecacheClear
- Duration for cacheexcludeMethods
- JSON RPC methods to be omitted from caching
Round Robin
import { RoundRobin } from "rpc-balancer"
import { ethers } from 'ethers'
const balancer = new RoundRobin({
maxConnections: 2,
maxResponses: 2,
maxRetries: 2,
cache: {
caching: true,
cacheClear: 2000,
excludeMethods: []
}
})
await balancer.init(["RPC_LINKS"])
const provider = new ethers.providers.Web3Provider(balancer)
Dynamic Load Balancing
import { RoundRobin } from "rpc-balancer"
import { ethers } from 'ethers'
const balancer = new LoadBalanceRPC({
maxConnections: 2,
maxResponses: 2,
maxRetries: 2,
cache: {
caching: true,
cacheClear: 2000,
excludeMethods: []
}
})
await balancer.init(["RPC_LINKS"])
const provider = new ethers.providers.Web3Provider(balancer)
Author
👤 Satyam Kulkarni
- Website: https://satyamkulkarni.xyz
- Twitter: @sk1122_
- Github: @sk1122
- LinkedIn: @satyam-kulkarni
🤝 Contributing
Contributions, issues and feature requests are welcome!Feel free to check issues page.
Show your support
Give a ⭐️ if this project helped you!
This README was generated with ❤️ by readme-md-generator