made piece picker less anal about speed categories, to improve performance

This commit is contained in:
Arvid Norberg 2007-07-05 22:49:28 +00:00
parent 0e1e1484ee
commit f90a80ab05
3 changed files with 30 additions and 17 deletions

View File

@ -1071,21 +1071,31 @@ namespace libtorrent
namespace
{
bool exclusively_requested_from(piece_picker::downloading_piece const& p
// the first bool is true if this is the only peer that has requested and downloaded
// blocks from this piece.
// the second bool is true if this is the only active peer that is requesting
// and downloading blocks from this piece. Active means having a connection.
boost::tuple<bool, bool> requested_from(piece_picker::downloading_piece const& p
, int num_blocks_in_piece, void* peer)
{
bool exclusive = true;
bool exclusive_active = true;
for (int j = 0; j < num_blocks_in_piece; ++j)
{
piece_picker::block_info const& info = p.info[j];
if (info.state != piece_picker::block_info::state_none
&& info.peer != peer
&& info.peer != 0
&& static_cast<policy::peer*>(info.peer)->connection)
&& info.peer != peer)
{
return false;
exclusive = false;
if (info.peer == 0
|| static_cast<policy::peer*>(info.peer)->connection == 0)
{
exclusive_active = false;
return boost::make_tuple(exclusive, exclusive_active);
}
}
}
return true;
return boost::make_tuple(exclusive, exclusive_active);
}
}
@ -1120,8 +1130,10 @@ namespace libtorrent
// is true if all the other pieces that are currently
// requested from this piece are from the same
// peer as 'peer'.
bool only_same_peer = exclusively_requested_from(*p
, num_blocks_in_piece, peer);
bool exclusive;
bool exclusive_active;
boost::tie(exclusive, exclusive_active)
= requested_from(*p, num_blocks_in_piece, peer);
// this means that this partial piece has
// been downloaded/requested partially from
@ -1130,7 +1142,7 @@ namespace libtorrent
// blocks to the backup list. If the prioritized
// blocks aren't enough, blocks from this list
// will be picked.
if (prefer_whole_pieces && !only_same_peer)
if (prefer_whole_pieces && !exclusive)
{
if (int(backup_blocks.size()) >= num_blocks) continue;
for (int j = 0; j < num_blocks_in_piece; ++j)
@ -1164,7 +1176,7 @@ namespace libtorrent
// if the state of the piece is none (the
// piece will in that case change state).
if (p->state != none && p->state != speed
&& !only_same_peer
&& !exclusive_active
&& !ignore_speed_categories)
{
if (int(backup_blocks.size()) >= num_blocks) continue;

View File

@ -149,7 +149,7 @@ struct peer_connection
bool m_prioritized;
bool m_ignore_limits;
bool m_abort;
stat m_stats;
libtorrent::stat m_stats;
io_service& m_ios;
std::string m_name;
int m_refs;
@ -192,7 +192,7 @@ void run_test(io_service& ios, connections_t& v)
tick.async_wait(boost::bind(&do_tick, _1, boost::ref(tick), boost::ref(v)));
deadline_timer complete(ios);
complete.expires_from_now(seconds(stat::history * 2));
complete.expires_from_now(seconds(libtorrent::stat::history * 2));
complete.async_wait(boost::bind(&do_stop, boost::ref(tick), boost::ref(v)));
std::for_each(v.begin(), v.end()

View File

@ -188,9 +188,10 @@ int test_main()
piece_block expected4[] =
{
piece_block(2, 0), piece_block(2, 1)
, piece_block(2, 2), piece_block(2, 3)
piece_block(3, 0), piece_block(3, 1)
, piece_block(3, 2), piece_block(3, 3)
};
TEST_CHECK(std::equal(picked.begin()
, picked.end(), expected4));
@ -204,12 +205,12 @@ int test_main()
piece_block expected5[] =
{
piece_block(2, 0), piece_block(2, 1)
, piece_block(2, 2), piece_block(2, 3)
, piece_block(3, 0), piece_block(3, 1)
piece_block(3, 0), piece_block(3, 1)
, piece_block(3, 2), piece_block(3, 3)
, piece_block(5, 0), piece_block(5, 1)
, piece_block(5, 2), piece_block(5, 3)
, piece_block(2, 0), piece_block(2, 1)
, piece_block(2, 2), piece_block(2, 3)
};
TEST_CHECK(std::equal(picked.begin()