diff --git a/crates/udp/src/swarm.rs b/crates/udp/src/swarm.rs index d88b9d3..6a5e327 100644 --- a/crates/udp/src/swarm.rs +++ b/crates/udp/src/swarm.rs @@ -84,6 +84,7 @@ impl TorrentMaps { self.ipv6.scrape(request) } } + /// Remove forbidden or inactive torrents, reclaim space and update statistics pub fn clean_and_update_statistics( &self, @@ -105,15 +106,18 @@ impl TorrentMaps { .clean_and_get_statistics(config, statistics_sender, &mut cache, mode, now); if config.statistics.active() { - statistics.ipv4.peers.store(ipv4.0, Ordering::Relaxed); - statistics.ipv6.peers.store(ipv6.0, Ordering::Relaxed); + statistics.ipv4.torrents.store(ipv4.0, Ordering::Relaxed); + statistics.ipv6.torrents.store(ipv6.0, Ordering::Relaxed); - if let Some(message) = ipv4.1.map(StatisticsMessage::Ipv4PeerHistogram) { + statistics.ipv4.peers.store(ipv4.1, Ordering::Relaxed); + statistics.ipv6.peers.store(ipv6.1, Ordering::Relaxed); + + if let Some(message) = ipv4.2.map(StatisticsMessage::Ipv4PeerHistogram) { if let Err(err) = statistics_sender.try_send(message) { ::log::error!("couldn't send statistics message: {:#}", err); } } - if let Some(message) = ipv6.1.map(StatisticsMessage::Ipv6PeerHistogram) { + if let Some(message) = ipv6.2.map(StatisticsMessage::Ipv6PeerHistogram) { if let Err(err) = statistics_sender.try_send(message) { ::log::error!("couldn't send statistics message: {:#}", err); } @@ -204,7 +208,8 @@ impl TorrentMapShards { access_list_cache: &mut AccessListCache, access_list_mode: AccessListMode, now: SecondsSinceServerStart, - ) -> (usize, Option>) { + ) -> (usize, usize, Option>) { + let mut total_num_torrents = 0; let mut total_num_peers = 0; let mut opt_histogram: Option> = if config.statistics.torrent_peer_histograms @@ -271,8 +276,10 @@ impl TorrentMapShards { return false; } - // Only remove if no peers have been added since previous - // cleaning step + // Check pending_removal flag set in previous cleaning step. This + // prevents us from removing TorrentData entries that were just + // added but do not yet contain any peers. Also double-check that + // no peers have been added since we last checked. if torrent_data .pending_removal .fetch_and(false, Ordering::Acquire) @@ -285,9 +292,11 @@ impl TorrentMapShards { }); torrent_map_shard.shrink_to_fit(); + + total_num_torrents += torrent_map_shard.len(); } - (total_num_peers, opt_histogram) + (total_num_torrents, total_num_peers, opt_histogram) } fn get_shard(&self, info_hash: &InfoHash) -> &RwLock> { diff --git a/crates/udp/src/workers/statistics/mod.rs b/crates/udp/src/workers/statistics/mod.rs index 4814bb7..9ae5b91 100644 --- a/crates/udp/src/workers/statistics/mod.rs +++ b/crates/udp/src/workers/statistics/mod.rs @@ -249,7 +249,10 @@ fn print_to_stdout(config: &Config, statistics: &CollectedStatistics) { " error: {:>10}", statistics.responses_per_second_error ); - println!(" torrents: {:>10}", statistics.num_torrents); + println!( + " torrents: {:>10} (updated every {}s)", + statistics.num_torrents, config.cleaning.torrent_cleaning_interval + ); println!( " peers: {:>10} (updated every {}s)", statistics.num_peers, config.cleaning.torrent_cleaning_interval diff --git a/crates/udp/templates/statistics.html b/crates/udp/templates/statistics.html index 0fe8930..01bd37f 100644 --- a/crates/udp/templates/statistics.html +++ b/crates/udp/templates/statistics.html @@ -25,10 +25,10 @@

IPv4

- + - + @@ -141,10 +141,10 @@

IPv6

* Peer count is updated every { peer_update_interval } seconds* Torrent/peer count is updated every { peer_update_interval } seconds
Number of torrents{ ipv4.num_torrents }{ ipv4.num_torrents } *
Number of peers
- + - +
* Peer count is updated every { peer_update_interval } seconds* Torrent/peer count is updated every { peer_update_interval } seconds
Number of torrents{ ipv6.num_torrents }{ ipv6.num_torrents } *
Number of peers