gakonst / ethers-rs

Complete Ethereum & Celo library and wallet implementation in Rust. https://docs.rs/ethers
Apache License 2.0
2.5k stars 795 forks source link

Slow websockets when amount requested through a single connection is substantially large #2498

Open syahrul12345 opened 1 year ago

syahrul12345 commented 1 year ago

Version 2.0.7

Platform MacOS Venture 13.3.1

Description Using a singular websocket connection, if a large number of requests are made, all requests are only completed after a long time. A total of 40,000 requests to will only finish after 90 seconds. I tried this code:

1) Clone this repo: https://github.com/syahrul12345/ethers-websockets-tests 2) Change .example.env to .env and provide your http and ws endpoints. (I am using reth) 3) Execute an individual benchmark by using this command

//Do with 5 iterations, each with 50 websocket requests
cargo run -- --outer 5 --iterations 50
//Replay with more requests
cargo run -- --outer 1 --iterations 40000

Logs:

------ BENCHMARK  ------
Iteration index: 0
Requests done this iteration : 40000
Total time taken: 98.080538458s
the-emerald commented 1 year ago

You seem to be measuring performance while compiling in debug mode. Try adding the --release flag for much better performance?

syahrul12345 commented 1 year ago

Im using the release flags, but it really does nothing. Im also compiling using native cpu flags. Added some additional logs in my repo.

For example, a single websocket connect with 1000 requests takes almost 40 seconds to complete!

Time taken for websocket client index 0 request index 986 is 40.720993583s
Time taken for websocket client index 0 request index 970 is 40.721093416s
Time taken for websocket client index 0 request index 991 is 40.721256917s
Time taken for websocket client index 0 request index 898 is 40.72104225s
Time taken for websocket client index 0 request index 897 is 40.904411292s
Time taken for websocket client index 0 request index 993 is 40.948703334s
Time taken for websocket client index 0 request index 984 is 40.957841708s
Time taken for websocket client index 0 request index 988 is 40.957901209s
Time taken for websocket client index 0 request index 900 is 40.957975833s
Time taken for websocket client index 0 request index 989 is 40.957957125s

Command i use:

make build && ./target/release/async-eth --outer 1 --iterations 1000