forked from premiere/premiere-libtorrent
another rate limiter optimization attempt
This commit is contained in:
parent
fa6818e757
commit
20184a9a22
|
@ -1,3 +1,4 @@
|
||||||
|
* rate limiter optimization
|
||||||
* rate limiter overflow fix (for very high limits)
|
* rate limiter overflow fix (for very high limits)
|
||||||
* non-auto-managed torrents no longer count against the torrent limits
|
* non-auto-managed torrents no longer count against the torrent limits
|
||||||
* handle DHT error responses correctly
|
* handle DHT error responses correctly
|
||||||
|
|
|
@ -64,6 +64,19 @@ struct TORRENT_EXTRA_EXPORT bandwidth_channel
|
||||||
void return_quota(int amount);
|
void return_quota(int amount);
|
||||||
void use_quota(int amount);
|
void use_quota(int amount);
|
||||||
|
|
||||||
|
// this is an optimization. If there is more than one second
|
||||||
|
// of quota built up in this channel, just apply it right away
|
||||||
|
// instead of introducing a delay to split it up evenly. This
|
||||||
|
// should especially help in situations where a single peer
|
||||||
|
// has a capacity under the rate limit, but would otherwise be
|
||||||
|
// held back by the latency of getting bandwidth from the limiter
|
||||||
|
bool need_queueing(int amount)
|
||||||
|
{
|
||||||
|
if (m_quota_left - amount < m_limit) return true;
|
||||||
|
m_quota_left -= amount;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// used as temporary storage while distributing
|
// used as temporary storage while distributing
|
||||||
// bandwidth
|
// bandwidth
|
||||||
int tmp;
|
int tmp;
|
||||||
|
|
|
@ -102,11 +102,17 @@ namespace libtorrent
|
||||||
|
|
||||||
bw_request bwr(peer, blk, priority);
|
bw_request bwr(peer, blk, priority);
|
||||||
int i = 0;
|
int i = 0;
|
||||||
if (chan1 && chan1->throttle() > 0) bwr.channel[i++] = chan1;
|
if (chan1 && chan1->throttle() > 0 && chan1->need_queueing(blk))
|
||||||
if (chan2 && chan2->throttle() > 0) bwr.channel[i++] = chan2;
|
bwr.channel[i++] = chan1;
|
||||||
if (chan3 && chan3->throttle() > 0) bwr.channel[i++] = chan3;
|
if (chan2 && chan2->throttle() > 0 && chan2->need_queueing(blk))
|
||||||
if (chan4 && chan4->throttle() > 0) bwr.channel[i++] = chan4;
|
bwr.channel[i++] = chan2;
|
||||||
if (chan5 && chan5->throttle() > 0) bwr.channel[i++] = chan5;
|
if (chan3 && chan3->throttle() > 0 && chan3->need_queueing(blk))
|
||||||
|
bwr.channel[i++] = chan3;
|
||||||
|
if (chan4 && chan4->throttle() > 0 && chan4->need_queueing(blk))
|
||||||
|
bwr.channel[i++] = chan4;
|
||||||
|
if (chan5 && chan5->throttle() > 0 && chan5->need_queueing(blk))
|
||||||
|
bwr.channel[i++] = chan5;
|
||||||
|
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
{
|
{
|
||||||
// the connection is not rate limited by any of its
|
// the connection is not rate limited by any of its
|
||||||
|
@ -115,6 +121,7 @@ namespace libtorrent
|
||||||
// the queue, just satisfy the request immediately
|
// the queue, just satisfy the request immediately
|
||||||
return blk;
|
return blk;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_queued_bytes += blk;
|
m_queued_bytes += blk;
|
||||||
m_queue.push_back(bwr);
|
m_queue.push_back(bwr);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue