From 385e85c19a765fe552b906f18f7c239fc2164805 Mon Sep 17 00:00:00 2001 From: manoranjith Date: Tue, 3 Dec 2024 23:28:01 +0100 Subject: [PATCH] feat: make worker job polling interval config - Previously, the value was hardcoded to 5000ms. This could lead to long wait between processing jobs and hence a delay in result being available in the coprocessor db. - Now, make this interval configurable via command line argument. Can be fine tuned as per needed performance. --- fhevm-engine/coprocessor/README.md | 5 +++-- fhevm-engine/coprocessor/src/daemon_cli.rs | 4 ++++ fhevm-engine/coprocessor/src/tfhe_worker.rs | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/fhevm-engine/coprocessor/README.md b/fhevm-engine/coprocessor/README.md index a4f14d29..20c78fd3 100644 --- a/fhevm-engine/coprocessor/README.md +++ b/fhevm-engine/coprocessor/README.md @@ -50,6 +50,7 @@ Reload database and apply schemas from scratch make recreate_db ``` Run the server and background fhe worker + +``` +cargo run -- --run-server --run-bg-worker --worker-polling-interval-ms 1000 ``` -cargo run -- --run-server --run-bg-worker -``` \ No newline at end of file diff --git a/fhevm-engine/coprocessor/src/daemon_cli.rs b/fhevm-engine/coprocessor/src/daemon_cli.rs index 74fa069d..1bd23b86 100644 --- a/fhevm-engine/coprocessor/src/daemon_cli.rs +++ b/fhevm-engine/coprocessor/src/daemon_cli.rs @@ -11,6 +11,10 @@ pub struct Args { #[arg(long)] pub run_bg_worker: bool, + /// Polling interval for the background worker to fetch jobs + #[arg(long, default_value_t = 5000)] + pub worker_polling_interval_ms: u64, + /// Generate fhe keys and exit #[arg(long)] pub generate_fhe_keys: bool, diff --git a/fhevm-engine/coprocessor/src/tfhe_worker.rs b/fhevm-engine/coprocessor/src/tfhe_worker.rs index 61acc5bc..ec72d975 100644 --- a/fhevm-engine/coprocessor/src/tfhe_worker.rs +++ b/fhevm-engine/coprocessor/src/tfhe_worker.rs @@ -85,7 +85,7 @@ async fn tfhe_worker_cycle( WORK_ITEMS_NOTIFICATIONS_COUNTER.inc(); info!(target: "tfhe_worker", "Received work_available notification from postgres"); }, - _ = tokio::time::sleep(tokio::time::Duration::from_millis(5000)) => { + _ = tokio::time::sleep(tokio::time::Duration::from_millis(args.worker_polling_interval_ms)) => { WORK_ITEMS_POLL_COUNTER.inc(); info!(target: "tfhe_worker", "Polling the database for more work on timer"); },