diff options
| author | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-01-06 13:13:42 +0000 |
|---|---|---|
| committer | Tatsuhiro Tsujikawa <tatsuhiro.t@gmail.com> | 2009-01-06 13:13:42 +0000 |
| commit | 0a4f43d0edeefb5bc49329b791984c7b2072d1df (patch) | |
| tree | 55d0b23ea83e0a9dbd1d78458b2affb493965700 /src/ServerStat.cc | |
| parent | 5325ec4155ad85339a6a5717b6f4854c0bf67eb0 (diff) | |
2009-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Applied AdaptiveURISelector patch from Aurelien Lefebvre. This
patch adds AdaptiveURISelector, which selects one of the bests
mirrors for first and reserved connections. For supplementary
ones, it returns mirrors which has not been tested yet, and if
each of them already tested, returns mirrors which has to be
tested again. Otherwise, it doesn't return anymore mirrors.
* src/AdaptiveURISelector.cc
* src/AdaptiveURISelector.h
* src/FtpNegotiationCommand.cc
* src/HttpResponseCommand.cc
* src/Makefile.am
* src/Makefile.in
* src/OptionHandlerFactory.cc
* src/RequestGroup.cc
* src/RequestGroup.h
* src/RequestGroupMan.cc
* src/ServerStat.cc
* src/ServerStat.h
* src/ServerStatMan.cc
* src/SpeedCalc.cc
* src/URISelector.h
* src/prefs.cc
* src/prefs.h
* test/RequestGroupManTest.cc
* test/ServerStatManTest.cc
* test/ServerStatTest.cc
Diffstat (limited to 'src/ServerStat.cc')
| -rw-r--r-- | src/ServerStat.cc | 103 |
1 files changed, 101 insertions, 2 deletions
diff --git a/src/ServerStat.cc b/src/ServerStat.cc index 055648fb..d439ca75 100644 --- a/src/ServerStat.cc +++ b/src/ServerStat.cc @@ -33,10 +33,13 @@ */ /* copyright --> */ #include "ServerStat.h" -#include "array_fun.h" + #include <ostream> #include <algorithm> +#include "array_fun.h" +#include "LogFactory.h" + namespace aria2 { const std::string ServerStat::STATUS_STRING[] = { @@ -49,7 +52,12 @@ ServerStat::ServerStat(const std::string& hostname, const std::string& protocol) _hostname(hostname), _protocol(protocol), _downloadSpeed(0), - _status(OK) {} + _singleConnectionAvgSpeed(0), + _multiConnectionAvgSpeed(0), + _counter(0), + _status(OK), + _logger(LogFactory::getInstance()) +{} ServerStat::~ServerStat() {} @@ -92,6 +100,94 @@ void ServerStat::updateDownloadSpeed(unsigned int downloadSpeed) _lastUpdated.reset(); } +unsigned int ServerStat::getSingleConnectionAvgSpeed() const +{ + return _singleConnectionAvgSpeed; +} + +void ServerStat::setSingleConnectionAvgSpeed +(unsigned int singleConnectionAvgSpeed) +{ + _singleConnectionAvgSpeed = singleConnectionAvgSpeed; +} + +void ServerStat::updateSingleConnectionAvgSpeed(unsigned int downloadSpeed) +{ + float avgDownloadSpeed; + if(_counter == 0) + return; + if(_counter < 5) { + avgDownloadSpeed = + ((((float)_counter-1)/(float)_counter)*(float)_singleConnectionAvgSpeed)+ + ((1.0/(float)_counter)*(float)downloadSpeed); + } + else { + avgDownloadSpeed = ((4.0/5.0)*(float)_singleConnectionAvgSpeed) + + ((1.0/5.0)*(float)downloadSpeed); + } + if(avgDownloadSpeed < (int)(0.80*_singleConnectionAvgSpeed)) { + _logger->debug("ServerStat:%s: resetting counter since single connection" + " speed dropped", getHostname().c_str()); + _counter = 0; + } + _logger->debug("ServerStat:%s: _singleConnectionAvgSpeed old:%.2fKB/s" + " new:%.2fKB/s last:%.2fKB/s", + getHostname().c_str(), + (float) _singleConnectionAvgSpeed/1024, + (float) avgDownloadSpeed/1024, + (float) downloadSpeed / 1024); + _singleConnectionAvgSpeed = (int)avgDownloadSpeed; +} + +unsigned int ServerStat::getMultiConnectionAvgSpeed() const +{ + return _multiConnectionAvgSpeed; +} + +void ServerStat::setMultiConnectionAvgSpeed +(unsigned int multiConnectionAvgSpeed) +{ + _multiConnectionAvgSpeed = multiConnectionAvgSpeed; +} + +void ServerStat::updateMultiConnectionAvgSpeed(unsigned int downloadSpeed) +{ + float avgDownloadSpeed; + if(_counter == 0) + return; + if(_counter < 5) { + avgDownloadSpeed = + ((((float)_counter-1)/(float)_counter)*(float)_multiConnectionAvgSpeed) + + ((1.0/(float)_counter)*(float)downloadSpeed); + } + else { + avgDownloadSpeed = ((4.0/5.0)*(float)_multiConnectionAvgSpeed) + + ((1.0/5.0)*(float)downloadSpeed); + } + _logger->debug("ServerStat:%s: _multiConnectionAvgSpeed old:%.2fKB/s" + " new:%.2fKB/s last:%.2fKB/s", + getHostname().c_str(), + (float) _multiConnectionAvgSpeed/1024, + (float) avgDownloadSpeed/1024, + (float) downloadSpeed / 1024); + _multiConnectionAvgSpeed = (int)avgDownloadSpeed; +} + +unsigned int ServerStat::getCounter() const +{ + return _counter; +} + +void ServerStat::increaseCounter() +{ + _counter++; +} + +void ServerStat::setCounter(unsigned int value) +{ + _counter = value; +} + void ServerStat::setStatus(STATUS status) { _status = status; @@ -160,7 +256,10 @@ std::ostream& operator<<(std::ostream& o, const ServerStat& serverStat) o << "host=" << serverStat.getHostname() << ", " << "protocol=" << serverStat.getProtocol() << ", " << "dl_speed=" << serverStat.getDownloadSpeed() << ", " + << "sc_avg_speed=" << serverStat.getSingleConnectionAvgSpeed() << ", " + << "mc_avg_speed=" << serverStat.getMultiConnectionAvgSpeed() << ", " << "last_updated=" << serverStat.getLastUpdated().getTime() << ", " + << "counter=" << serverStat.getCounter() << ", " << "status=" << ServerStat::STATUS_STRING[serverStat.getStatus()]; return o; } |
