Skip to content

Commit

Permalink
perf: connectable pool housekeeping (transmission#6111)
Browse files Browse the repository at this point in the history
  • Loading branch information
tearfur authored Oct 19, 2023
1 parent 4bdb306 commit 88fe767
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions libtransmission/peer-mgr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,23 @@ class tr_swarm
}
}

void remove_inactive_peer_info() noexcept
{
auto const now = tr_time();
for (auto iter = std::begin(connectable_pool), end = std::end(connectable_pool); iter != end;)
{
auto& [socket_address, peer_info] = *iter;
if (peer_info.is_inactive(now))
{
iter = connectable_pool.erase(iter);
}
else
{
++iter;
}
}
}

[[nodiscard]] uint16_t countActiveWebseeds(uint64_t now) const noexcept
{
if (!tor->is_running() || tor->is_done())
Expand Down Expand Up @@ -1145,6 +1162,7 @@ void tr_peerMgr::refillUpkeep() const
for (auto* const tor : session->torrents())
{
tor->swarm->cancelOldRequests();
tor->swarm->remove_inactive_peer_info();
}
}

Expand Down
6 changes: 6 additions & 0 deletions libtransmission/peer-mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ class tr_peer_info
return now - std::max(piece_data_at_, connection_changed_at_);
}

[[nodiscard]] auto is_inactive(time_t const now) const noexcept
{
return !is_in_use() && now - connection_changed_at_ >= UselessThresSecs;
}

// ---

constexpr void on_connection_failed() noexcept
Expand Down Expand Up @@ -417,6 +422,7 @@ class tr_peer_info

// the minimum we'll wait before attempting to reconnect to a peer
static auto constexpr MinimumReconnectIntervalSecs = time_t{ 5U };
static auto constexpr UselessThresSecs = time_t{ 24 * 60 * 60 };

static auto inline n_known_connectable = size_t{};

Expand Down

0 comments on commit 88fe767

Please sign in to comment.