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: Report MDBX commit latency metrics #5668

Merged
merged 5 commits into from
Dec 15, 2023

Conversation

pakrentos
Copy link
Contributor

Implements an enhancement described in #5458

@onbjerg onbjerg added C-enhancement New feature or request A-db Related to the database labels Dec 4, 2023
@mattsse mattsse added the A-observability Related to tracing, metrics, logs and other observability tools label Dec 4, 2023
Copy link
Collaborator

@shekhirin shekhirin left a comment

Choose a reason for hiding this comment

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

I like this a lot, really clean change! Just a few comments.

crates/storage/db/src/metrics.rs Outdated Show resolved Hide resolved
Comment on lines +239 to +242
match this.inner.commit().map_err(|e| DatabaseError::Commit(e.into())) {
Ok((v, latency)) => (Ok(v), Some(latency)),
Err(e) => (Err(e), None),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

this looks a bit weird, feels like it would be better to put the latency into Ok variant and make it non-optional. But then we'd need to replace the Ok variant in execute_with_close_transaction_metric. What do you think is better?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@shekhirin i'm not sure if it is ok to make it non-optional, since abort function does not provide any latencies.
We can however introduce a method to CommitLatency that requires self-invocation (thus, it must be called after passing an inner pointer to some FFI method). This change would make getter methods return Some(Duration) instead of None (so the getters' return type must also be altered). However, this could lead to less readable code due to the need for additional checks within each metric during record. To mitigate this, we could employ a useful macro.

Additionally, we could employ the proposed method to set an internal flag, checked during transaction metric recording. Yet, I'm concerned this might not be a best practice.

Each of these approaches would enable the initialization of a new CommitLatency struct within the abort function, allowing us to pass it as part of the Ok variant

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, you're right about the abort method. Ok, current impl is fine with me!

Comment on lines +239 to +242
match this.inner.commit().map_err(|e| DatabaseError::Commit(e.into())) {
Ok((v, latency)) => (Ok(v), Some(latency)),
Err(e) => (Err(e), None),
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

ah, you're right about the abort method. Ok, current impl is fine with me!

@shekhirin
Copy link
Collaborator

LGTM, pending @mattsse

@shekhirin
Copy link
Collaborator

Verified that it works

ubuntu@reth3:~/reth$ curl -s localhost:9001 | grep '^reth_database_transaction_commit' | grep whole
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0"} 0.000015258
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0.5"} 0.000015256574364089644
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0.9"} 0.000015256574364089644
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0.95"} 0.000015256574364089644
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0.99"} 0.000015256574364089644
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="0.999"} 0.000015256574364089644
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="commit",quantile="1"} 0.000015258
reth_database_transaction_commit_whole_duration_seconds_sum{mode="read-only",outcome="commit"} 0.00044248199999999985
reth_database_transaction_commit_whole_duration_seconds_count{mode="read-only",outcome="commit"} 29
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0.5"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0.9"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0.95"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0.99"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="0.999"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",quantile="1"} 0
reth_database_transaction_commit_whole_duration_seconds_sum{mode="read-only"} 0
reth_database_transaction_commit_whole_duration_seconds_count{mode="read-only"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0.5"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0.9"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0.95"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0.99"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="0.999"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-only",outcome="drop",quantile="1"} 0
reth_database_transaction_commit_whole_duration_seconds_sum{mode="read-only",outcome="drop"} 0
reth_database_transaction_commit_whole_duration_seconds_count{mode="read-only",outcome="drop"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0"} 0.05485251
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0.5"} 0.06518668725510515
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0.9"} 0.06667667989030134
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0.95"} 0.06667667989030134
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0.99"} 0.06667667989030134
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="0.999"} 0.06667667989030134
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",outcome="commit",quantile="1"} 0.080699562
reth_database_transaction_commit_whole_duration_seconds_sum{mode="read-write",outcome="commit"} 1.2210061919999997
reth_database_transaction_commit_whole_duration_seconds_count{mode="read-write",outcome="commit"} 13
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0.5"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0.9"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0.95"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0.99"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="0.999"} 0
reth_database_transaction_commit_whole_duration_seconds{mode="read-write",quantile="1"} 0
reth_database_transaction_commit_whole_duration_seconds_sum{mode="read-write"} 0
reth_database_transaction_commit_whole_duration_seconds_count{mode="read-write"} 0

@shekhirin shekhirin added this pull request to the merge queue Dec 15, 2023
Merged via the queue into paradigmxyz:main with commit 667972c Dec 15, 2023
27 checks passed
@pakrentos pakrentos deleted the report_mbdx_metrics branch December 15, 2023 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-db Related to the database A-observability Related to tracing, metrics, logs and other observability tools C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants