Refactor/async runtime#16
Merged
Merged
Conversation
Rewrite the accept loop and per-connection handler on top of a multi-threaded tokio runtime while keeping the public API of run_listener/start synchronous, so the existing std::net::TcpListener tests and client code work unchanged. - Shutdown: add an async notifier alongside the atomic flag so the accept loop can park on notified() via tokio::select! instead of the old self-connect wake-up trick. - Server: introduce ServerConfig::worker_threads, build a scoped runtime inside run_listener, and drive an async accept/handler loop that uses tokio::io for read/write and tokio::time::timeout for the per-client idle timeout. - Tests: drop Shutdown::wake_listener from shutdown_test (no longer needed) and spread ..Default::default() in max_clients_test so it survives the new field.
Add a new io-threads directive (CLI: --io-threads, file: io-threads) that controls how many worker threads back the tokio runtime driving the TCP server. Zero or unset means "let tokio pick" — one worker per logical CPU in practice — which is the right default for the vast majority of deployments; an explicit value lets operators cap the server's CPU footprint on shared hosts. - config/file.rs: new FileConfig::io_threads + parser directive. - cli.rs: new --io-threads flag with precedence CLI > file > default; box RawFlags inside ScanOutcome to keep clippy happy now that the enum has grown a bit. - main.rs: wire the resolved value into ServerConfig::worker_threads and log it at startup. - ferrum.conf.example: document the new directive.
Fan 500 simultaneous connections into the server with only two tokio worker threads and PING each of them end-to-end. The test proves the async accept loop multiplexes hundreds of sockets with a handful of threads — the workload that would have cost 500 OS threads under the pre-tokio design.
Re-ran redis-benchmark on the exact same hardware as the Week 7 baseline so v0.3.0 (sync) and v0.4.0 (tokio) numbers sit side by side in the same file for easy git-diff regression spotting. Key findings: - Single-client throughput +5% on average (async read/write batches more efficiently than blocking syscalls). - Pipelined numbers stay inside run-to-run noise — the hot path is now engine bound, not I/O bound. - A new c=500 scenario documents the real win of Phase 8: hundreds of clients run on a handful of worker threads instead of exploding the kernel thread count.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.