From 0c2d3a0dac38276f5c5518bc35b7c0c84a25bf06 Mon Sep 17 00:00:00 2001 From: arvidn Date: Tue, 19 Nov 2019 23:54:14 +0100 Subject: [PATCH] optimize setting with unlimited unchoke slots --- ChangeLog | 1 + include/libtorrent/settings_pack.hpp | 3 ++- src/session.cpp | 4 ++-- src/session_impl.cpp | 29 ++++++++++++++++++++++++++++ 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 14195a7c0..609efa38a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ + * optimize setting with unlimited unchoke slots * fixed restoring of trackers, comment, creation date and created-by in resume data * fix handling of torrents with too large pieces * fixed division by zero in anti-leech choker diff --git a/include/libtorrent/settings_pack.hpp b/include/libtorrent/settings_pack.hpp index 892a83c42..1a026a98a 100644 --- a/include/libtorrent/settings_pack.hpp +++ b/include/libtorrent/settings_pack.hpp @@ -1358,7 +1358,8 @@ namespace aux { // ``unchoke_slots_limit`` is the max number of unchoked peers in the // session. The number of unchoke slots may be ignored depending on - // what ``choking_algorithm`` is set to. + // what ``choking_algorithm`` is set to. Setting this limit to -1 + // means unlimited, i.e. all peers will always be unchoked. unchoke_slots_limit, #if TORRENT_ABI_VERSION == 1 diff --git a/src/session.cpp b/src/session.cpp index dc686b855..247826ec2 100644 --- a/src/session.cpp +++ b/src/session.cpp @@ -205,8 +205,8 @@ namespace { // allow lots of peers to try to connect simultaneously set.set_int(settings_pack::listen_queue_size, 3000); - // unchoke many peers - set.set_int(settings_pack::unchoke_slots_limit, 2000); + // unchoke all peers + set.set_int(settings_pack::unchoke_slots_limit, -1); // use 1 GB of cache set.set_int(settings_pack::cache_size, 32768 * 2); diff --git a/src/session_impl.cpp b/src/session_impl.cpp index cf3a664fe..a7f423244 100644 --- a/src/session_impl.cpp +++ b/src/session_impl.cpp @@ -3909,6 +3909,9 @@ namespace aux { TORRENT_ASSERT(is_single_thread()); if (m_stats_counters[counters::num_unchoke_slots] == 0) return; + // if we unchoke everyone, skip this logic + if (settings().get_int(settings_pack::unchoke_slots_limit) < 0) return; + std::vector opt_unchoke; // collect the currently optimistically unchoked peers here, so we can @@ -4174,6 +4177,13 @@ namespace aux { time_duration const unchoke_interval = now - m_last_choke; m_last_choke = now; + // if we unchoke everyone, skip this logic + if (settings().get_int(settings_pack::unchoke_slots_limit) < 0) + { + m_stats_counters.set_value(counters::num_unchoke_slots, std::numeric_limits::max()); + return; + } + // build list of all peers that are // unchokable. // TODO: 3 there should be a pre-calculated list of all peers eligible for @@ -6298,6 +6308,25 @@ namespace aux { m_alerts.emplace_alert(torrent_handle() , performance_alert::too_many_optimistic_unchoke_slots); } + + if (allowed_upload_slots == std::numeric_limits::max()) + { + // this means we're not aplpying upload slot limits, unchoke + // everyone + for (auto const& p : m_connections) + { + if (p->is_disconnecting() || p->is_connecting()) + continue; + + auto const t = p->associated_torrent().lock(); + t->unchoke_peer(*p); + } + } + else + { + // trigger recalculating unchoke slots + m_unchoke_time_scaler = 0; + } } void session_impl::update_connection_speed()