more end-game piece picker optimization (early exit)

This commit is contained in:
Arvid Norberg 2011-02-08 04:08:04 +00:00
parent 73e3bbae7b
commit e079907252
3 changed files with 18 additions and 18 deletions

View File

@ -873,7 +873,6 @@ namespace libtorrent
// the number of times the piece picker fell through
// to the end-game mode
int m_end_game_piece_picker_blocks;
int m_strict_end_game_piece_picker_blocks;
int m_piece_picker_blocks;
int m_piece_picks;
int m_reject_piece_picks;

View File

@ -231,6 +231,18 @@ namespace libtorrent
std::vector<pending_block> const& dq = c.download_queue();
std::vector<pending_block> const& rq = c.request_queue();
// if the number of pieces we have + the number of pieces
// we're requesting from is less than the number of pieces
// in the torrent, there are still some unrequested pieces
// and we're not strictly speaking in end-game mode yet
// also, if we already have at least one outstanding
// request, we shouldn't pick any busy pieces either
bool dont_pick_busy_blocks = (ses.m_settings.strict_end_game_mode
&& p.num_have() + p.get_download_queue().size()
< t.torrent_file().num_pieces())
|| dq.size() + rq.size() > 0;
for (std::vector<piece_block>::iterator i = interesting_pieces.begin();
i != interesting_pieces.end(); ++i)
{
@ -243,8 +255,14 @@ namespace libtorrent
int num_block_requests = p.num_peers(*i);
if (num_block_requests > 0)
{
// have we picked enough pieces?
if (num_requests <= 0) break;
// this block is busy. This means all the following blocks
// in the interesting_pieces list are busy as well, we might
// as well just exit the loop
if (dont_pick_busy_blocks) break;
// if this piece already has the max number of requests to it,
// no need to consider it, since we won't send another request anyway
if (num_block_requests >= ses.m_settings.max_duplicate_block_requests)
@ -317,19 +335,6 @@ namespace libtorrent
++ses.m_end_game_piece_picker_blocks;
#endif
// if the number of pieces we have + the number of pieces
// we're requesting from is less than the number of pieces
// in the torrent, there are still some unrequested pieces
// and we're not strictly speaking in end-game mode yet
if (t.settings().strict_end_game_mode
&& p.num_have() + p.get_download_queue().size()
< t.torrent_file().num_pieces())
return;
#ifdef TORRENT_STATS
++ses.m_strict_end_game_piece_picker_blocks;
#endif
// if all blocks has the same number of peers on them
// we want to pick a random block
std::random_shuffle(busy_pieces.begin(), busy_pieces.end());

View File

@ -806,7 +806,6 @@ namespace aux {
":outstanding requests:outstanding end-game requests"
":outstanding writing blocks"
":end game piece picker blocks"
":strict end game piece picker blocks"
":piece picker blocks"
":piece picks"
":reject piece picks"
@ -825,7 +824,6 @@ namespace aux {
m_eof_peers = 0;
m_connreset_peers = 0;
m_end_game_piece_picker_blocks = 0;
m_strict_end_game_piece_picker_blocks = 0;
m_piece_picker_blocks = 0;
m_piece_picks = 0;
m_reject_piece_picks = 0;
@ -2697,7 +2695,6 @@ namespace aux {
<< outstanding_end_game_requests << "\t"
<< outstanding_write_blocks << "\t"
<< m_end_game_piece_picker_blocks << "\t"
<< m_strict_end_game_piece_picker_blocks << "\t"
<< m_piece_picker_blocks << "\t"
<< m_piece_picks << "\t"
<< m_reject_piece_picks << "\t"
@ -2715,7 +2712,6 @@ namespace aux {
m_eof_peers = 0;
m_connreset_peers = 0;
m_end_game_piece_picker_blocks = 0;
m_strict_end_game_piece_picker_blocks = 0;
m_piece_picker_blocks = 0;
m_piece_picks = 0;
m_reject_piece_picks = 0;