Smoother download rate from HTTP
Crude filtering (low pass) of the download rate, over a 400msec time window.
This commit is contained in:
@@ -789,17 +789,27 @@ void Client::receivedBytes(unsigned int count)
|
|||||||
unsigned int Client::transferRateBytesPerSec() const
|
unsigned int Client::transferRateBytesPerSec() const
|
||||||
{
|
{
|
||||||
unsigned int e = d->timeTransferSample.elapsedMSec();
|
unsigned int e = d->timeTransferSample.elapsedMSec();
|
||||||
if (e < 400) {
|
if (e > 400) {
|
||||||
// if called too frequently, return cahced value, to smooth out
|
// too long a window, ignore
|
||||||
// < 1 sec changes in flow
|
d->timeTransferSample.stamp();
|
||||||
|
d->bytesTransferred = 0;
|
||||||
|
d->lastTransferRate = 0;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (e < 100) { // avoid really narrow windows
|
||||||
return d->lastTransferRate;
|
return d->lastTransferRate;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int ratio = (d->bytesTransferred * 1000) / e;
|
unsigned int ratio = (d->bytesTransferred * 1000) / e;
|
||||||
|
// run a low-pass filter
|
||||||
|
unsigned int smoothed = ((400 - e) * d->lastTransferRate) + (e * ratio);
|
||||||
|
smoothed /= 400;
|
||||||
|
|
||||||
d->timeTransferSample.stamp();
|
d->timeTransferSample.stamp();
|
||||||
d->bytesTransferred = 0;
|
d->bytesTransferred = 0;
|
||||||
d->lastTransferRate = ratio;
|
d->lastTransferRate = smoothed;
|
||||||
return ratio;
|
return smoothed;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // of namespace HTTP
|
} // of namespace HTTP
|
||||||
|
|||||||
Reference in New Issue
Block a user