Skip to content

Commit

Permalink
feat: decrease the tracker stast importer exec interval
Browse files Browse the repository at this point in the history
We are having problems with the live demo server:

torrust/torrust-demo#1

Due to a high CPU and memory usage.
  • Loading branch information
josecelano committed Apr 24, 2024
1 parent 3b329ff commit bdbb316
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/console/cronjobs/tracker_statistics_importer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,28 @@ pub fn start(

info!("Tracker statistics importer cronjob starting ...");

// code-review: we set an execution interval to avoid intense polling to
// the database. If we remove the interval we would be constantly
// queering if there are torrent stats pending to update, unless there
// are torrents to update. Maybe we should only sleep for 100 milliseconds
// if we did not update any torrents in the latest execution.
// With this current limit we can only import 50 torrent stats every 100
// milliseconds which is 500 torrents per second (1800000 torrents per hour).
// If the tracker can handle a request in 100 milliseconds.

let execution_interval_in_milliseconds = 100;
// code-review:
//
// We set an execution interval to avoid intense polling to the
// database. If we remove the interval we would be constantly queering
// if there are torrent stats pending to update, unless there are
// torrents to update. Maybe we should only sleep for 100 milliseconds
// if we did not update any torrents in the latest execution. With this
// current limit we can only import 50 torrent stats every 2000 seconds,
// which is 500 torrents per second (1800000 torrents per hour).
//
// | Interval (secs) | Number of torrents imported per hour |
// ------------------|--------------------------------------|
// | 1 sec | 50 * (3600/1) = 180000 |
// | 2 sec | 50 * (3600/2) = 90000 |
// | 3 sec | 50 * (3600/3) = 60000 |
// | 4 sec | 50 * (3600/4) = 45000 |
// | 5 sec | 50 * (3600/5) = 36000 |
//
// The `execution_interval_in_milliseconds` could be a config option in
// the future.

let execution_interval_in_milliseconds = 2000;
let execution_interval_duration = std::time::Duration::from_millis(execution_interval_in_milliseconds);
let mut execution_interval = tokio::time::interval(execution_interval_duration);

Expand Down

0 comments on commit bdbb316

Please sign in to comment.