Skip to content

Commit

Permalink
Add metrics for index inserts and deletes (#2236)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsdt authored Feb 10, 2025
1 parent d43548b commit c2d40f8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
5 changes: 2 additions & 3 deletions crates/cli/examples/regen-csharp-moduledef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn main() -> anyhow::Result<()> {
},
)?
.into_iter()
.map(|(filename, code)| {
.try_for_each(|(filename, code)| {
// Skip anything but raw types (in particular, this will skip top-level SpacetimeDBClient.g.cs which we don't need).
let Some(filename) = filename.strip_prefix("Types/") else {
return Ok(());
Expand All @@ -64,8 +64,7 @@ fn main() -> anyhow::Result<()> {
);

fs::write(dir.join(filename), code.as_ref())
})
.collect::<std::io::Result<()>>()?;
})?;

Ok(())
}
25 changes: 23 additions & 2 deletions crates/core/src/db/datastore/locking_tx_datastore/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -689,20 +689,41 @@ pub(super) fn record_tx_metrics(

if let (Some(tx_data), Some(committed_state)) = (tx_data, committed_state) {
for (table_id, table_name, inserts) in tx_data.inserts_with_table_name() {
update_table_gauges(db, table_id, table_name, committed_state.get_table(*table_id));
let table = committed_state.get_table(*table_id);
let num_indexes = table.map(|t| t.indexes.len()).unwrap_or(0) as u64;

update_table_gauges(db, table_id, table_name, table);
// Increment rows inserted counter
DB_METRICS
.rdb_num_rows_inserted
.with_label_values(workload, db, reducer, &table_id.0, table_name)
.inc_by(inserts.len() as u64);
// We don't have sparse indexes, so we can just multiply by the number of indexes.
if num_indexes > 0 {
// Increment index rows inserted counter
DB_METRICS
.rdb_num_index_entries_inserted
.with_label_values(workload, db, reducer, &table_id.0, table_name)
.inc_by((inserts.len() as u64) * num_indexes);
}
}
for (table_id, table_name, deletes) in tx_data.deletes_with_table_name() {
update_table_gauges(db, table_id, table_name, committed_state.get_table(*table_id));
let table = committed_state.get_table(*table_id);
let num_indexes = table.map(|t| t.indexes.len()).unwrap_or(0) as u64;
update_table_gauges(db, table_id, table_name, table);
// Increment rows deleted counter
DB_METRICS
.rdb_num_rows_deleted
.with_label_values(workload, db, reducer, &table_id.0, table_name)
.inc_by(deletes.len() as u64);
// We don't have sparse indexes, so we can just multiply by the number of indexes.
if num_indexes > 0 {
// Increment index rows inserted counter
DB_METRICS
.rdb_num_index_entries_deleted
.with_label_values(workload, db, reducer, &table_id.0, table_name)
.inc_by((deletes.len() as u64) * num_indexes);
}
}
}

Expand Down
10 changes: 10 additions & 0 deletions crates/core/src/db/db_metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,21 @@ metrics_group!(
#[labels(txn_type: WorkloadType, db: Identity, reducer_or_query: str, table_id: u32, table_name: str)]
pub rdb_num_rows_inserted: IntCounterVec,

#[name = spacetime_num_index_rows_inserted_total]
#[help = "The cumulative number of index entries inserted. Does not count schema changes."]
#[labels(txn_type: WorkloadType, db: Identity, reducer_or_query: str, table_id: u32, table_name: str)]
pub rdb_num_index_entries_inserted: IntCounterVec,

#[name = spacetime_num_rows_deleted_total]
#[help = "The cumulative number of rows deleted from a table"]
#[labels(txn_type: WorkloadType, db: Identity, reducer_or_query: str, table_id: u32, table_name: str)]
pub rdb_num_rows_deleted: IntCounterVec,

#[name = spacetime_num_index_rows_deleted_total]
#[help = "The cumulative number of index entries deleted. Does not count schema changes."]
#[labels(txn_type: WorkloadType, db: Identity, reducer_or_query: str, table_id: u32, table_name: str)]
pub rdb_num_index_entries_deleted: IntCounterVec,

#[name = spacetime_num_rows_scanned_total]
#[help = "The cumulative number of rows scanned from the database"]
#[labels(txn_type: WorkloadType, db: Identity)]
Expand Down

2 comments on commit c2d40f8

@github-actions
Copy link

@github-actions github-actions bot commented on c2d40f8 Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Criterion benchmark results

Error when comparing benchmarks: Couldn't find AWS credentials in environment, credentials file, or IAM role.

Caused by:
Couldn't find AWS credentials in environment, credentials file, or IAM role.

@github-actions
Copy link

@github-actions github-actions bot commented on c2d40f8 Feb 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Callgrind benchmark results Error when comparing benchmarks: Couldn't find AWS credentials in environment, credentials file, or IAM role.

Caused by:
Couldn't find AWS credentials in environment, credentials file, or IAM role.

Please sign in to comment.