mirror of https://github.com/aria2/aria2
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Cached TransferStat/download speed to avoid to sum them up in each call. * src/DefaultPeerStorage.cc * src/DefaultPeerStorage.h * src/SegmentMan.cc * src/SegmentMan.hpull/1/head
parent
9233a6258f
commit
ef927009b7
|
@ -1,3 +1,12 @@
|
|||
2009-03-20 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Cached TransferStat/download speed to avoid to sum them up in each
|
||||
call.
|
||||
* src/DefaultPeerStorage.cc
|
||||
* src/DefaultPeerStorage.h
|
||||
* src/SegmentMan.cc
|
||||
* src/SegmentMan.h
|
||||
|
||||
2009-03-19 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
|
||||
|
||||
Typedefed cuid_t as int32_t in Command.h
|
||||
|
|
|
@ -224,13 +224,11 @@ TransferStat DefaultPeerStorage::calculateStat()
|
|||
s.sessionUploadLength = (*i)->getSessionUploadLength();
|
||||
|
||||
_peerTransferStatMap[(*i)->getID()] = caluclateStatFor(*i);
|
||||
stat = stat+s;
|
||||
stat += s;
|
||||
}
|
||||
_cachedTransferStat = stat;
|
||||
} else {
|
||||
for(std::map<std::string, TransferStat>::const_iterator i =
|
||||
_peerTransferStatMap.begin(); i != _peerTransferStatMap.end(); ++i) {
|
||||
stat = stat+(*i).second;
|
||||
}
|
||||
stat = _cachedTransferStat;
|
||||
}
|
||||
stat.sessionDownloadLength += removedPeerSessionDownloadLength;
|
||||
stat.sessionUploadLength += removedPeerSessionUploadLength;
|
||||
|
@ -242,7 +240,10 @@ TransferStat DefaultPeerStorage::calculateStat()
|
|||
void DefaultPeerStorage::updateTransferStatFor(const SharedHandle<Peer>& peer)
|
||||
{
|
||||
logger->debug("Updating TransferStat for peer %s", peer->getID().c_str());
|
||||
_peerTransferStatMap[peer->getID()] = caluclateStatFor(peer);
|
||||
_cachedTransferStat = _cachedTransferStat-_peerTransferStatMap[peer->getID()];
|
||||
TransferStat s = caluclateStatFor(peer);
|
||||
_cachedTransferStat += s;
|
||||
_peerTransferStatMap[peer->getID()] = s;
|
||||
}
|
||||
|
||||
void DefaultPeerStorage::deleteUnusedPeer(size_t delSize) {
|
||||
|
|
|
@ -69,6 +69,8 @@ private:
|
|||
|
||||
Time _lastTransferStatMapUpdated;
|
||||
|
||||
TransferStat _cachedTransferStat;
|
||||
|
||||
bool isPeerAlreadyAdded(const SharedHandle<Peer>& peer);
|
||||
public:
|
||||
DefaultPeerStorage(const SharedHandle<BtContext>& btContext,
|
||||
|
|
|
@ -65,7 +65,8 @@ SegmentMan::SegmentMan(const Option* option,
|
|||
logger(LogFactory::getInstance()),
|
||||
_downloadContext(downloadContext),
|
||||
_pieceStorage(pieceStorage),
|
||||
_lastPeerStatDlspdMapUpdated(0)
|
||||
_lastPeerStatDlspdMapUpdated(0),
|
||||
_cachedDlspd(0)
|
||||
{}
|
||||
|
||||
SegmentMan::~SegmentMan() {}
|
||||
|
@ -313,19 +314,24 @@ unsigned int SegmentMan::calculateDownloadSpeed()
|
|||
speed += s;
|
||||
}
|
||||
}
|
||||
_cachedDlspd = speed;
|
||||
} else {
|
||||
for(std::map<cuid_t, unsigned int>::const_iterator i =
|
||||
_peerStatDlspdMap.begin();
|
||||
i != _peerStatDlspdMap.end(); ++i) {
|
||||
speed += (*i).second;
|
||||
}
|
||||
speed = _cachedDlspd;
|
||||
}
|
||||
return speed;
|
||||
}
|
||||
|
||||
void SegmentMan::updateDownloadSpeedFor(const SharedHandle<PeerStat>& pstat)
|
||||
{
|
||||
_peerStatDlspdMap[pstat->getCuid()] = pstat->calculateDownloadSpeed();
|
||||
unsigned int newspd = pstat->calculateDownloadSpeed();
|
||||
unsigned int oldSpd = _peerStatDlspdMap[pstat->getCuid()];
|
||||
if(_cachedDlspd > oldSpd) {
|
||||
_cachedDlspd -= oldSpd;
|
||||
_cachedDlspd += newspd;
|
||||
} else {
|
||||
_cachedDlspd = newspd;
|
||||
}
|
||||
_peerStatDlspdMap[pstat->getCuid()] = newspd;
|
||||
}
|
||||
|
||||
class PeerStatDownloadLengthOperator {
|
||||
|
|
|
@ -89,6 +89,8 @@ private:
|
|||
|
||||
Time _lastPeerStatDlspdMapUpdated;
|
||||
|
||||
unsigned int _cachedDlspd;
|
||||
|
||||
SharedHandle<Segment> checkoutSegment(cuid_t cuid,
|
||||
const SharedHandle<Piece>& piece);
|
||||
|
||||
|
|
Loading…
Reference in New Issue