Fix: [Network] Prevent stalling save game transfer when compression is slow #9106
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.
Motivation / Problem
If the threaded savegame logic yields packets slow enough, e.g. 1 every tick, and the network is fast enough, i.e. it can handle 33 packets / second (~400 kbps or ~8 Mbps with #9099), then
sent_packets
would be doubled every tick. From an initial value of 4it would take 29 ticks to get to 2**31 and on tick 30 it would overflow into 0. From that moment on the server cannot send any packets anymore as
i < sent_packets
would always return false.Description
Just limit to how far
send_packets
can be doubled. Similarly, reduce the type size because the number of packets that may be sent per tick becomes quite hilarious quickly.Limitations
This artificially limits the save game transfer speed to 1400 MiB/s (or 35 GiB/s with #9099 applied). If the saving would be able to saturate the network link, this artificial limit is reached after 91 MiB (or 2 GiB with #9099 applied) of the save game was already sent due to the ramp up from 4 to 32768 packets per second every tick.
Checklist for review
Some things are not automated, and forgotten often. This list is a reminder for the reviewers.