Skip to content

Commit

Permalink
Merge #522: feat: added benchmarking binary for torrent repository st…
Browse files Browse the repository at this point in the history
…ruct

ebb7d4c chore: make Containerfile use nightly rust (Warm Beer)
1735a7a chore: only run contract, deployment & testing jobs in nightly rust (Warm Beer)
6087e4f feat: added benchmarking binary for torrent repository (Warm Beer)

Pull request description:

  Moved the `Tracker.torrents` field to be its own `TorrentRepository` struct with different implementations.

  Added a new crate that benchmarks the different `TorrentRepository` implementations for speed.

  ### Run benchmarks
  ```shell
  cargo run --release -p torrust-torrent-repository-benchmarks -- --threads 4 --sleep 0 --compare true
  ```

  #### Example result
  ```shell
  tokio::sync::RwLock<std::collections::BTreeMap<InfoHash, Entry>>
  add_one_torrent: Avg/AdjAvg: (146ns, 0ns)
  update_one_torrent_in_parallel: Avg/AdjAvg: (5.965616ms, 5.816375ms)
  add_multiple_torrents_in_parallel: Avg/AdjAvg: (14.050554ms, 14.132902ms)
  update_multiple_torrents_in_parallel: Avg/AdjAvg: (7.201337ms, 7.120315ms)

  std::sync::RwLock<std::collections::BTreeMap<InfoHash, Entry>>
  add_one_torrent: Avg/AdjAvg: (82ns, 83ns)
  update_one_torrent_in_parallel: Avg/AdjAvg: (27.311075ms, 26.869114ms)
  add_multiple_torrents_in_parallel: Avg/AdjAvg: (28.967141ms, 28.967141ms)
  update_multiple_torrents_in_parallel: Avg/AdjAvg: (48.316966ms, 0ns)

  std::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<std::sync::Mutex<Entry>>>>
  add_one_torrent: Avg/AdjAvg: (137ns, 125ns)
  update_one_torrent_in_parallel: Avg/AdjAvg: (5.057729ms, 5.057729ms)
  add_multiple_torrents_in_parallel: Avg/AdjAvg: (48.833962ms, 48.833962ms)
  update_multiple_torrents_in_parallel: Avg/AdjAvg: (6.193212ms, 6.071166ms)

  tokio::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<std::sync::Mutex<Entry>>>>
  add_one_torrent: Avg/AdjAvg: (174ns, 166ns)
  update_one_torrent_in_parallel: Avg/AdjAvg: (5.56332ms, 5.56332ms)
  add_multiple_torrents_in_parallel: Avg/AdjAvg: (16.360504ms, 15.872786ms)
  update_multiple_torrents_in_parallel: Avg/AdjAvg: (6.800225ms, 6.890521ms)

  tokio::sync::RwLock<std::collections::BTreeMap<InfoHash, Arc<tokio::sync::Mutex<Entry>>>>
  add_one_torrent: Avg/AdjAvg: (192ns, 208ns)
  update_one_torrent_in_parallel: Avg/AdjAvg: (6.374304ms, 6.17711ms)
  add_multiple_torrents_in_parallel: Avg/AdjAvg: (17.313591ms, 17.089898ms)
  update_multiple_torrents_in_parallel: Avg/AdjAvg: (6.955371ms, 6.975057ms)

  ```

  ### Relevant issues
  #496
  #495

Top commit has no ACKs.

Tree-SHA512: 062d18c91b1d89ab95eda5ddc2cb7674d481b705a21c43e9cf3a11e0bf71e52bb6bccd5b5e4404fcf8ebdc442764dd60006c6962aac2a414c4b4cdecfa422a67
  • Loading branch information
josecelano committed Dec 21, 2023
2 parents a3274dc + ebb7d4c commit 20b052d
Show file tree
Hide file tree
Showing 19 changed files with 1,117 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/contract.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

strategy:
matrix:
toolchain: [stable, nightly]
toolchain: [nightly]

steps:
- id: checkout
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:

strategy:
matrix:
toolchain: [stable, nightly]
toolchain: [nightly]

steps:
- id: checkout
Expand Down Expand Up @@ -44,7 +44,7 @@ jobs:
name: Setup Toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
toolchain: ${{ matrix.toolchain }}

- id: publish
name: Publish Crates
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:

strategy:
matrix:
toolchain: [stable, nightly]
toolchain: [nightly]

steps:
- id: checkout
Expand Down Expand Up @@ -79,7 +79,7 @@ jobs:

strategy:
matrix:
toolchain: [stable, nightly]
toolchain: [nightly]

steps:
- id: checkout
Expand Down
97 changes: 97 additions & 0 deletions Cargo.lock

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

6 changes: 4 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ version = "3.0.0-alpha.12-develop"
[dependencies]
aquatic_udp_protocol = "0"
async-trait = "0"
axum = "0.6"
axum = { version = "0.6", features = ["macros"] }
axum-client-ip = "0.4"
axum-server = { version = "0", features = ["tls-rustls"] }
binascii = "0"
Expand Down Expand Up @@ -68,16 +68,18 @@ tower-http = { version = "0.4", features = ["compression-full"] }
uuid = { version = "1", features = ["v4"] }

[dev-dependencies]
criterion = { version = "0.5.1", features = ["async_tokio"] }
local-ip-address = "0"
mockall = "0"
once_cell = "1.18.0"
reqwest = { version = "0", features = ["json"] }
serde_bytes = "0"
serde_repr = "0"
serde_urlencoded = "0"
torrust-tracker-test-helpers = { version = "3.0.0-alpha.12-develop", path = "packages/test-helpers" }

[workspace]
members = ["contrib/bencode", "packages/configuration", "packages/located-error", "packages/primitives", "packages/test-helpers"]
members = ["contrib/bencode", "packages/configuration", "packages/located-error", "packages/primitives", "packages/test-helpers", "packages/torrent-repository-benchmarks"]

[profile.dev]
debug = 1
Expand Down
4 changes: 2 additions & 2 deletions Containerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Torrust Tracker

## Builder Image
FROM rust:bookworm as chef
FROM rustlang/rust:nightly-bookworm as chef
WORKDIR /tmp
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall --no-confirm cargo-chef cargo-nextest

## Tester Image
FROM rust:slim-bookworm as tester
FROM rustlang/rust:nightly-bookworm-slim as tester
WORKDIR /tmp

RUN apt-get update; apt-get install -y curl sqlite3; apt-get autoclean
Expand Down
21 changes: 21 additions & 0 deletions packages/torrent-repository-benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[package]
name = "torrust-torrent-repository-benchmarks"
authors.workspace = true
categories.workspace = true
description.workspace = true
documentation.workspace = true
edition.workspace = true
homepage.workspace = true
keywords.workspace = true
license.workspace = true
publish.workspace = true
repository.workspace = true
rust-version.workspace = true
version.workspace = true

[dependencies]
aquatic_udp_protocol = "0.8.0"
clap = { version = "4.4.8", features = ["derive"] }
futures = "0.3.29"
tokio = { version = "1", features = ["macros", "net", "rt-multi-thread", "signal", "sync"] }
torrust-tracker = { path = "../../" }
15 changes: 15 additions & 0 deletions packages/torrent-repository-benchmarks/src/args.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use clap::Parser;

#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
pub struct Args {
/// Amount of benchmark worker threads
#[arg(short, long)]
pub threads: usize,
/// Amount of time in ns a thread will sleep to simulate a client response after handling a task
#[arg(short, long)]
pub sleep: Option<u64>,
/// Compare with old implementations of the torrent repository
#[arg(short, long)]
pub compare: Option<bool>,
}
Loading

0 comments on commit 20b052d

Please sign in to comment.