forked from premiere/premiere-libtorrent
parent
c3e1e405b2
commit
46b33f920b
|
@ -62,8 +62,6 @@ void bind_session_settings()
|
||||||
.def_readwrite("cache_buffer_chunk_size", &session_settings::cache_buffer_chunk_size)
|
.def_readwrite("cache_buffer_chunk_size", &session_settings::cache_buffer_chunk_size)
|
||||||
.def_readwrite("cache_expiry", &session_settings::cache_expiry)
|
.def_readwrite("cache_expiry", &session_settings::cache_expiry)
|
||||||
.def_readwrite("use_read_cache", &session_settings::use_read_cache)
|
.def_readwrite("use_read_cache", &session_settings::use_read_cache)
|
||||||
.def_readwrite("explicit_read_cache", &session_settings::explicit_read_cache)
|
|
||||||
.def_readwrite("explicit_cache_interval", &session_settings::explicit_cache_interval)
|
|
||||||
.def_readwrite("disk_io_write_mode", &session_settings::disk_io_write_mode)
|
.def_readwrite("disk_io_write_mode", &session_settings::disk_io_write_mode)
|
||||||
.def_readwrite("disk_io_read_mode", &session_settings::disk_io_read_mode)
|
.def_readwrite("disk_io_read_mode", &session_settings::disk_io_read_mode)
|
||||||
.def_readwrite("coalesce_reads", &session_settings::coalesce_reads)
|
.def_readwrite("coalesce_reads", &session_settings::coalesce_reads)
|
||||||
|
|
|
@ -956,17 +956,6 @@ namespace libtorrent
|
||||||
// torrents.
|
// torrents.
|
||||||
int m_auto_scrape_time_scaler;
|
int m_auto_scrape_time_scaler;
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// the index of the torrent that we'll
|
|
||||||
// refresh the next time
|
|
||||||
int m_next_explicit_cache_torrent;
|
|
||||||
|
|
||||||
// this is a counter of the number of seconds until
|
|
||||||
// the next time the read cache is rotated, if we're
|
|
||||||
// using an explicit read read cache.
|
|
||||||
int m_cache_rotation_timer;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// the index of the torrent that we'll
|
// the index of the torrent that we'll
|
||||||
// refresh the next time
|
// refresh the next time
|
||||||
int m_next_suggest_torrent;
|
int m_next_suggest_torrent;
|
||||||
|
|
|
@ -451,26 +451,6 @@ namespace libtorrent
|
||||||
// once we want to calculate the piece hash
|
// once we want to calculate the piece hash
|
||||||
bool dont_flush_write_cache;
|
bool dont_flush_write_cache;
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// defaults to 0. If set to something greater than 0, the disk read cache
|
|
||||||
// will not be evicted by cache misses and will explicitly be controlled
|
|
||||||
// based on the rarity of pieces. Rare pieces are more likely to be
|
|
||||||
// cached. This would typically be used together with ``suggest_mode``
|
|
||||||
// set to ``suggest_read_cache``. The value is the number of pieces to
|
|
||||||
// keep in the read cache. If the actual read cache can't fit as many, it
|
|
||||||
// will essentially be clamped.
|
|
||||||
bool explicit_read_cache;
|
|
||||||
|
|
||||||
// the number of seconds in between each refresh of a part of the
|
|
||||||
// explicit read cache. Torrents take turns in refreshing and this is the
|
|
||||||
// time in between each torrent refresh. Refreshing a torrent's explicit
|
|
||||||
// read cache means scanning all pieces and picking a random set of the
|
|
||||||
// rarest ones. There is an affinity to pick pieces that are already in
|
|
||||||
// the cache, so that subsequent refreshes only swaps in pieces that are
|
|
||||||
// rarer than whatever is in the cache at the time.
|
|
||||||
int explicit_cache_interval;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// the buffer modes to use for reading and writing. Set
|
// the buffer modes to use for reading and writing. Set
|
||||||
// session_settings::disk_io_read_mode and disk_io_write_mode to one of
|
// session_settings::disk_io_read_mode and disk_io_write_mode to one of
|
||||||
// these.
|
// these.
|
||||||
|
|
|
@ -284,20 +284,6 @@ namespace libtorrent
|
||||||
// hash
|
// hash
|
||||||
dont_flush_write_cache,
|
dont_flush_write_cache,
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// ``explicit_read_cache`` defaults to 0. If set to something greater
|
|
||||||
// than 0, the disk read cache will not be evicted by cache misses and
|
|
||||||
// will explicitly be controlled based on the rarity of pieces. Rare
|
|
||||||
// pieces are more likely to be cached. This would typically be used
|
|
||||||
// together with ``suggest_mode`` set to ``suggest_read_cache``. The
|
|
||||||
// value is the number of pieces to keep in the read cache. If the
|
|
||||||
// actual read cache can't fit as many, it will essentially be
|
|
||||||
// clamped.
|
|
||||||
explicit_read_cache,
|
|
||||||
#else
|
|
||||||
deprecated12,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// allocate separate, contiguous, buffers for read and write calls.
|
// allocate separate, contiguous, buffers for read and write calls.
|
||||||
// Only used where writev/readv cannot be used will use more RAM but
|
// Only used where writev/readv cannot be used will use more RAM but
|
||||||
// may improve performance
|
// may improve performance
|
||||||
|
@ -942,20 +928,6 @@ namespace libtorrent
|
||||||
cache_buffer_chunk_size,
|
cache_buffer_chunk_size,
|
||||||
cache_expiry,
|
cache_expiry,
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// ``explicit_cache_interval`` is the number of seconds in between
|
|
||||||
// each refresh of a part of the explicit read cache. Torrents take
|
|
||||||
// turns in refreshing and this is the time in between each torrent
|
|
||||||
// refresh. Refreshing a torrent's explicit read cache means scanning
|
|
||||||
// all pieces and picking a random set of the rarest ones. There is an
|
|
||||||
// affinity to pick pieces that are already in the cache, so that
|
|
||||||
// subsequent refreshes only swaps in pieces that are rarer than
|
|
||||||
// whatever is in the cache at the time.
|
|
||||||
explicit_cache_interval,
|
|
||||||
#else
|
|
||||||
deprecated13,
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// determines how files are opened when they're in read only mode
|
// determines how files are opened when they're in read only mode
|
||||||
// versus read and write mode. The options are:
|
// versus read and write mode. The options are:
|
||||||
//
|
//
|
||||||
|
|
|
@ -655,10 +655,6 @@ namespace libtorrent
|
||||||
void get_peer_info(std::vector<peer_info>* v);
|
void get_peer_info(std::vector<peer_info>* v);
|
||||||
void get_download_queue(std::vector<partial_piece_info>* queue) const;
|
void get_download_queue(std::vector<partial_piece_info>* queue) const;
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
void refresh_explicit_cache(int cache_size);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void add_suggest_piece(int piece);
|
void add_suggest_piece(int piece);
|
||||||
void update_suggest_piece(int index, int change);
|
void update_suggest_piece(int index, int change);
|
||||||
void update_auto_sequential();
|
void update_auto_sequential();
|
||||||
|
@ -1135,8 +1131,6 @@ namespace libtorrent
|
||||||
void set_limit_impl(int limit, int channel, bool state_update = true);
|
void set_limit_impl(int limit, int channel, bool state_update = true);
|
||||||
int limit_impl(int channel) const;
|
int limit_impl(int channel) const;
|
||||||
|
|
||||||
void refresh_explicit_cache_impl(disk_io_job const* j, int cache_size);
|
|
||||||
|
|
||||||
int prioritize_tracker(int tracker_index);
|
int prioritize_tracker(int tracker_index);
|
||||||
int deprioritize_tracker(int tracker_index);
|
int deprioritize_tracker(int tracker_index);
|
||||||
|
|
||||||
|
|
|
@ -308,32 +308,6 @@ TORRENT_TEST(stop_start_seed_graceful)
|
||||||
test_stop_start_download(swarm_test::upload, true);
|
test_stop_start_download(swarm_test::upload, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
TORRENT_TEST(explicit_cache)
|
|
||||||
{
|
|
||||||
setup_swarm(2, swarm_test::download
|
|
||||||
// add session
|
|
||||||
, [](lt::settings_pack& pack) {
|
|
||||||
pack.set_int(settings_pack::suggest_mode, settings_pack::suggest_read_cache);
|
|
||||||
pack.set_bool(settings_pack::explicit_read_cache, true);
|
|
||||||
pack.set_int(settings_pack::explicit_cache_interval, 5);
|
|
||||||
}
|
|
||||||
// add torrent
|
|
||||||
, [](lt::add_torrent_params& params) {}
|
|
||||||
// on alert
|
|
||||||
, [](lt::alert const* a, lt::session& ses) {}
|
|
||||||
// terminate
|
|
||||||
, [](int ticks, lt::session& ses) -> bool
|
|
||||||
{
|
|
||||||
if (ticks > 80)
|
|
||||||
{
|
|
||||||
TEST_ERROR("timeout");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (!is_seed(ses)) return false;
|
|
||||||
return true;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
TORRENT_TEST(shutdown)
|
TORRENT_TEST(shutdown)
|
||||||
{
|
{
|
||||||
setup_swarm(2, swarm_test::download
|
setup_swarm(2, swarm_test::download
|
||||||
|
|
|
@ -397,10 +397,6 @@ namespace aux {
|
||||||
, m_optimistic_unchoke_time_scaler(0)
|
, m_optimistic_unchoke_time_scaler(0)
|
||||||
, m_disconnect_time_scaler(90)
|
, m_disconnect_time_scaler(90)
|
||||||
, m_auto_scrape_time_scaler(180)
|
, m_auto_scrape_time_scaler(180)
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
, m_next_explicit_cache_torrent(0)
|
|
||||||
, m_cache_rotation_timer(0)
|
|
||||||
#endif
|
|
||||||
, m_next_suggest_torrent(0)
|
, m_next_suggest_torrent(0)
|
||||||
, m_suggest_timer(0)
|
, m_suggest_timer(0)
|
||||||
, m_peak_up_rate(0)
|
, m_peak_up_rate(0)
|
||||||
|
@ -3439,44 +3435,6 @@ namespace aux {
|
||||||
++m_next_suggest_torrent;
|
++m_next_suggest_torrent;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
// refresh explicit disk read cache
|
|
||||||
// --------------------------------------------------------------
|
|
||||||
--m_cache_rotation_timer;
|
|
||||||
if (m_settings.get_bool(settings_pack::explicit_read_cache)
|
|
||||||
&& m_cache_rotation_timer <= 0)
|
|
||||||
{
|
|
||||||
INVARIANT_CHECK;
|
|
||||||
m_cache_rotation_timer = m_settings.get_int(settings_pack::explicit_cache_interval);
|
|
||||||
|
|
||||||
torrent_map::iterator least_recently_refreshed = m_torrents.begin();
|
|
||||||
if (m_next_explicit_cache_torrent >= int(m_torrents.size()))
|
|
||||||
m_next_explicit_cache_torrent = 0;
|
|
||||||
|
|
||||||
std::advance(least_recently_refreshed, m_next_explicit_cache_torrent);
|
|
||||||
|
|
||||||
// how many blocks does this torrent get?
|
|
||||||
int cache_size = (std::max)(0, m_settings.get_int(settings_pack::cache_size) * 9 / 10);
|
|
||||||
|
|
||||||
if (m_connections.empty())
|
|
||||||
{
|
|
||||||
// if we don't have any connections at all, split the
|
|
||||||
// cache evenly across all torrents
|
|
||||||
cache_size = cache_size / (std::max)(int(m_torrents.size()), 1);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
cache_size = cache_size * least_recently_refreshed->second->num_peers()
|
|
||||||
/ int(m_connections.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (least_recently_refreshed != m_torrents.end())
|
|
||||||
least_recently_refreshed->second->refresh_explicit_cache(cache_size);
|
|
||||||
++m_next_explicit_cache_torrent;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
// connect new peers
|
// connect new peers
|
||||||
// --------------------------------------------------------------
|
// --------------------------------------------------------------
|
||||||
|
|
|
@ -156,7 +156,6 @@ namespace libtorrent
|
||||||
SET(use_read_cache, true, 0),
|
SET(use_read_cache, true, 0),
|
||||||
DEPRECATED_SET(use_write_cache, true, 0),
|
DEPRECATED_SET(use_write_cache, true, 0),
|
||||||
SET(dont_flush_write_cache, false, 0),
|
SET(dont_flush_write_cache, false, 0),
|
||||||
DEPRECATED_SET(explicit_read_cache, false, 0),
|
|
||||||
SET(coalesce_reads, false, 0),
|
SET(coalesce_reads, false, 0),
|
||||||
SET(coalesce_writes, false, 0),
|
SET(coalesce_writes, false, 0),
|
||||||
SET(auto_manage_prefer_seeds, false, 0),
|
SET(auto_manage_prefer_seeds, false, 0),
|
||||||
|
@ -255,7 +254,6 @@ namespace libtorrent
|
||||||
SET(cache_size, 1024, 0),
|
SET(cache_size, 1024, 0),
|
||||||
SET(cache_buffer_chunk_size, 0, &session_impl::update_cache_buffer_chunk_size),
|
SET(cache_buffer_chunk_size, 0, &session_impl::update_cache_buffer_chunk_size),
|
||||||
SET(cache_expiry, 300, 0),
|
SET(cache_expiry, 300, 0),
|
||||||
DEPRECATED_SET(explicit_cache_interval, 30, 0),
|
|
||||||
SET(disk_io_write_mode, settings_pack::enable_os_cache, 0),
|
SET(disk_io_write_mode, settings_pack::enable_os_cache, 0),
|
||||||
SET(disk_io_read_mode, settings_pack::enable_os_cache, 0),
|
SET(disk_io_read_mode, settings_pack::enable_os_cache, 0),
|
||||||
SET(outgoing_port, 0, 0),
|
SET(outgoing_port, 0, 0),
|
||||||
|
|
101
src/torrent.cpp
101
src/torrent.cpp
|
@ -9864,107 +9864,6 @@ namespace libtorrent
|
||||||
update_want_peers();
|
update_want_peers();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef TORRENT_NO_DEPRECATE
|
|
||||||
// TODO: 2 this should probably be removed
|
|
||||||
void torrent::refresh_explicit_cache(int cache_size)
|
|
||||||
{
|
|
||||||
TORRENT_ASSERT(is_single_thread());
|
|
||||||
if (!ready_for_connections()) return;
|
|
||||||
|
|
||||||
if (m_abort) return;
|
|
||||||
TORRENT_ASSERT(m_storage);
|
|
||||||
|
|
||||||
if (!is_loaded()) return;
|
|
||||||
|
|
||||||
// rotate the cached pieces
|
|
||||||
cache_status status;
|
|
||||||
m_ses.disk_thread().get_cache_info(&status, false, m_storage.get());
|
|
||||||
|
|
||||||
// add blocks_per_piece / 2 in order to round to closest whole piece
|
|
||||||
int blocks_per_piece = m_torrent_file->piece_length() / block_size();
|
|
||||||
int num_cache_pieces = (cache_size + blocks_per_piece / 2) / blocks_per_piece;
|
|
||||||
if (num_cache_pieces > m_torrent_file->num_pieces())
|
|
||||||
num_cache_pieces = m_torrent_file->num_pieces();
|
|
||||||
|
|
||||||
std::vector<int> avail_vec;
|
|
||||||
if (has_picker())
|
|
||||||
{
|
|
||||||
m_picker->get_availability(avail_vec);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// we don't keep track of availability, do it the expensive way
|
|
||||||
// do a linear search from the first piece
|
|
||||||
for (int i = 0; i < m_torrent_file->num_pieces(); ++i)
|
|
||||||
{
|
|
||||||
int availability = 0;
|
|
||||||
if (!have_piece(i))
|
|
||||||
{
|
|
||||||
avail_vec.push_back(INT_MAX);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const_peer_iterator j = this->begin(); j != this->end(); ++j)
|
|
||||||
if ((*j)->has_piece(i)) ++availability;
|
|
||||||
avail_vec.push_back(availability);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// now pick the num_cache_pieces rarest pieces from avail_vec
|
|
||||||
std::vector<std::pair<int, int> > pieces(m_torrent_file->num_pieces());
|
|
||||||
for (int i = 0; i < m_torrent_file->num_pieces(); ++i)
|
|
||||||
{
|
|
||||||
pieces[i].second = i;
|
|
||||||
if (!have_piece(i)) pieces[i].first = INT_MAX;
|
|
||||||
else pieces[i].first = avail_vec[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove write cache entries
|
|
||||||
status.pieces.erase(std::remove_if(status.pieces.begin(), status.pieces.end()
|
|
||||||
, boost::bind(&cached_piece_info::kind, _1) == cached_piece_info::write_cache)
|
|
||||||
, status.pieces.end());
|
|
||||||
|
|
||||||
// decrease the availability of the pieces that are
|
|
||||||
// already in the read cache, to move them closer to
|
|
||||||
// the beginning of the pieces list, and more likely
|
|
||||||
// to be included in this round of cache pieces
|
|
||||||
for (std::vector<cached_piece_info>::iterator i = status.pieces.begin()
|
|
||||||
, end(status.pieces.end()); i != end; ++i)
|
|
||||||
{
|
|
||||||
--pieces[i->piece].first;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::random_shuffle(pieces.begin(), pieces.end(), randint);
|
|
||||||
std::stable_sort(pieces.begin(), pieces.end()
|
|
||||||
, boost::bind(&std::pair<int, int>::first, _1) <
|
|
||||||
boost::bind(&std::pair<int, int>::first, _2));
|
|
||||||
avail_vec.clear();
|
|
||||||
for (int i = 0; i < num_cache_pieces; ++i)
|
|
||||||
{
|
|
||||||
if (pieces[i].first == INT_MAX) break;
|
|
||||||
avail_vec.push_back(pieces[i].second);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!avail_vec.empty())
|
|
||||||
{
|
|
||||||
// the number of pieces to cache for this torrent is proportional
|
|
||||||
// the number of peers it has, divided by the total number of peers.
|
|
||||||
// Each peer gets an equal share of the cache
|
|
||||||
|
|
||||||
avail_vec.resize((std::min)(num_cache_pieces, int(avail_vec.size())));
|
|
||||||
|
|
||||||
for (std::vector<int>::iterator i = avail_vec.begin()
|
|
||||||
, end(avail_vec.end()); i != end; ++i)
|
|
||||||
{
|
|
||||||
inc_refcount("cache_piece");
|
|
||||||
m_ses.disk_thread().async_cache_piece(m_storage.get(), *i
|
|
||||||
, boost::bind(&torrent::on_disk_cache_complete
|
|
||||||
, shared_from_this(), _1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // TORRENT_NO_DEPRECATE
|
|
||||||
|
|
||||||
void torrent::sent_bytes(int bytes_payload, int bytes_protocol)
|
void torrent::sent_bytes(int bytes_payload, int bytes_protocol)
|
||||||
{
|
{
|
||||||
m_stat.sent_bytes(bytes_payload, bytes_protocol);
|
m_stat.sent_bytes(bytes_payload, bytes_protocol);
|
||||||
|
|
Loading…
Reference in New Issue