Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
3d53b23
feat: [#1491] copy torrent repo benchmarking into a new pkg
josecelano Apr 30, 2025
16a6d08
feat!: [#1491] remove unused torrent repositories
josecelano Apr 30, 2025
b2a9684
feat!: [#1491] remove unused torrent repository entry types
josecelano Apr 30, 2025
89123fa
feat!: [#1491] remove unused traits RepositoryAsync and EntryAsync
josecelano Apr 30, 2025
382e0af
faet!: [#1491] remove unused trait Repository
josecelano Apr 30, 2025
ecd2266
feat!: [#1491] remove unused traits Entry and EntrySync
josecelano Apr 30, 2025
e0a4aac
feat!: [#1491] remove unneeded generic
josecelano Apr 30, 2025
e87479e
refactor: [#1491] extract mod torrent
josecelano Apr 30, 2025
f868b04
refactor: [#1491] put implementation and type in the same module
josecelano Apr 30, 2025
0acfc8f
refactor: [#1491] remove unneeded type alias EntrySingle
josecelano Apr 30, 2025
2b0727e
refactor: [#1491] reorganize repository module
josecelano May 1, 2025
f106c01
refactor: [#1491] move type alias to torrent-repository pkg
josecelano May 1, 2025
71aa8d0
fix: [#1491] deadlock running tests
josecelano May 1, 2025
9be7c68
refactor: [#1491] remove redundant type aliases
josecelano May 1, 2025
df00533
refactor: [#1491] rename main types in torrent-repository pkg
josecelano May 1, 2025
21b18e4
refactor: [#1491] move functionality from InMemoryTorrentRepository t…
josecelano May 2, 2025
32acbb1
refactor: [#1491] rename method
josecelano May 2, 2025
09bbef7
refactor: [#1491] rename varaible
josecelano May 2, 2025
1f5d18f
refactor: [#1491] remove duplicate code
josecelano May 2, 2025
7215f6e
refactor: [#1491] clean tests in torrent-repository
josecelano May 2, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ jobs:
cargo publish -p torrust-tracker-metrics
cargo publish -p torrust-tracker-primitives
cargo publish -p torrust-tracker-test-helpers
cargo publish -p torrust-tracker-torrent-benchmarking
cargo publish -p torrust-tracker-torrent-repository
cargo publish -p torrust-udp-tracker-server
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ torrust-rest-tracker-api-client = { version = "3.0.0-develop", path = "packages/
torrust-tracker-test-helpers = { version = "3.0.0-develop", path = "packages/test-helpers" }

[workspace]
members = ["console/tracker-client"]
members = ["console/tracker-client", "packages/torrent-repository-benchmarking"]

[profile.dev]
debug = 1
Expand Down
2 changes: 1 addition & 1 deletion packages/http-tracker-core/src/statistics/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub async fn get_metrics(
in_memory_torrent_repository: Arc<InMemoryTorrentRepository>,
stats_repository: Arc<Repository>,
) -> TrackerMetrics {
let torrents_metrics = in_memory_torrent_repository.get_torrents_metrics();
let torrents_metrics = in_memory_torrent_repository.get_aggregate_swarm_metadata();
let stats = stats_repository.get_stats().await;

TrackerMetrics {
Expand Down
4 changes: 2 additions & 2 deletions packages/rest-tracker-api-core/src/statistics/services.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ pub async fn get_metrics(
http_stats_repository: Arc<bittorrent_http_tracker_core::statistics::repository::Repository>,
udp_server_stats_repository: Arc<udp_server_statistics::repository::Repository>,
) -> TrackerMetrics {
let torrents_metrics = in_memory_torrent_repository.get_torrents_metrics();
let torrents_metrics = in_memory_torrent_repository.get_aggregate_swarm_metadata();
let udp_banned_ips_total = ban_service.read().await.get_banned_ips_total();
let http_stats = http_stats_repository.get_stats().await;
let udp_server_stats = udp_server_stats_repository.get_stats().await;
Expand Down Expand Up @@ -97,7 +97,7 @@ pub async fn get_labeled_metrics(
udp_stats_repository: Arc<bittorrent_udp_tracker_core::statistics::repository::Repository>,
udp_server_stats_repository: Arc<udp_server_statistics::repository::Repository>,
) -> TrackerLabeledMetrics {
let _torrents_metrics = in_memory_torrent_repository.get_torrents_metrics();
let _torrents_metrics = in_memory_torrent_repository.get_aggregate_swarm_metadata();
let _udp_banned_ips_total = ban_service.read().await.get_banned_ips_total();

let http_stats = http_stats_repository.get_stats().await;
Expand Down
38 changes: 38 additions & 0 deletions packages/torrent-repository-benchmarking/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
description = "A library to runt benchmarking for different implementations of a repository of torrents files and their peers."
keywords = ["library", "repository", "torrents"]
name = "torrust-tracker-torrent-repository-benchmarking"
readme = "README.md"

authors.workspace = true
categories.workspace = true
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
license.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
aquatic_udp_protocol = "0"
bittorrent-primitives = "0.1.0"
crossbeam-skiplist = "0"
dashmap = "6"
futures = "0"
parking_lot = "0"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker-clock = { version = "3.0.0-develop", path = "../clock" }
torrust-tracker-configuration = { version = "3.0.0-develop", path = "../configuration" }
torrust-tracker-primitives = { version = "3.0.0-develop", path = "../primitives" }
zerocopy = "0.7"

[dev-dependencies]
async-std = { version = "1", features = ["attributes", "tokio1"] }
criterion = { version = "0", features = ["async_tokio"] }
rstest = "0"

[[bench]]
harness = false
name = "repository_benchmark"
32 changes: 32 additions & 0 deletions packages/torrent-repository-benchmarking/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Torrust Tracker Torrent Repository Benchmarking

A library to runt benchmarking for different implementations of a repository of torrents files and their peers. Torrent repositories are used by the [Torrust Tracker](https://github.com/torrust/torrust-tracker).

## Benchmarking

```console
cargo bench -p torrust-tracker-torrent-repository
```

Example partial output:

```output
Running benches/repository_benchmark.rs (target/release/deps/repository_benchmark-a9b0013c8d09c3c3)
add_one_torrent/RwLockStd
time: [63.057 ns 63.242 ns 63.506 ns]
Found 12 outliers among 100 measurements (12.00%)
2 (2.00%) low severe
2 (2.00%) low mild
2 (2.00%) high mild
6 (6.00%) high severe
add_one_torrent/RwLockStdMutexStd
time: [62.505 ns 63.077 ns 63.817 ns]
```

## Documentation

[Crate documentation](https://docs.rs/torrust-tracker-torrent-repository).

## License

The project is licensed under the terms of the [GNU AFFERO GENERAL PUBLIC LICENSE](./LICENSE).
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, Instant};

use bittorrent_primitives::info_hash::InfoHash;
use futures::stream::FuturesUnordered;
use torrust_tracker_torrent_repository::repository::RepositoryAsync;
use torrust_tracker_torrent_repository_benchmarking::repository::RepositoryAsync;

use super::utils::{generate_unique_info_hashes, DEFAULT_PEER};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::{Duration, Instant};

use bittorrent_primitives::info_hash::InfoHash;
use futures::stream::FuturesUnordered;
use torrust_tracker_torrent_repository::repository::Repository;
use torrust_tracker_torrent_repository_benchmarking::repository::Repository;

use super::utils::{generate_unique_info_hashes, DEFAULT_PEER};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::time::Duration;
mod helpers;

use criterion::{criterion_group, criterion_main, Criterion};
use torrust_tracker_torrent_repository::{
use torrust_tracker_torrent_repository_benchmarking::{
TorrentsDashMapMutexStd, TorrentsRwLockStd, TorrentsRwLockStdMutexStd, TorrentsRwLockStdMutexTokio, TorrentsRwLockTokio,
TorrentsRwLockTokioMutexStd, TorrentsRwLockTokioMutexTokio, TorrentsSkipMapMutexParkingLot, TorrentsSkipMapMutexStd,
TorrentsSkipMapRwLockParkingLot,
Expand Down
92 changes: 92 additions & 0 deletions packages/torrent-repository-benchmarking/src/entry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
use std::fmt::Debug;
use std::net::SocketAddr;
use std::sync::Arc;

use torrust_tracker_configuration::TrackerPolicy;
use torrust_tracker_primitives::swarm_metadata::SwarmMetadata;
use torrust_tracker_primitives::{peer, DurationSinceUnixEpoch};

use self::peer_list::PeerList;

pub mod mutex_parking_lot;
pub mod mutex_std;
pub mod mutex_tokio;
pub mod peer_list;
pub mod rw_lock_parking_lot;
pub mod single;

pub trait Entry {
/// It returns the swarm metadata (statistics) as a struct:
///
/// `(seeders, completed, leechers)`
fn get_swarm_metadata(&self) -> SwarmMetadata;

/// Returns True if Still a Valid Entry according to the Tracker Policy
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool;

/// Returns True if the Peers is Empty
fn peers_is_empty(&self) -> bool;

/// Returns the number of Peers
fn get_peers_len(&self) -> usize;

/// Get all swarm peers, optionally limiting the result.
fn get_peers(&self, limit: Option<usize>) -> Vec<Arc<peer::Peer>>;

/// It returns the list of peers for a given peer client, optionally limiting the
/// result.
///
/// It filters out the input peer, typically because we want to return this
/// list of peers to that client peer.
fn get_peers_for_client(&self, client: &SocketAddr, limit: Option<usize>) -> Vec<Arc<peer::Peer>>;

/// It updates a peer and returns true if the number of complete downloads have increased.
///
/// The number of peers that have complete downloading is synchronously updated when peers are updated.
/// That's the total torrent downloads counter.
fn upsert_peer(&mut self, peer: &peer::Peer) -> bool;

/// It removes peer from the swarm that have not been updated for more than `current_cutoff` seconds
fn remove_inactive_peers(&mut self, current_cutoff: DurationSinceUnixEpoch);
}

#[allow(clippy::module_name_repetitions)]
pub trait EntrySync {
fn get_swarm_metadata(&self) -> SwarmMetadata;
fn meets_retaining_policy(&self, policy: &TrackerPolicy) -> bool;
fn peers_is_empty(&self) -> bool;
fn get_peers_len(&self) -> usize;
fn get_peers(&self, limit: Option<usize>) -> Vec<Arc<peer::Peer>>;
fn get_peers_for_client(&self, client: &SocketAddr, limit: Option<usize>) -> Vec<Arc<peer::Peer>>;
fn upsert_peer(&self, peer: &peer::Peer) -> bool;
fn remove_inactive_peers(&self, current_cutoff: DurationSinceUnixEpoch);
}

#[allow(clippy::module_name_repetitions)]
pub trait EntryAsync {
fn get_swarm_metadata(&self) -> impl std::future::Future<Output = SwarmMetadata> + Send;
fn meets_retaining_policy(self, policy: &TrackerPolicy) -> impl std::future::Future<Output = bool> + Send;
fn peers_is_empty(&self) -> impl std::future::Future<Output = bool> + Send;
fn get_peers_len(&self) -> impl std::future::Future<Output = usize> + Send;
fn get_peers(&self, limit: Option<usize>) -> impl std::future::Future<Output = Vec<Arc<peer::Peer>>> + Send;
fn get_peers_for_client(
&self,
client: &SocketAddr,
limit: Option<usize>,
) -> impl std::future::Future<Output = Vec<Arc<peer::Peer>>> + Send;
fn upsert_peer(self, peer: &peer::Peer) -> impl std::future::Future<Output = bool> + Send;
fn remove_inactive_peers(self, current_cutoff: DurationSinceUnixEpoch) -> impl std::future::Future<Output = ()> + Send;
}

/// A data structure containing all the information about a torrent in the tracker.
///
/// This is the tracker entry for a given torrent and contains the swarm data,
/// that's the list of all the peers trying to download the same torrent.
/// The tracker keeps one entry like this for every torrent.
#[derive(Clone, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct Torrent {
/// A network of peers that are all trying to download the torrent associated to this entry
pub(crate) swarm: PeerList,
/// The number of peers that have ever completed downloading the torrent associated to this entry
pub(crate) downloaded: u32,
}
Loading