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

feat(prover): improve precision for prover timings in database #2418

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion core/lib/db_connection/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ pub fn duration_to_naive_time(duration: Duration) -> NaiveTime {
(total_seconds / 60) % 60,
total_seconds % 60,
)
.unwrap()
.expect("failed to convert Duration to NaiveTime")
}

pub fn duration_to_naive_time_ms(duration: Duration) -> NaiveTime {
let total_ms = duration.as_millis();
let ms = (total_ms % 1_000) as u64;
duration_to_naive_time(duration) + Duration::from_millis(ms)
}

pub const fn pg_interval_from_duration(processing_timeout: Duration) -> PgInterval {
Expand Down
5 changes: 3 additions & 2 deletions prover/crates/bin/prover_fri/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,11 @@ pub async fn save_proof(
connection: &mut Connection<'_, Prover>,
protocol_version: ProtocolSemanticVersion,
) {
let time_taken = started_at.elapsed();
tracing::info!(
"Successfully proven job: {}, total time taken: {:?}",
job_id,
started_at.elapsed()
time_taken,
);
let proof = artifacts.proof_wrapper;

Expand Down Expand Up @@ -101,7 +102,7 @@ pub async fn save_proof(
let mut transaction = connection.start_transaction().await.unwrap();
transaction
.fri_prover_jobs_dal()
.save_proof(job_id, started_at.elapsed(), &blob_url)
.save_proof(job_id, time_taken, &blob_url)
.await;
if is_scheduler_proof {
transaction
Expand Down
11 changes: 10 additions & 1 deletion prover/crates/bin/witness_vector_generator/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,24 @@ impl JobProcessor for WitnessVectorGenerator {

METRICS.gpu_witness_vector_generation_time[&circuit_type].observe(started_at.elapsed());

let wvg_time_taken = started_at.elapsed();
tracing::info!(
"Finished witness vector generation for job: {job_id} in zone: {:?} took: {:?}",
self.zone,
started_at.elapsed()
wvg_time_taken
);

let serialized: Vec<u8> =
bincode::serialize(&artifacts).expect("Failed to serialize witness vector artifacts");

self.pool
.connection()
.await
.unwrap()
.fri_prover_jobs_dal()
.save_wvg_time_taken(job_id, wvg_time_taken)
.await;

let now = Instant::now();
let mut attempts = 0;

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE prover_jobs_fri
DROP COLUMN IF EXISTS wvg_time_taken;

ALTER TABLE prover_jobs_fri_archive
DROP COLUMN IF EXISTS wvg_time_taken;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ALTER TABLE prover_jobs_fri
ADD COLUMN IF NOT EXISTS wvg_time_taken TIME;

ALTER TABLE prover_jobs_fri_archive
ADD COLUMN IF NOT EXISTS wvg_time_taken TIME;
22 changes: 20 additions & 2 deletions prover/crates/lib/prover_dal/src/fri_prover_dal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use zksync_db_connection::{
connection::Connection, instrument::InstrumentExt, metrics::MethodLatency,
};

use crate::{duration_to_naive_time, pg_interval_from_duration, Prover};
use crate::{duration_to_naive_time_ms, pg_interval_from_duration, Prover};

#[derive(Debug)]
pub struct FriProverDal<'a, 'c> {
Expand Down Expand Up @@ -265,7 +265,7 @@ impl FriProverDal<'_, '_> {
prover_jobs_fri.depth,
prover_jobs_fri.is_node_final_proof
"#,
duration_to_naive_time(time_taken),
duration_to_naive_time_ms(time_taken),
blob_url,
i64::from(id)
)
Expand All @@ -288,6 +288,24 @@ impl FriProverDal<'_, '_> {
.unwrap()
}

pub async fn save_wvg_time_taken(&mut self, id: u32, wvg_time_taken: Duration) {
sqlx::query!(
r#"
UPDATE prover_jobs_fri
SET
updated_at = NOW(),
wvg_time_taken = $1
WHERE
id = $2
"#,
duration_to_naive_time_ms(wvg_time_taken),
i64::from(id)
)
.execute(self.storage.conn())
.await
.unwrap();
}

pub async fn requeue_stuck_jobs(
&mut self,
processing_timeout: Duration,
Expand Down
2 changes: 1 addition & 1 deletion prover/crates/lib/prover_dal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use zksync_db_connection::connection::DbMarker;
pub use zksync_db_connection::{
connection::Connection,
connection_pool::ConnectionPool,
utils::{duration_to_naive_time, pg_interval_from_duration},
utils::{duration_to_naive_time, duration_to_naive_time_ms, pg_interval_from_duration},
};

use crate::{
Expand Down
Loading