ajsonrpc

Crates.ioajsonrpc
lib.rsajsonrpc
version0.1.7
sourcesrc
created_at2023-08-23 02:36:34.467079
updated_at2023-08-31 02:26:18.140596
descriptionA performance oriented websocket json-rpc router
homepagehttps://github.com/tennisbowling/ajsonrpc
repositoryhttps://github.com/tennisbowling/ajsonrpc
max_upload_size
id951523
size16,301
(TennisBowling)

documentation

README

ajsonrpc

Sssumes that the resp from the node is

  • valid json

  • has a id field

  • the id field is encoded as such: "1" (string)

You shouldn't have a problem with this as long as your doing things correctly

You also should not drop the oneshot Reciever if using the send() function.

example benchmark comparing ajsonrpc with the web3 library.
Ran on a Ryzen 5 26000x and geth was on a Ryzen 9 5950x. All requests were eth_syncing requests.

1 million requests were made concurrently.

ajsonrpc web3
36.1s 72.7s

ajsonrpc is 2.1x faster than web3 in this case.

100 concurrent requests:

ajsonrpc web3 http (reqwests)
3.1792ms 5.5222ms 20.674ms

"normal" http requests are 8x slower than ajsonrpc

Usage

Add this to your Cargo.toml:

[dependencies]
ajsonrpc = "0.1.0"

Example

use ajsonrpc;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    
    let router = ajsonrpc::WsRouter::new("ws://192.168.86.109:8546".to_string()).await?;

    let id = 1;

    let resp = router.make_request(format!(r#"{{"jsonrpc":"2.0","method":"eth_syncing","params":[],"id":"{}"}}"#, id), id).await?;

    println!("Response: {:?}", resp);

    Ok(())
}
Commit count: 14

cargo fmt