diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-10-25 23:33:45 +0900 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2012-10-25 23:33:45 +0900 |
| commit | 0ecfa19925453e3e4bf8ca947dc72a597654e401 (patch) | |
| tree | 09e2a91ca926e58489bee5c4ba2ae3ba2ba102de /src/PeerStat.cc | |
| parent | 46bdaf0e8dae04d223d9b8b65ac80bc0773d8398 (diff) | |
Reworked download/upload statistics calculation
The old implementation calculates download/upload statistics for a
RequestGroup by summing up all PeerStat objects. For global
statistics, those are summed together. This clearly incurs runtime
penalty and we introduced some kind of caching which updates
statistics every 250ms but it did not work right.
This change removes all these aggregation code, and instead makes
RequestGroup and RequestGroupMan objects hold NetStat object and
download/upload bytes are directly calculated by thier own NetStat.
This is far more simplar than the old way and less runtime penalty and
brings more accuracy.
Diffstat (limited to 'src/PeerStat.cc')
| -rw-r--r-- | src/PeerStat.cc | 87 |
1 files changed, 50 insertions, 37 deletions
diff --git a/src/PeerStat.cc b/src/PeerStat.cc index 891f47f6..0aa8b4dd 100644 --- a/src/PeerStat.cc +++ b/src/PeerStat.cc @@ -33,7 +33,6 @@ */ /* copyright --> */ #include "PeerStat.h" -#include "SharedHandle.h" #include "wallclock.h" namespace aria2 { @@ -42,22 +41,11 @@ PeerStat::PeerStat (cuid_t cuid, const std::string& hostname, const::std::string& protocol) : cuid_(cuid), hostname_(hostname), - protocol_(protocol), - downloadStartTime_(global::wallclock()), - status_(PeerStat::IDLE), - avgDownloadSpeed_(0), - avgUploadSpeed_(0), - sessionDownloadLength_(0), - sessionUploadLength_(0) + protocol_(protocol) {} PeerStat::PeerStat(cuid_t cuid) - : cuid_(cuid), - status_(PeerStat::IDLE), - avgDownloadSpeed_(0), - avgUploadSpeed_(0), - sessionDownloadLength_(0), - sessionUploadLength_(0) + : cuid_(cuid) {} PeerStat::~PeerStat() {} @@ -67,72 +55,97 @@ PeerStat::~PeerStat() {} */ int PeerStat::calculateDownloadSpeed() { - return downloadSpeed_.calculateSpeed(); + return netStat_.calculateDownloadSpeed(); } int PeerStat::calculateAvgDownloadSpeed() { - avgDownloadSpeed_ = downloadSpeed_.calculateAvgSpeed(); - return avgDownloadSpeed_; + return netStat_.calculateAvgDownloadSpeed(); } int PeerStat::calculateUploadSpeed() { - return uploadSpeed_.calculateSpeed(); + return netStat_.calculateUploadSpeed(); } int PeerStat::calculateAvgUploadSpeed() { - avgUploadSpeed_ = uploadSpeed_.calculateAvgSpeed(); - return avgUploadSpeed_; + return netStat_.calculateAvgUploadSpeed(); } void PeerStat::updateDownloadLength(size_t bytes) { - downloadSpeed_.update(bytes); - sessionDownloadLength_ += bytes; + netStat_.updateDownloadLength(bytes); } void PeerStat::updateUploadLength(size_t bytes) { - uploadSpeed_.update(bytes); - sessionUploadLength_ += bytes; + netStat_.updateUploadLength(bytes); } int PeerStat::getMaxDownloadSpeed() const { - return downloadSpeed_.getMaxSpeed(); + return netStat_.getMaxDownloadSpeed(); } int PeerStat::getMaxUploadSpeed() const { - return uploadSpeed_.getMaxSpeed(); + return netStat_.getMaxUploadSpeed(); +} + +int PeerStat::getAvgDownloadSpeed() const +{ + return netStat_.getAvgDownloadSpeed(); +} + +int PeerStat::getAvgUploadSpeed() const +{ + return netStat_.getAvgUploadSpeed(); +} + +uint64_t PeerStat::getSessionDownloadLength() const +{ + return netStat_.getSessionDownloadLength(); +} + +uint64_t PeerStat::getSessionUploadLength() const +{ + return netStat_.getSessionUploadLength(); +} + +void PeerStat::addSessionDownloadLength(uint64_t length) +{ + netStat_.addSessionDownloadLength(length); +} + +const Timer& PeerStat::getDownloadStartTime() const +{ + return netStat_.getDownloadStartTime(); +} + +NetStat::STATUS PeerStat::getStatus() const +{ + return netStat_.getStatus(); } void PeerStat::reset() { - downloadSpeed_.reset(); - uploadSpeed_.reset(); - downloadStartTime_ = global::wallclock(); - status_ = PeerStat::IDLE; + netStat_.reset(); } void PeerStat::downloadStart() { - reset(); - status_ = PeerStat::ACTIVE; + netStat_.downloadStart(); } void PeerStat::downloadStop() { - calculateAvgDownloadSpeed(); - calculateAvgUploadSpeed(); - status_ = PeerStat::IDLE; + netStat_.downloadStop(); } -bool PeerStat::affectsOverallSpeed() const +TransferStat PeerStat::toTransferStat() { - return !downloadSpeed_.isIntervalOver(); + return netStat_.toTransferStat(); } } // namespace aria2 |
