mirror of https://github.com/aria2/aria2
2008-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Cache last calculated average download/upload speed. PeerStat::getAvgDownloadSpeed(), PeerStat::getAvgUploadSpeed() return cached value. Now SpeedCalc::changeSw() is called from SpeedCalc::calculateSpeed() * src/PeerStat.h * src/SpeedCalc.cc * src/SpeedCalc.hpull/1/head
parent
4947fa39b3
commit
f242a1ec8f
|
@ -1,3 +1,12 @@
|
|||
2008-07-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Cache last calculated average download/upload speed.
|
||||
PeerStat::getAvgDownloadSpeed(), PeerStat::getAvgUploadSpeed() return
|
||||
cached value.
|
||||
* src/PeerStat.h
|
||||
* src/SpeedCalc.cc
|
||||
* src/SpeedCalc.h
|
||||
|
||||
2008-07-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Call parseUrl directly.
|
||||
|
|
|
@ -54,9 +54,13 @@ private:
|
|||
SpeedCalc uploadSpeed;
|
||||
Time downloadStartTime;
|
||||
PeerStat::STATUS status;
|
||||
unsigned int _avgDownloadSpeed;
|
||||
unsigned int _avgUploadSpeed;
|
||||
public:
|
||||
|
||||
PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE) {}
|
||||
PeerStat(int32_t cuid = 0):cuid(cuid), status(PeerStat::IDLE),
|
||||
_avgDownloadSpeed(0),
|
||||
_avgUploadSpeed(0) {}
|
||||
|
||||
~PeerStat() {}
|
||||
|
||||
|
@ -71,6 +75,11 @@ public:
|
|||
return downloadSpeed.calculateSpeed(now);
|
||||
}
|
||||
|
||||
unsigned int calculateAvgDownloadSpeed() {
|
||||
_avgDownloadSpeed = downloadSpeed.calculateAvgSpeed();
|
||||
return _avgDownloadSpeed;
|
||||
}
|
||||
|
||||
unsigned int calculateUploadSpeed() {
|
||||
return uploadSpeed.calculateSpeed();
|
||||
}
|
||||
|
@ -79,6 +88,11 @@ public:
|
|||
return uploadSpeed.calculateSpeed(now);
|
||||
}
|
||||
|
||||
unsigned int calculateAvgUploadSpeed() {
|
||||
_avgUploadSpeed = uploadSpeed.calculateAvgSpeed();
|
||||
return _avgUploadSpeed;
|
||||
}
|
||||
|
||||
void updateDownloadLength(size_t bytes) {
|
||||
downloadSpeed.update(bytes);
|
||||
}
|
||||
|
@ -96,11 +110,11 @@ public:
|
|||
}
|
||||
|
||||
unsigned int getAvgDownloadSpeed() const {
|
||||
return downloadSpeed.getAvgSpeed();
|
||||
return _avgDownloadSpeed;
|
||||
}
|
||||
|
||||
unsigned int getAvgUploadSpeed() const {
|
||||
return uploadSpeed.getAvgSpeed();
|
||||
return _avgUploadSpeed;
|
||||
}
|
||||
|
||||
void reset() {
|
||||
|
@ -116,6 +130,8 @@ public:
|
|||
}
|
||||
|
||||
void downloadStop() {
|
||||
calculateAvgDownloadSpeed();
|
||||
calculateAvgUploadSpeed();
|
||||
status = PeerStat::IDLE;
|
||||
}
|
||||
|
||||
|
|
|
@ -64,6 +64,9 @@ unsigned int SpeedCalc::calculateSpeed() {
|
|||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||
prevSpeed = speed;
|
||||
maxSpeed = std::max(speed, maxSpeed);
|
||||
if(isIntervalOver()) {
|
||||
changeSw();
|
||||
}
|
||||
return speed;
|
||||
} else {
|
||||
return prevSpeed;
|
||||
|
@ -76,6 +79,9 @@ unsigned int SpeedCalc::calculateSpeed(const struct timeval& now) {
|
|||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||
prevSpeed = speed;
|
||||
maxSpeed = std::max(speed, maxSpeed);
|
||||
if(isIntervalOver()) {
|
||||
changeSw();
|
||||
}
|
||||
return speed;
|
||||
} else {
|
||||
return prevSpeed;
|
||||
|
@ -102,7 +108,7 @@ void SpeedCalc::changeSw() {
|
|||
nextInterval = cpArray[sw].difference()+CHANGE_INTERVAL_SEC;
|
||||
}
|
||||
|
||||
unsigned int SpeedCalc::getAvgSpeed() const {
|
||||
unsigned int SpeedCalc::calculateAvgSpeed() const {
|
||||
uint64_t milliElapsed = start.differenceInMillis();
|
||||
if(milliElapsed) {
|
||||
unsigned int speed = accumulatedLength*1000/milliElapsed;
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
return maxSpeed;
|
||||
}
|
||||
|
||||
unsigned int getAvgSpeed() const;
|
||||
unsigned int calculateAvgSpeed() const;
|
||||
|
||||
void update(size_t bytes);
|
||||
|
||||
|
|
Loading…
Reference in New Issue