上記の短い合計は実際には 25kb/秒ですが、接続をグループに分ける代わりに、速度で並べ替えてそれらをループします。総帯域幅から始めて、新しい帯域幅を (残りの帯域幅 / 残りの数) に設定します。これにより、5k および 10k 接続が高速化した場合に備えて、接続の制限が維持されます。割り当てられた帯域幅を超える可能性がありますが、それを修正します。
List<Connection> connections = GetConnections();
connections.Sort(); // sorts by Speed
bandwidth = 100000;
for (int i = 0; i < connections.Count; i++)
{
Connection cnn = connections[i];
cnn.SpeedLimit = bandwidth / (connections.Count - i);
bandwidth -= Math.Min(cnn.Speed, cnn.SpeedLimit);
}
(start with all connections SpeedLimit set to 20000 bytes/sec)
Speed bandwidth SpeedLimit
5000 100000 20000
10000 95000 23750
20000 85000 28333
20000 65000 32500
20000 45000 45000
接続の合計速度制限は 149583 であるため、低速のものの速度が上がると制限を超える可能性がありますが、毎秒制限を調整すると、かなり近くなるはずです。
接続速度は 5000、10000、28333、21000、45000 に変化するため、実際には 109,333 バイトをダウンロードしましたが、再度調整します。45k を除くすべての接続が可能な限界に達しました。
Speed bandwidth SpeedLimit
5000 100000 20000
10000 95000 23750
21000 85000 28333
28333 64000 32000
45000 35667 35667
新しい速度は、正確に 5000、10000、21000、28333、35667、100k になります。
Speed bandwidth SpeedLimit
5000 100000 20000
10000 95000 23750
21000 85000 28333
28333 64000 32000
35667 35667 35667
ここで、5k の接続速度が最大 20k であると仮定します。
Speed bandwidth SpeedLimit
10000 100000 20000
20000 90000 22500
21000 70000 23333
28333 49000 24500
35667 20667 20667