remove remainder of eviction/ghost torrent feature (#1251)

remove remainder of eviction/ghost torrent feature
This commit is contained in:
Arvid Norberg 2016-10-25 08:02:34 -04:00 committed by GitHub
parent 8bdbaec872
commit 675d16a2c3
13 changed files with 56 additions and 87 deletions

View File

@ -85,6 +85,14 @@ for l in f:
l = l.strip()
if mode == 'ignore':
if '#endif' in l: mode = ''
continue
if 'TORRENT_NO_DEPRECATE' in l:
mode = 'ignore'
continue
if description_line == True:
if len(names) > 0:
render_section(names, description, types)

View File

@ -564,43 +564,6 @@ aligned.
.. _`BEP 17`: http://bittorrent.org/beps/bep_0017.html
.. _`BEP 19`: http://bittorrent.org/beps/bep_0019.html
dynamic loading of torrent files
================================
libtorrent has a feature that can unload idle torrents from memory. The purpose
of this is to support being active on many more torrents than the RAM permits.
This is useful for both embedded devices that have limited RAM and servers
seeding tens of thousands of torrents.
The most significant parts of loaded torrents that use RAM are the piece
hashes (20 bytes per piece) and the file list. The entire info-dictionary
of the .torrent file is kept in RAM.
In order to activate the dynamic loading of torrent files, set the load
function on the session. See set_load_function().
When a load function is set on the session, the dynamic load/unload
feature is enabled. Torrents are kept in an LRU. Every time an operation
is performed, on a torrent or from a peer, that requires the metadata of
the torrent to be loaded, the torrent is bumped up in the LRU. When a torrent
is paused or queued, it is demoted to the least recently used torrent in
the LRU, since it's a good candidate for eviction.
To configure how many torrents are allowed to be loaded at the same time,
set settings_pack::active_loaded_limit on the session.
Torrents can be exempt from being unloaded by being *pinned*. Pinned torrents
still count against the limit, but are never considered for eviction.
You can either pin a torrent when adding it, in ``add_torrent_params``
(see async_add_torrent() and add_torrent()), or after ading it with the
set_pinned() function on torrent_handle.
Torrents that start out without metadata (e.g. magnet links or http downloads)
are automatically pinned. This is important in order to give the client a
chance to save the metadata to disk once it's received (see metadata_received_alert).
Once the metadata is saved to disk, it might make sense to unpin the torrent.
piece picker
============

View File

@ -573,20 +573,6 @@ void signal_handler(int)
quit = true;
}
void load_torrent(libtorrent::sha1_hash const& ih, std::vector<char>& buf, libtorrent::error_code& ec)
{
files_t::iterator i = hash_to_filename.find(ih);
if (i == hash_to_filename.end())
{
// for magnet links and torrents downloaded via
// URL, the metadata is saved in the resume file
// TODO: pick up metadata from the resume file
ec.assign(boost::system::errc::no_such_file_or_directory, boost::system::generic_category());
return;
}
load_file(i->second, buf, ec);
}
// if non-empty, a peer that will be added to all torrents
std::string peer;
@ -1213,7 +1199,6 @@ int main(int argc, char* argv[])
settings_pack settings;
settings.set_int(settings_pack::cache_size, cache_size);
settings.set_int(settings_pack::active_loaded_limit, 20);
settings.set_int(settings_pack::choking_algorithm, settings_pack::rate_based_choker);
int refresh_delay = 500;
@ -1393,7 +1378,6 @@ int main(int argc, char* argv[])
}
ses.set_ip_filter(loaded_ip_filter);
ses.set_load_function(&load_torrent);
error_code ec;

View File

@ -254,7 +254,7 @@ void torrent_view::print_tabs()
char str[400];
int pos = 0;
char const* filter_names[] = { "all", "downloading", "non-paused"
, "seeding", "queued", "stopped", "checking", "loaded"};
, "seeding", "queued", "stopped", "checking"};
for (int i = 0; i < int(sizeof(filter_names)/sizeof(filter_names[0])); ++i)
{
pos += std::snprintf(str+ pos, sizeof(str) - pos, "%s[%s]%s"

View File

@ -221,9 +221,6 @@ namespace libtorrent
void start_session(settings_pack pack);
void set_load_function(user_load_function_t fun)
{ m_user_load_torrent = fun; }
void init_peer_class_filter(bool unlimited_local);
#ifndef TORRENT_DISABLE_EXTENSIONS
@ -295,6 +292,12 @@ namespace libtorrent
std::weak_ptr<torrent> find_torrent(sha1_hash const& info_hash) const override;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
TORRENT_DEPRECATED
void set_load_function(user_load_function_t fun)
{ m_user_load_torrent = fun; }
TORRENT_DEPRECATED
std::weak_ptr<torrent> find_torrent(std::string const& uuid) const;
#endif
#ifndef TORRENT_DISABLE_MUTABLE_TORRENTS
@ -308,6 +311,7 @@ namespace libtorrent
, std::string uuid) override;
#ifndef TORRENT_NO_DEPRECATE
//deprecated in 1.2
TORRENT_DEPRECATED
void insert_uuid_torrent(std::string uuid, std::shared_ptr<torrent> const& t) override
{ m_uuids.insert(std::make_pair(uuid, t)); }
#endif
@ -368,7 +372,9 @@ namespace libtorrent
, void* userdata = nullptr);
#ifndef TORRENT_NO_DEPRECATE
TORRENT_DEPRECATED
entry dht_state() const;
TORRENT_DEPRECATED
void start_dht_deprecated(entry const& startup_state);
#endif
void on_dht_announce(error_code const& e);
@ -465,23 +471,23 @@ namespace libtorrent
alert* wait_for_alert(time_duration max_wait);
#ifndef TORRENT_NO_DEPRECATE
void pop_alerts();
alert const* pop_alert();
size_t set_alert_queue_size_limit(size_t queue_size_limit_);
int upload_rate_limit_depr() const;
int download_rate_limit_depr() const;
int local_upload_rate_limit() const;
int local_download_rate_limit() const;
TORRENT_DEPRECATED void pop_alerts();
TORRENT_DEPRECATED alert const* pop_alert();
TORRENT_DEPRECATED size_t set_alert_queue_size_limit(size_t queue_size_limit_);
TORRENT_DEPRECATED int upload_rate_limit_depr() const;
TORRENT_DEPRECATED int download_rate_limit_depr() const;
TORRENT_DEPRECATED int local_upload_rate_limit() const;
TORRENT_DEPRECATED int local_download_rate_limit() const;
void set_local_download_rate_limit(int bytes_per_second);
void set_local_upload_rate_limit(int bytes_per_second);
void set_download_rate_limit_depr(int bytes_per_second);
void set_upload_rate_limit_depr(int bytes_per_second);
void set_max_connections(int limit);
void set_max_uploads(int limit);
TORRENT_DEPRECATED void set_local_download_rate_limit(int bytes_per_second);
TORRENT_DEPRECATED void set_local_upload_rate_limit(int bytes_per_second);
TORRENT_DEPRECATED void set_download_rate_limit_depr(int bytes_per_second);
TORRENT_DEPRECATED void set_upload_rate_limit_depr(int bytes_per_second);
TORRENT_DEPRECATED void set_max_connections(int limit);
TORRENT_DEPRECATED void set_max_uploads(int limit);
int max_connections() const;
int max_uploads() const;
TORRENT_DEPRECATED int max_connections() const;
TORRENT_DEPRECATED int max_uploads() const;
#endif
bandwidth_manager* get_bandwidth_manager(int channel) override;
@ -1173,9 +1179,11 @@ namespace libtorrent
std::array<std::vector<std::shared_ptr<plugin>>, 4> m_ses_extensions;
#endif
#ifndef TORRENT_NO_DEPRECATE
// if this function is set, it indicates that torrents are allowed
// to be unloaded. If it isn't, torrents will never be unloaded
user_load_function_t m_user_load_torrent;
#endif
// this is true whenever we have posted a deferred-disk job
// it means we don't need to post another one

View File

@ -131,7 +131,9 @@ namespace libtorrent
on_disk_queue_counter,
on_disk_counter,
#ifndef TORRENT_NO_DEPRECATE
torrent_evicted_counter,
#endif
// bittorrent message counters
// TODO: should keepalives be in here too?

View File

@ -260,6 +260,7 @@ namespace libtorrent
void resume();
bool is_paused() const;
#ifndef TORRENT_NO_DEPRECATE
// This function enables dynamic-loading-of-torrent-files_. When a
// torrent is unloaded but needs to be available in memory, this function
// is called **from within the libtorrent network thread**. From within
@ -280,9 +281,9 @@ namespace libtorrent
// The signature of the function to pass in is::
//
// void fun(sha1_hash const& info_hash, std::vector<char>& buf, error_code& ec);
TORRENT_DEPRECATED
void set_load_function(user_load_function_t fun);
#ifndef TORRENT_NO_DEPRECATE
// deprecated in libtorrent 1.1, use performance_counters instead
// returns session wide-statistics and status. For more information, see
// the ``session_status`` struct.

View File

@ -1045,7 +1045,15 @@ namespace libtorrent
// about you for any reason and tries to connect, it will still be
// accepted, unless the torrent is paused, which means it won't accept
// any connections.
//
active_downloads,
active_seeds,
active_checking,
active_dht_limit,
active_tracker_limit,
active_lsd_limit,
active_limit,
#ifndef TORRENT_NO_DEPRECATE
// ``active_loaded_limit`` is the number of torrents that are allowed
// to be *loaded* at any given time. Note that a torrent can be active
// even though it's not loaded. If an unloaded torrents finds a peer
@ -1054,14 +1062,10 @@ namespace libtorrent
// unloading torrents is not enabled, this setting have no effect. If
// this limit is set to 0, it means unlimited. For more information,
// see dynamic-loading-of-torrent-files_.
active_downloads,
active_seeds,
active_checking,
active_dht_limit,
active_tracker_limit,
active_lsd_limit,
active_limit,
active_loaded_limit,
#else
deprecated20,
#endif
// ``auto_manage_interval`` is the number of seconds between the
// torrent queue is updated, and rotated.

View File

@ -118,8 +118,6 @@ TORRENT_TEST(session_stats)
std::vector<stats_metric> stats = session_stats_metrics();
int const downloading_idx = find_metric_idx("ses.num_downloading_torrents");
TEST_CHECK(downloading_idx >= 0);
int const evicted_idx = find_metric_idx("ses.torrent_evicted_counter");
TEST_CHECK(evicted_idx >= 0);
int const incoming_extended_idx = find_metric_idx("ses.num_incoming_extended");
TEST_CHECK(incoming_extended_idx >= 0);
@ -136,7 +134,6 @@ TORRENT_TEST(session_stats)
// there's one downloading torrent
TEST_EQUAL(ss->values[downloading_idx], 1);
TEST_EQUAL(ss->values[evicted_idx], 0);
TEST_EQUAL(ss->values[incoming_extended_idx], 1);
}
// terminate

View File

@ -421,12 +421,12 @@ namespace libtorrent
return sync_call_ret<bool>(&session_impl::is_paused);
}
#ifndef TORRENT_NO_DEPRECATE
void session_handle::set_load_function(user_load_function_t fun)
{
async_call(&session_impl::set_load_function, fun);
}
#ifndef TORRENT_NO_DEPRECATE
session_status session_handle::status() const
{
return sync_call_ret<session_status>(&session_impl::status);

View File

@ -230,10 +230,12 @@ namespace libtorrent
METRIC(ses, num_have_pieces)
METRIC(ses, num_total_pieces_added)
#ifndef TORRENT_NO_DEPRECATE
// this counts the number of times a torrent has been
// evicted (only applies when `dynamic loading of torrent files`_
// is enabled).
METRIC(ses, torrent_evicted_counter)
#endif
// the number of allowed unchoked peers
METRIC(ses, num_unchoke_slots)

View File

@ -240,7 +240,7 @@ namespace libtorrent
SET(active_tracker_limit, 1600, nullptr),
SET(active_lsd_limit, 60, nullptr),
SET(active_limit, 15, &session_impl::trigger_auto_manage),
SET(active_loaded_limit, 100, &session_impl::trigger_auto_manage),
DEPRECATED_SET(active_loaded_limit, 100, &session_impl::trigger_auto_manage),
SET(auto_manage_interval, 30, nullptr),
SET(seed_time_limit, 24 * 60 * 60, nullptr),
SET(auto_scrape_interval, 1800, nullptr),

View File

@ -490,7 +490,7 @@ reports = [
'disk.arc_mfu_ghost_size' \
], {'allow-negative': True}),
('torrent churn', 'num torrents', '', '', ['ses.num_loaded_torrents', 'ses.num_pinned_torrents', 'ses.torrent_evicted_counter']),
('torrent churn', 'num torrents', '', '', ['ses.num_loaded_torrents', 'ses.num_pinned_torrents']),
('pinned torrents', 'num torrents', '', '', ['ses.num_pinned_torrents']),
('loaded torrents', 'num torrents', '', '', ['ses.num_loaded_torrents', 'ses.num_pinned_torrents']),
('request latency', 'us', '', 'latency from receiving requests to sending response', ['disk.request_latency']),