forked from premiere/premiere-libtorrent
modified the hueristic for taking over blocks slightly, added logging
This commit is contained in:
parent
1271334f95
commit
79ebcf5dd8
|
@ -1041,8 +1041,9 @@ namespace libtorrent
|
|||
// peer that has taken over it.
|
||||
boost::optional<tcp::endpoint> peer
|
||||
= t->picker().get_downloader(block_finished);
|
||||
if (!t->picker().is_finished(block_finished) && peer)
|
||||
if (peer)
|
||||
{
|
||||
assert(!t->picker().is_finished(block_finished));
|
||||
peer_connection* pc = t->connection_for(*peer);
|
||||
if (pc && pc != this)
|
||||
{
|
||||
|
|
|
@ -1163,14 +1163,17 @@ namespace libtorrent
|
|||
|
||||
assert(block.block_index < blocks_in_piece(block.piece_index));
|
||||
#ifndef NDEBUG
|
||||
if (i->requested_blocks[block.block_index] != 1)
|
||||
if (i->requested_blocks[block.block_index] == false)
|
||||
{
|
||||
assert(false);
|
||||
}
|
||||
#endif
|
||||
|
||||
// clear this block as being downloaded
|
||||
i->requested_blocks[block.block_index] = 0;
|
||||
i->requested_blocks[block.block_index] = false;
|
||||
|
||||
// clear the downloader of this block
|
||||
i->info[block.block_index].peer = tcp::endpoint();
|
||||
|
||||
// if there are no other blocks in this piece
|
||||
// that's being downloaded, remove it from the list
|
||||
|
|
|
@ -181,25 +181,35 @@ namespace
|
|||
const std::deque<piece_block>& request_queue = i->second->request_queue();
|
||||
const int queue_size = (int)i->second->download_queue().size()
|
||||
+ (int)i->second->request_queue().size();
|
||||
const float weight = queue_size == 0
|
||||
|
||||
bool in_request_queue = std::find_first_of(
|
||||
busy_pieces.begin()
|
||||
, busy_pieces.end()
|
||||
, request_queue.begin()
|
||||
, request_queue.end()) != busy_pieces.end();
|
||||
|
||||
bool in_download_queue = std::find_first_of(
|
||||
busy_pieces.begin()
|
||||
, busy_pieces.end()
|
||||
, download_queue.begin()
|
||||
, download_queue.end()) != busy_pieces.end();
|
||||
|
||||
// if the block is in the request queue rather than the download queue
|
||||
// (i.e. the request message hasn't been sent yet) lower the weight in
|
||||
// order to prioritize it. Taking over a block in the request queue is
|
||||
// free in terms of redundant download. A block that already has been
|
||||
// requested is likely to be in transit already, and would in that case
|
||||
// mean redundant data to receive.
|
||||
const float weight = (queue_size == 0)
|
||||
? std::numeric_limits<float>::max()
|
||||
: i->second->statistics().download_payload_rate() / queue_size;
|
||||
: i->second->statistics().download_payload_rate() / queue_size
|
||||
* in_request_queue ? .1f : 1.f;
|
||||
|
||||
// if the peer's (i) weight is less than the lowest we've found so
|
||||
// far (weight == priority) and it has blocks in its request-
|
||||
// or download queue that we could request from this peer (c),
|
||||
// replace the currently lowest ranking peer.
|
||||
if (weight < min_weight
|
||||
&& (std::find_first_of(
|
||||
busy_pieces.begin()
|
||||
, busy_pieces.end()
|
||||
, request_queue.begin()
|
||||
, request_queue.end()) != busy_pieces.end()
|
||||
|| std::find_first_of(
|
||||
busy_pieces.begin()
|
||||
, busy_pieces.end()
|
||||
, download_queue.begin()
|
||||
, download_queue.end()) != busy_pieces.end()))
|
||||
if (weight < min_weight && (in_request_queue || in_download_queue))
|
||||
{
|
||||
peer = i->second;
|
||||
min_weight = weight;
|
||||
|
|
|
@ -209,6 +209,7 @@ namespace
|
|||
<< "16. bytes received 10 seconds mean\n"
|
||||
<< "17. total payload download\n"
|
||||
<< "18. total web seed payload download\n"
|
||||
<< "19. total redundant bytes downloaded\n"
|
||||
<< "\n";
|
||||
}
|
||||
#endif
|
||||
|
@ -2015,6 +2016,7 @@ namespace libtorrent
|
|||
<< mean_dl << "\t"
|
||||
<< m_stat.total_payload_download() << "\t"
|
||||
<< m_web_stat.total_payload_download() << "\t"
|
||||
<< m_total_redundant_bytes
|
||||
<< "\n";
|
||||
|
||||
(*m_log)
|
||||
|
|
Loading…
Reference in New Issue