Skip to content

Commit

Permalink
fix(prover): Reduce amount of prover connections per prover subcompon…
Browse files Browse the repository at this point in the history
…ent (#734)

## What ❔

Configuration limit on number of DB connections per prover subcomponent.

## Why ❔

During surge of TPS, prover database was pummeled with connections. This
change will makes sure the database will be protected from rogue
connections. Assuming the patch is wrong, prover subcomponents will be
throttled.

## Checklist

- [x] PR title corresponds to the body of PR (we generate changelog
entries from PRs).
- [ ] Tests for the changes have been added / updated.
- [ ] Documentation comments have been added / updated.
- [x] Code has been formatted via `zk fmt` and `zk lint`.
- [x] Spellcheck has been run via `cargo spellcheck
--cfg=./spellcheck/era.cfg --code 1`.
  • Loading branch information
EmilLuta committed Dec 21, 2023
1 parent 5c34ba6 commit d38aa85
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
11 changes: 4 additions & 7 deletions prover/proof_fri_compressor/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ async fn main() -> anyhow::Result<()> {
let opt = Opt::from_args();
let config = FriProofCompressorConfig::from_env().context("FriProofCompressorConfig")?;
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;
let pool = ConnectionPool::builder(
postgres_config.prover_url()?,
postgres_config.max_connections()?,
)
.build()
.await
.context("failed to build a connection pool")?;
let pool = ConnectionPool::singleton(postgres_config.prover_url()?)
.build()
.await
.context("failed to build a connection pool")?;
let object_store_config =
ProverObjectStoreConfig::from_env().context("ProverObjectStoreConfig::from_env()")?;
let blob_store = ObjectStoreFactory::new(object_store_config.0)
Expand Down
17 changes: 10 additions & 7 deletions prover/prover_fri/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,16 @@ async fn main() -> anyhow::Result<()> {
circuit_ids_for_round_to_be_proven.clone()
);
let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;
let pool = ConnectionPool::builder(
postgres_config.prover_url()?,
postgres_config.max_connections()?,
)
.build()
.await
.context("failed to build a connection pool")?;

// There are 2 threads using the connection pool:
// 1. The prover thread, which is used to update the prover job status.
// 2. The socket listener thread, which is used to update the prover instance status.
const MAX_POOL_SIZE_FOR_PROVER: u32 = 2;

let pool = ConnectionPool::builder(postgres_config.prover_url()?, MAX_POOL_SIZE_FOR_PROVER)
.build()
.await
.context("failed to build a connection pool")?;
let port = prover_config.witness_vector_receiver_port;
let prover_tasks = get_prover_tasks(
prover_config,
Expand Down
11 changes: 4 additions & 7 deletions prover/witness_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,10 @@ async fn main() -> anyhow::Result<()> {
.build()
.await
.context("failed to build a connection_pool")?;
let prover_connection_pool = ConnectionPool::builder(
postgres_config.prover_url()?,
postgres_config.max_connections()?,
)
.build()
.await
.context("failed to build a prover_connection_pool")?;
let prover_connection_pool = ConnectionPool::singleton(postgres_config.prover_url()?)
.build()
.await
.context("failed to build a prover_connection_pool")?;
let (stop_sender, stop_receiver) = watch::channel(false);
let vk_commitments = get_cached_commitments();
let protocol_versions = prover_connection_pool
Expand Down
11 changes: 4 additions & 7 deletions prover/witness_vector_generator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,10 @@ async fn main() -> anyhow::Result<()> {
let exporter_config = PrometheusExporterConfig::pull(config.prometheus_listener_port);

let postgres_config = PostgresConfig::from_env().context("PostgresConfig::from_env()")?;
let pool = ConnectionPool::builder(
postgres_config.prover_url()?,
postgres_config.max_connections()?,
)
.build()
.await
.context("failed to build a connection pool")?;
let pool = ConnectionPool::singleton(postgres_config.prover_url()?)
.build()
.await
.context("failed to build a connection pool")?;
let object_store_config =
ProverObjectStoreConfig::from_env().context("ProverObjectStoreConfig::from_env()")?;
let blob_store = ObjectStoreFactory::new(object_store_config.0)
Expand Down

0 comments on commit d38aa85

Please sign in to comment.