2010-08-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>

Enter end game mode as soon as all pieces are assigned to peer to
	avoid substantial slow down at the very last stage of download.
	* src/DefaultBtInteractive.cc
	* src/DefaultPieceStorage.cc
	* src/DefaultPieceStorage.h
	* src/PieceStorage.h
	* src/UnknownLengthPieceStorage.h
	* test/MockPieceStorage.h
pull/1/head
Tatsuhiro Tsujikawa 2010-08-26 14:49:40 +00:00
parent e396d2e2c4
commit 835de071f2
7 changed files with 38 additions and 9 deletions

View File

@ -1,3 +1,14 @@
2010-08-26 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Enter end game mode as soon as all pieces are assigned to peer to
avoid substantial slow down at the very last stage of download.
* src/DefaultBtInteractive.cc
* src/DefaultPieceStorage.cc
* src/DefaultPieceStorage.h
* src/PieceStorage.h
* src/UnknownLengthPieceStorage.h
* test/MockPieceStorage.h
2010-08-25 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>
Updated IPv6 DHT usage.

View File

@ -323,7 +323,8 @@ size_t DefaultBtInteractive::receiveMessages() {
break;
}
}
if(countOldOutstandingRequest >= maxOutstandingRequest_ &&
if(!pieceStorage_->isEndGame() &&
countOldOutstandingRequest >= maxOutstandingRequest_ &&
dispatcher_->countOutstandingRequest() == 0){
maxOutstandingRequest_ =
std::min((size_t)UB_MAX_OUTSTANDING_REQUEST,
@ -394,6 +395,12 @@ void DefaultBtInteractive::fillPiece(size_t maxMissingBlock) {
}
void DefaultBtInteractive::addRequests() {
if(!pieceStorage_->isEndGame() && !pieceStorage_->hasMissingUnusedPiece()) {
pieceStorage_->enterEndGame();
}
if(pieceStorage_->isEndGame()) {
maxOutstandingRequest_ = 2;
}
fillPiece(maxOutstandingRequest_);
size_t reqNumToCreate =
maxOutstandingRequest_ <= dispatcher_->countOutstandingRequest() ?
@ -402,6 +409,7 @@ void DefaultBtInteractive::addRequests() {
std::vector<SharedHandle<BtMessage> > requests;
requests.reserve(reqNumToCreate);
if(pieceStorage_->isEndGame()) {
logger_->debug("ENDGAME");
btRequestFactory_->createRequestMessagesOnEndGame(requests,reqNumToCreate);
} else {
btRequestFactory_->createRequestMessages(requests, reqNumToCreate);

View File

@ -71,6 +71,7 @@ DefaultPieceStorage::DefaultPieceStorage
bitfieldMan_(new BitfieldMan(downloadContext->getPieceLength(),
downloadContext->getTotalLength())),
diskWriterFactory_(new DefaultDiskWriterFactory()),
endGame_(false),
endGamePieceNum_(END_GAME_PIECE_NUM),
logger_(LogFactory::getInstance()),
option_(option),
@ -82,11 +83,6 @@ DefaultPieceStorage::~DefaultPieceStorage() {
delete bitfieldMan_;
}
bool DefaultPieceStorage::isEndGame()
{
return bitfieldMan_->countMissingBlock() <= endGamePieceNum_;
}
bool DefaultPieceStorage::getMissingPieceIndex(size_t& index,
const unsigned char* bitfield,
size_t length)

View File

@ -78,6 +78,7 @@ private:
SharedHandle<DiskWriterFactory> diskWriterFactory_;
std::deque<SharedHandle<Piece> > usedPieces_;
bool endGame_;
size_t endGamePieceNum_;
Logger* logger_;
const Option* option_;
@ -187,8 +188,16 @@ public:
virtual bool isSelectiveDownloadingMode();
virtual bool isEndGame();
virtual bool isEndGame()
{
return endGame_;
}
virtual void enterEndGame()
{
endGame_ = true;
}
virtual SharedHandle<DiskAdaptor> getDiskAdaptor();
virtual size_t getPieceLength(size_t index);

View File

@ -189,6 +189,9 @@ public:
virtual bool isEndGame() = 0;
virtual void enterEndGame() = 0;
// TODO We can remove this.
virtual void setEndGamePieceNum(size_t num) = 0;
virtual SharedHandle<DiskAdaptor> getDiskAdaptor() = 0;

View File

@ -211,6 +211,8 @@ public:
return false;
}
virtual void enterEndGame() {}
virtual void setEndGamePieceNum(size_t num) {}
virtual SharedHandle<DiskAdaptor> getDiskAdaptor();

View File

@ -190,8 +190,8 @@ public:
virtual void setEndGamePieceNum(size_t num) {}
void setEndGame(bool flag) {
this->endGame = flag;
virtual void enterEndGame() {
this->endGame = true;
}
virtual SharedHandle<DiskAdaptor> getDiskAdaptor() {