Skip to content

Commit ecec5c7

Browse files
committed
chore(coprocessor): add pg_auto_explain_with_min_duration config in zkproof-worker
1 parent 959e704 commit ecec5c7

File tree

6 files changed

+27
-9
lines changed

6 files changed

+27
-9
lines changed

coprocessor/fhevm-engine/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coprocessor/fhevm-engine/zkproof-worker/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bincode = { workspace = true }
2222
thiserror = { workspace = true }
2323
tracing = { workspace = true }
2424
tracing-subscriber = { workspace = true }
25+
humantime = { workspace = true }
2526

2627
# local dependencies
2728
fhevm-engine-common = { path = "../fhevm-engine-common" }

coprocessor/fhevm-engine/zkproof-worker/src/bin/zkproof_worker.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use clap::{command, Parser};
22
use fhevm_engine_common::healthz_server::HttpServer;
33
use fhevm_engine_common::telemetry;
4-
use std::sync::Arc;
4+
use humantime::parse_duration;
5+
use std::{sync::Arc, time::Duration};
56
use tokio::{join, task};
67
use tokio_util::sync::CancellationToken;
78
use tracing::{error, info, Level};
@@ -26,6 +27,15 @@ pub struct Args {
2627
#[arg(long, default_value_t = 5)]
2728
pub pg_pool_connections: u32,
2829

30+
/// Postgres acquire timeout
31+
/// A longer timeout could affect the healthz/liveness updates
32+
#[arg(long, default_value = "15s", value_parser = parse_duration)]
33+
pub pg_timeout: Duration,
34+
35+
/// Postgres diagnostics: enable auto_explain extension
36+
#[arg(long, value_parser = parse_duration)]
37+
pub pg_auto_explain_with_min_duration: Option<Duration>,
38+
2939
/// Postgres database url. If unspecified DATABASE_URL environment variable
3040
/// is used
3141
#[arg(long)]
@@ -78,6 +88,8 @@ async fn main() {
7888
pg_pool_connections: args.pg_pool_connections,
7989
pg_polling_interval: args.pg_polling_interval,
8090
worker_thread_count: args.worker_thread_count,
91+
pg_timeout: args.pg_timeout,
92+
pg_auto_explain_with_min_duration: args.pg_auto_explain_with_min_duration,
8193
};
8294

8395
if let Err(err) = telemetry::setup_otlp(&args.service_name) {

coprocessor/fhevm-engine/zkproof-worker/src/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pub mod auxiliary;
44
mod tests;
55

66
pub mod verifier;
7-
use std::io;
7+
use std::{io, time::Duration};
88

99
use fhevm_engine_common::{pg_pool::ServiceError, types::FhevmError};
1010
use thiserror::Error;
@@ -73,6 +73,8 @@ pub struct Config {
7373
pub notify_database_channel: String,
7474
pub pg_pool_connections: u32,
7575
pub pg_polling_interval: u32,
76+
pub pg_timeout: Duration,
77+
pub pg_auto_explain_with_min_duration: Option<Duration>,
7678

7779
pub worker_thread_count: u32,
7880
}

coprocessor/fhevm-engine/zkproof-worker/src/tests/utils.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,17 @@ pub async fn setup() -> anyhow::Result<(PostgresPoolManager, DBInstance)> {
2121
pg_pool_connections: 10,
2222
pg_polling_interval: 60,
2323
worker_thread_count: 1,
24+
pg_timeout: Duration::from_secs(15),
25+
pg_auto_explain_with_min_duration: None,
2426
};
2527

2628
let pool_mngr = PostgresPoolManager::connect_pool(
2729
test_instance.parent_token.child_token(),
2830
conf.database_url.as_str(),
29-
Duration::from_secs(15),
30-
10,
31+
conf.pg_timeout,
32+
conf.pg_pool_connections,
3133
Duration::from_secs(2),
32-
None, // TODO: conf.pg_auto_explain_with_min_duration
34+
conf.pg_auto_explain_with_min_duration,
3335
)
3436
.await
3537
.unwrap();

coprocessor/fhevm-engine/zkproof-worker/src/verifier.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,18 +80,18 @@ impl HealthCheckService for ZkProofService {
8080
impl ZkProofService {
8181
pub async fn create(conf: Config, token: CancellationToken) -> Option<ZkProofService> {
8282
// Each worker needs at least 3 pg connections
83-
let pool_connections =
83+
let max_pool_connections =
8484
std::cmp::max(conf.pg_pool_connections, 3 * conf.worker_thread_count);
8585
let t = telemetry::tracer("init_service");
8686
let _s = t.child_span("pg_connect");
8787

8888
let Some(pool_mngr) = PostgresPoolManager::connect_pool(
8989
token.child_token(),
9090
conf.database_url.as_str(),
91-
Duration::from_secs(15),
92-
pool_connections,
91+
conf.pg_timeout,
92+
max_pool_connections,
9393
Duration::from_secs(2),
94-
None, // TODO: conf.pg_auto_explain_with_min_duration
94+
conf.pg_auto_explain_with_min_duration,
9595
)
9696
.await
9797
else {

0 commit comments

Comments
 (0)