fix(bandwidth_scheduler) - slightly increase base_bandwidth #12719
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.
Bandwidth scheduler always grants
base_bandwidth
on all links.base_bandwidth
has to be low enough to allow granting enough bandwidth to send a max size receipt on one link without going over themax_shard_bandwidth
limit.Previously I described this requirement as:
num_shards * base_bandwidth + max_receipt_size <= max_shard_bandwidth
But this is actually incorrect. The inequality assumed that
base_bandwidth
is granted on every link, and thenmax_receipt_size
of bandwidth is granted on top of that. This is not what actually happens, the bandwidth scheduler is smarter than that. It'll notice that one link already hasbase_bandwidth
granted on it and increase the grant bymax_receipt_size - base_bandwidth
, notmax_receipt_size
.This means that the proper inequality is:
An example might be helpful.
Let's say that there are
3
shards and shard0
wants to send out a max size receipt.At first there are no grants on any of the links coming out of shard
0
:Then bandwidth scheduler grants
base_bandwidth
on all links:Now bandwidth scheduler processes a bandwidth request to send a max size receipt on link
0->0
. The previous inequality assumed that the final grant would be:And shard
0
can't send out more thanmax_shard_bandwidth
, so it must hold that3*base_bandwidth + max_receipt_size <= max_shard_bandwidth
But in reality the final grants look like this:
So it must hold that
2*base_bandwidth + max_receipt_size <= max_shard_bandwidth
.This means that we can set base bandwidth to
(max_shard_bandwidth - max_receipt_size) / (num_shards - 1)
, which gives a slightly larger value than before, allowing to send more receipts without having to make a bandwidth request.