A redis wannabe clone, with just a few commands focussing on performance, learning Tokio and performance profiling. It's an exercise.
# Debug (is way slower)
cargo run
# Release
cargo run --release
- GET
- SET
- INFO (returns nothing but "OK")
- running official
redis-server
(Redis server v=5.0.7, currently latest on Ubuntuapt install
) - vs. running rustdis
cargo run --release
Benchmark: redis-benchmark -t set,get -n 1000000 -r 1000000 -c 1000
- 1M requests for SET and GET
- 1M random values
- 1k concurrent banging clients
Current results (on my machine):
- rustdis: ~73k/s (~81% redis performance)
- redis-server: ~90k/s
cargo install flamegraph
# with sudo
echo "kernel.perf_event_paranoid = -1" >> /etc/sysctl.conf
sysctl --system
flamegraph ./target/release/rustdis
- 🆗 increase buffer and channel sizes
- 🆗 make tokio channel unbound
- 🆗 using
tokio::task::block_in_place
instead of "spawn and join" - 🆗 "bug" using
tokio::mpsc::channel
wrong with blocking thread - 🆗 move shared state access into
Processor
- 🆗 double-buffered read buffer 2-phase loop: 1. reading (empty buf), 2. sending/reading
- 🔝 buffering socket writes to a phase (+8% req/s through-put)
- 🔜 WIP: optimize chatty unbound channel with buffered payloads (according to the flamegraph this might be the next bottleneck)
- 🔙 tweak rust compilation (see Cargo.toml)
- 🔙 tokio increasing max blocking threads
- 🔙 checking out different sync primitives mutex/rwlock
- 🔙 key-partitioning sync primitives into 2, 4, 8, 128 parts