Repository navigation
Conversation
Replace flume channel with tokio::sync::mpsc in the eventloop and client. The sync Client gains a runtime Handle for block_on sends; Connection continues to own the Runtime so the I/O driver stays alive for the lifetime of the connection. Results: tokio-sync vs main ┌─────────┬───────────────┬─────────────────────┬────────┬──────────────┐ │ Payload │ main (median) │ tokio-sync (median) │ Δ time │ Δ throughput │ ├─────────┼───────────────┼─────────────────────┼────────┼──────────────┤ │ 32 B │ 1.402 ms │ 1.316 ms │ −5.4% │ +5.8% │ ├─────────┼───────────────┼─────────────────────┼────────┼──────────────┤ │ 100 B │ 1.397 ms │ 1.383 ms │ −3.5% │ +3.6% │ ├─────────┼───────────────┼─────────────────────┼────────┼──────────────┤ │ 1024 B │ 1.664 ms │ 1.716 ms │ +3.3% │ −3.2% │ └─────────┴───────────────┴─────────────────────┴────────┴──────────────┘ All results are statistically significant (p < 0.05). --- Interpretation Small messages (32–100 B): tokio-sync wins by 3.5–5.4%. These are channel-bound — the message is tiny relative to the per-message bookkeeping cost, so the reduction in lock contention from dropping flume's mutex pays off directly. The channel send/receive path sees fewer cache line bounces. Large messages (1024 B): tokio-sync is 3.3% slower. At 1 KB, the payload dominates. The likely cause is that tokio's bounded mpsc uses an intrusive linked-list of Arc-allocated nodes rather than flume's pre-allocated ring buffer, so 1 KB payloads incur an extra allocation + Arc refcount per message where flume's ring buffer would reuse a slot. This is a known design tradeoff in tokio mpsc. The crossover point is somewhere between 100 B and 1024 B. For the typical MQTT use case (small control messages, moderate publish payloads), the switch is neutral-to-positive overall.
tokio::sync::mpsc
Contributor
Author
|
This PR was for documentation purpose. A note of why both |
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.
Replace flume channel with
tokio::sync::mpscin the eventloop and client. The sync Client gains a runtime Handle for block_on sends.Benchmark Results: tokio-sync vs main
refer: bench/throughput
All results are statistically significant (p < 0.05).
Interpretation
Small messages (32–100 B): tokio-sync wins by 3.5–5.4%. These are channel-bound — the message is tiny relative to the per-message bookkeeping cost, so the reduction in lock contention from dropping flume's mutex pays off directly. The channel send/receive path sees fewer cache line bounces.
Large messages (1024 B): tokio-sync is 3.3% slower. At 1 KB, the payload dominates. The likely cause is that tokio's bounded mpsc uses an intrusive linked-list of Arc-allocated nodes rather than flume's pre-allocated ring buffer, so 1 KB payloads incur an extra allocation + Arc refcount per message where flume's ring buffer would reuse a slot. This is a known design tradeoff in tokio mpsc.
The crossover point is somewhere between 100 B and 1024 B. For the typical MQTT use case (small control messages, moderate publish payloads), the switch is neutral-to-positive overall.
Type of change
Checklist:
cargo fmtCHANGELOG.mdif it's relevant to the users of the library. If it's not relevant mention why.