Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Torrent repository with parking_lot crate locks #800

Conversation

josecelano
Copy link
Member

@josecelano josecelano commented Apr 16, 2024

Relates to: #774

A new torrent repository implementation with a different lock implementation for the torrent entry.

The crate is: parking_lot

It's supposed to be faster than the standard implementation of Mutex and RwLock.

This PR adds two implementations with Mutex and RwLock.

Subtasks

  • With parking_lot::RwLock
  • With parking_lot::Mutex

Performance

With parking_lot::RwLock:

Requests out: 420183.87/second
Responses in: 356799.49/second
  - Connect responses:  176636.38
  - Announce responses: 176603.09
  - Scrape responses:   3560.02
  - Error responses:    0.00
Peers per announce response: 0.00
Announce responses per info hash:
  - p10: 1
  - p25: 1
  - p50: 1
  - p75: 1
  - p90: 2
  - p95: 3
  - p99: 104
  - p99.9: 287
  - p100: 359

With parking_lot::RwLock::Mutex

Requests out: 405157.91/second
Responses in: 363773.19/second
  - Connect responses:  180009.24
  - Announce responses: 180202.03
  - Scrape responses:   3561.92
  - Error responses:    0.00
Peers per announce response: 0.00
Announce responses per info hash:
  - p10: 1
  - p25: 1
  - p50: 1
  - p75: 1
  - p90: 2
  - p95: 3
  - p99: 105
  - p99.9: 293
  - p100: 367

With current implementation (SkipMap and Std Mutex):

Requests out: 415067.21/second
Responses in: 369397.08/second
  - Connect responses:  183049.81
  - Announce responses: 182717.15
  - Scrape responses:   3630.12
  - Error responses:    0.00
Peers per announce response: 0.00
Announce responses per info hash:
  - p10: 1
  - p25: 1
  - p50: 1
  - p75: 1
  - p90: 2
  - p95: 3
  - p99: 104
  - p99.9: 297
  - p100: 375

image

image

Conclusion

Performance looks similar (the current version is slightly better), so I would keep the current version with the standard Mutex.

It provides implementations of Mutex and RwLock that are smaller, faster and more flexible than those in the Rust standard library. It will be used to check if a new torrent repo implementation using these lock is faster.
@josecelano josecelano added the Optimization Make it Faster label Apr 16, 2024
Copy link

codecov bot commented Apr 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.93%. Comparing base (7664ec6) to head (0058e72).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #800      +/-   ##
===========================================
+ Coverage    78.55%   78.93%   +0.37%     
===========================================
  Files          160      162       +2     
  Lines         9024     9186     +162     
===========================================
+ Hits          7089     7251     +162     
  Misses        1935     1935              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

It's used for benchmarking in the torrent-repository workspace package.
@josecelano josecelano marked this pull request as ready for review April 16, 2024 15:29
@josecelano josecelano force-pushed the torrent-repository-with-parking-lot-locks branch from 15df3ee to 0058e72 Compare April 16, 2024 15:33
@josecelano
Copy link
Member Author

ACK 0058e72

@josecelano josecelano requested a review from da2ce7 April 16, 2024 16:28
@josecelano josecelano merged commit 6271ce8 into torrust:develop Apr 16, 2024
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Optimization Make it Faster
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant