Skip to content

Commit 1c9a0e5

Browse files
sshaderConvex, Inc.
authored and
Convex, Inc.
committed
Add more details to our metrics on push times (#24024)
* GitOrigin-RevId: abb085bb50dd1dd3838b8c200e2266c6f414dafa
1 parent cc5edc9 commit 1c9a0e5

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

crates/database/src/database.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,13 +1280,15 @@ impl<RT: Runtime> Database<RT> {
12801280
let start = Instant::now();
12811281
let result = async {
12821282
let t = f(&mut tx).0.await?;
1283+
let func_end_time = Instant::now();
12831284
let ts = self
12841285
.commit_with_write_source(tx, write_source.clone())
12851286
.await?;
1286-
Ok((ts, t))
1287+
let commit_end_time = Instant::now();
1288+
Ok((ts, t, func_end_time, commit_end_time))
12871289
}
12881290
.await;
1289-
let duration = Instant::now() - start;
1291+
let total_duration = Instant::now() - start;
12901292
match result {
12911293
Err(e) => {
12921294
if is_retriable(&e) {
@@ -1299,13 +1301,15 @@ impl<RT: Runtime> Database<RT> {
12991301
return Err(e);
13001302
}
13011303
},
1302-
Ok((ts, t)) => {
1304+
Ok((ts, t, func_end_time, commit_end_time)) => {
13031305
return Ok((
13041306
ts,
13051307
t,
13061308
OccRetryStats {
13071309
retries: backoff.failures(),
1308-
duration,
1310+
total_duration,
1311+
duration: func_end_time - start,
1312+
commit_duration: commit_end_time - func_end_time,
13091313
},
13101314
))
13111315
},
@@ -1897,8 +1901,10 @@ pub struct OccRetryStats {
18971901
/// Number of times the transaction was retried. 0 for a transaction that
18981902
/// succeeded the first time.
18991903
pub retries: u32,
1900-
/// The duration of the successful transaction
1904+
/// The duration of the successful transaction, not including commit
19011905
pub duration: Duration,
1906+
pub commit_duration: Duration,
1907+
pub total_duration: Duration,
19021908
}
19031909

19041910
/// The read that conflicted as part of an OCC

crates/local_backend/src/deploy_config.rs

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
use std::collections::BTreeMap;
1+
use std::{
2+
collections::BTreeMap,
3+
time::{
4+
Duration,
5+
Instant,
6+
},
7+
};
28

39
use anyhow::{
410
anyhow,
@@ -95,7 +101,7 @@ pub struct GetConfigHashesResponse {
95101

96102
#[derive(Deserialize, Debug, Copy, Clone)]
97103
#[serde(rename_all = "camelCase")]
98-
pub struct PushMetrics {
104+
pub struct ClientPushMetrics {
99105
pub typecheck: f64,
100106
pub bundle: f64,
101107
pub schema_push: f64,
@@ -137,7 +143,7 @@ pub struct ConfigJson {
137143
// Used in CLI >= 0.14.0, None when there is no schema file.
138144
pub schema_id: Option<String>,
139145
// Used in CLI >= future
140-
pub push_metrics: Option<PushMetrics>,
146+
pub push_metrics: Option<ClientPushMetrics>,
141147
// Use for external node dependencies
142148
// TODO: add what version of CLI this is used for
143149
pub node_dependencies: Option<Vec<NodeDependencyJson>>,
@@ -281,6 +287,12 @@ pub struct PushAnalytics {
281287
pub udf_server_version: Version,
282288
pub analyze_results: BTreeMap<CanonicalizedModulePath, AnalyzedModule>,
283289
pub schema: Option<DatabaseSchema>,
290+
}
291+
292+
pub struct PushMetrics {
293+
pub build_external_deps_time: Duration,
294+
pub upload_source_package_time: Duration,
295+
pub analyze_time: Duration,
284296
pub occ_stats: OccRetryStats,
285297
}
286298

@@ -351,7 +363,7 @@ pub async fn push_config(
351363
pub async fn push_config_handler(
352364
application: &Application<ProdRuntime>,
353365
config: ConfigJson,
354-
) -> anyhow::Result<(Identity, PushAnalytics)> {
366+
) -> anyhow::Result<(Identity, PushAnalytics, PushMetrics)> {
355367
let modules: Vec<ModuleConfig> = config
356368
.modules
357369
.into_iter()
@@ -366,6 +378,7 @@ pub async fn push_config_handler(
366378
ErrorMetadata::bad_request("InvalidVersion", "The function version is invalid"),
367379
)?;
368380

381+
let begin_build_external_deps = Instant::now();
369382
// Upload external node dependencies separately
370383
let external_deps_id_and_pkg = if let Some(deps) = config.node_dependencies
371384
&& !deps.is_empty()
@@ -375,6 +388,7 @@ pub async fn push_config_handler(
375388
} else {
376389
None
377390
};
391+
let end_build_external_deps = Instant::now();
378392
let external_deps_pkg_size = external_deps_id_and_pkg
379393
.as_ref()
380394
.map(|(_, pkg)| pkg.package_size)
@@ -383,7 +397,7 @@ pub async fn push_config_handler(
383397
let source_package = application
384398
.upload_package(&modules, external_deps_id_and_pkg)
385399
.await?;
386-
400+
let end_upload_source_package = Instant::now();
387401
// Verify that we have not exceeded the max zipped or unzipped file size
388402
let combined_pkg_size = source_package
389403
.as_ref()
@@ -398,7 +412,7 @@ pub async fn push_config_handler(
398412
import_phase_rng_seed: application.runtime().with_rng(|rng| rng.gen()),
399413
import_phase_unix_timestamp: application.runtime().unix_timestamp(),
400414
};
401-
415+
let begin_analyze = Instant::now();
402416
// Run analyze to make sure the new modules are valid.
403417
let (auth_module, analyze_result) = analyze_modules_with_auth_config(
404418
application,
@@ -407,6 +421,7 @@ pub async fn push_config_handler(
407421
source_package.clone(),
408422
)
409423
.await?;
424+
let end_analyze = Instant::now();
410425
let (
411426
ConfigMetadataAndSchema {
412427
config_metadata,
@@ -436,6 +451,11 @@ pub async fn push_config_handler(
436451
udf_server_version: udf_config.server_version,
437452
analyze_results: analyze_result,
438453
schema,
454+
},
455+
PushMetrics {
456+
build_external_deps_time: end_build_external_deps - begin_build_external_deps,
457+
upload_source_package_time: end_upload_source_package - end_build_external_deps,
458+
analyze_time: end_analyze - begin_analyze,
439459
occ_stats,
440460
},
441461
))

0 commit comments

Comments
 (0)