upload: adaptive payload buffer and packet chunk size for fast connections#444
Open
got3nks wants to merge 2 commits intoamule-project:masterfrom
Open
upload: adaptive payload buffer and packet chunk size for fast connections#444got3nks wants to merge 2 commits intoamule-project:masterfrom
got3nks wants to merge 2 commits intoamule-project:masterfrom
Conversation
3028800 to
ab6af17
Compare
Buffer ~10 seconds worth of data per upload slot, clamped between
180 KiB (eMule minimum) and 16 MiB (upper bound):
payloadBufferLimit = clamp(GetUploadDatarate() * 10, 180 KiB, 16 MiB)
Compensates for aMule's synchronous disk I/O: the throttler can drain
the buffer between CreateNextBlockPackage() calls, so a larger lookahead
prevents socket starvation on fast slots. Intended as a temporary measure
until an async disk I/O thread (eMule-style) is implemented.
Scale chunk size with actual slot throughput, floor 10 KiB (stock aMule),
ceil 128 KiB:
chunkSize = clamp(GetUploadDatarate() / 8, 10 KiB, 128 KiB)
Slow slots keep small chunks for smooth flow; fast slots (>1 MB/s) get
128 KiB chunks to reduce per-packet header overhead and socket queue
churn.
ab6af17 to
de3ac51
Compare
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.
Summary
Two minimal changes to
UploadClient.cppthat significantly improve upload throughput on fast connections by scaling two previously hardcoded constants with the actual slot data rate.Adaptive payload buffer
Replaces the hardcoded 100 KiB per-client payload buffer with a rate-adaptive value:
The 100 KiB stock buffer drains in ~10ms at 10 MB/s, leaving the socket queue empty while
CreateNextBlockPackage()refills synchronously from disk. A larger buffer gives the main thread more headroom between disk reads.Adaptive packet chunk size
Replaces the hardcoded 10 KiB packet split threshold with a rate-adaptive value:
Applied in both
CreateStandardPackets()andCreatePackedPackets().MAX_PACKET_SIZE(2 MB), compatible with all peersBackward compatibility
UploadClient.cpponly, no throttler or socket layer touchedTest results
Tested on a 1 Gbps dedicated server running aMule in Docker:
Note: peak results were achieved together with #436 (uint16 → uint32 speed limits), which removes the 524 Mbps configuration cap. This PR alone still provides significant improvement on connections below that limit.
Recommended configuration for fast connections
For best results, set an explicit
MaxUploadvalue rather than relying on unlimited mode (MaxUpload=0). In unlimited mode aMule ramps up slots slowly based on observed throughput; an explicit value ensures the full slot count is available immediately.MaxUpload=65534(maximum before the uint16 overflow threshold, ~524 Mbps)MaxUpload=100000or higher for gigabit connectionsSetting
MaxUploadto your actual uplink capacity also gives the slot allocation algorithm accurate data to work with.