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>
|
2008-07-19 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||||
|
|
||||||
Call parseUrl directly.
|
Call parseUrl directly.
|
||||||
|
|
|
@ -54,9 +54,13 @@ private:
|
||||||
SpeedCalc uploadSpeed;
|
SpeedCalc uploadSpeed;
|
||||||
Time downloadStartTime;
|
Time downloadStartTime;
|
||||||
PeerStat::STATUS status;
|
PeerStat::STATUS status;
|
||||||
|
unsigned int _avgDownloadSpeed;
|
||||||
|
unsigned int _avgUploadSpeed;
|
||||||
public:
|
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() {}
|
~PeerStat() {}
|
||||||
|
|
||||||
|
@ -71,6 +75,11 @@ public:
|
||||||
return downloadSpeed.calculateSpeed(now);
|
return downloadSpeed.calculateSpeed(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int calculateAvgDownloadSpeed() {
|
||||||
|
_avgDownloadSpeed = downloadSpeed.calculateAvgSpeed();
|
||||||
|
return _avgDownloadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int calculateUploadSpeed() {
|
unsigned int calculateUploadSpeed() {
|
||||||
return uploadSpeed.calculateSpeed();
|
return uploadSpeed.calculateSpeed();
|
||||||
}
|
}
|
||||||
|
@ -79,6 +88,11 @@ public:
|
||||||
return uploadSpeed.calculateSpeed(now);
|
return uploadSpeed.calculateSpeed(now);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int calculateAvgUploadSpeed() {
|
||||||
|
_avgUploadSpeed = uploadSpeed.calculateAvgSpeed();
|
||||||
|
return _avgUploadSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
void updateDownloadLength(size_t bytes) {
|
void updateDownloadLength(size_t bytes) {
|
||||||
downloadSpeed.update(bytes);
|
downloadSpeed.update(bytes);
|
||||||
}
|
}
|
||||||
|
@ -96,11 +110,11 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getAvgDownloadSpeed() const {
|
unsigned int getAvgDownloadSpeed() const {
|
||||||
return downloadSpeed.getAvgSpeed();
|
return _avgDownloadSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getAvgUploadSpeed() const {
|
unsigned int getAvgUploadSpeed() const {
|
||||||
return uploadSpeed.getAvgSpeed();
|
return _avgUploadSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
void reset() {
|
void reset() {
|
||||||
|
@ -116,6 +130,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void downloadStop() {
|
void downloadStop() {
|
||||||
|
calculateAvgDownloadSpeed();
|
||||||
|
calculateAvgUploadSpeed();
|
||||||
status = PeerStat::IDLE;
|
status = PeerStat::IDLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,6 +64,9 @@ unsigned int SpeedCalc::calculateSpeed() {
|
||||||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||||
prevSpeed = speed;
|
prevSpeed = speed;
|
||||||
maxSpeed = std::max(speed, maxSpeed);
|
maxSpeed = std::max(speed, maxSpeed);
|
||||||
|
if(isIntervalOver()) {
|
||||||
|
changeSw();
|
||||||
|
}
|
||||||
return speed;
|
return speed;
|
||||||
} else {
|
} else {
|
||||||
return prevSpeed;
|
return prevSpeed;
|
||||||
|
@ -76,6 +79,9 @@ unsigned int SpeedCalc::calculateSpeed(const struct timeval& now) {
|
||||||
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
unsigned int speed = lengthArray[sw]*1000/milliElapsed;
|
||||||
prevSpeed = speed;
|
prevSpeed = speed;
|
||||||
maxSpeed = std::max(speed, maxSpeed);
|
maxSpeed = std::max(speed, maxSpeed);
|
||||||
|
if(isIntervalOver()) {
|
||||||
|
changeSw();
|
||||||
|
}
|
||||||
return speed;
|
return speed;
|
||||||
} else {
|
} else {
|
||||||
return prevSpeed;
|
return prevSpeed;
|
||||||
|
@ -102,7 +108,7 @@ void SpeedCalc::changeSw() {
|
||||||
nextInterval = cpArray[sw].difference()+CHANGE_INTERVAL_SEC;
|
nextInterval = cpArray[sw].difference()+CHANGE_INTERVAL_SEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int SpeedCalc::getAvgSpeed() const {
|
unsigned int SpeedCalc::calculateAvgSpeed() const {
|
||||||
uint64_t milliElapsed = start.differenceInMillis();
|
uint64_t milliElapsed = start.differenceInMillis();
|
||||||
if(milliElapsed) {
|
if(milliElapsed) {
|
||||||
unsigned int speed = accumulatedLength*1000/milliElapsed;
|
unsigned int speed = accumulatedLength*1000/milliElapsed;
|
||||||
|
|
|
@ -71,7 +71,7 @@ public:
|
||||||
return maxSpeed;
|
return maxSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int getAvgSpeed() const;
|
unsigned int calculateAvgSpeed() const;
|
||||||
|
|
||||||
void update(size_t bytes);
|
void update(size_t bytes);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue