Repository navigation
feat(metrics): Time transaction start, commit lock wait, and commit - #5405
colinbarry wants to merge 7 commits into
Conversation
When throughput dropped with idle CPU, nothing showed whether transactions were waiting on locks or doing work. Each database now exports three histograms: memgraph_transaction_begin_seconds (starting a transaction, mostly the storage access and engine lock waits), memgraph_commit_lock_wait_seconds (a write commit waiting for the commit locks), and memgraph_commit_seconds (the whole write commit, including the WAL write and SYNC replicas).
|
This PR has potential conflicts with the following other open pull requests which modify the same files:
|
Tracking
Standard development
CI Testing Labels
Kubernetes operator / Helm chartsDoes this change affect how Memgraph is deployed or configured on Kubernetes? It likely does if it adds, removes or renames a flag; changes run-time or startup settings; touches the license, AWS settings, coordinators, replication, TLS, monitoring or another enterprise feature.
Documentation checklist
|
|
Release note advisory Release note: The note contains two sentences and extra explanatory text; the required format calls for one short sentence describing the change followed immediately by the PR link. Consider shortening to a single sentence (e.g., describing the added histograms) and then the link. |
Unit tests build InMemoryStorage without metric handles, and the begin and commit timers asserted that the handles exist. Pass the raw histogram, which ScopedHistogramTimer already allows to be null.
Background work such as TTL, the async indexer, and replication also opens storage accessors, and unique accessors wait for running transactions by design, so timing in storage mixed internal waits into the begin histogram. Time the accessor setup in the interpreter instead. The commit histogram's help now says it covers each commit attempt, failed ones included.
…TRICS INFO Every metric must be readable through Cypher. Add the begin, commit lock wait, and commit histograms to SHOW METRICS INFO as p50, p90, and p99 rows, as for the other latency histograms. The deprecated JSON endpoint is unchanged.
Replicas observe memgraph_commit_seconds and memgraph_commit_lock_wait_seconds when they apply a replicated commit. The Help text now says so.
|
… released Observing commit_lock_wait_seconds right after taking the engine lock held the lock while the histogram's mutex was taken, so a scrape copying that histogram could stall every commit on the database. Measure the wait under the lock, and record it on scope exit, after the engine lock and the commit mutex are released.
There was a problem hiding this comment.
Automated review by the Memgraph review service
Verdict: APPROVE WITH NITS
Findings: 0 blocker, 1 non-blocking, 0 nit (1 inline) · 2 pre-existing · 2 nits (collapsed)
Pre-existing, not introduced by this PR (2)
-
src/dbms/inmemory/replication_handlers.cpp:608-613[Non-blocking] Strict-sync replica 2nd-phase finalization is not measured by either commit histogram
-
src/storage/v2/disk/storage.cpp:1816[Non-blocking] On-disk (
ON_DISK_TRANSACTIONAL) databases never populate the commit histograms, producing permanently-zeroCommitLatency/CommitLockWaitLatencypercentiles
Nits (2)
-
design.md:20[Nit] Release note and PR summary say "Time to commit" without "attempt" qualifier
vs correct Help text at
prometheus_metrics.cpp:797–801. -
?:1[Nit] Empty CI commit
52bb882b9zero file changes.
2 findings that state they need no change are omitted; they are in the full report.
| auto commit_serializer = mem_storage->LockCommitMutexIfNarrowing(); | ||
|
|
||
| auto engine_guard = std::unique_lock{storage_->engine_lock_}; | ||
| mem_storage->metric_handles_.commit_lock_wait_seconds.Observe(commit_lock_timer.Elapsed().count()); |
There was a problem hiding this comment.
[Non-blocking] commit_lock_wait_seconds.Observe() runs while holding commit_mutex_ + engine_lock_, adding prometheus-internal mutex contention to the commit critical section



When throughput dropped while CPU stayed idle, nothing showed whether transactions were waiting on locks or doing work.
Each database now exports three histograms:
memgraph_transaction_begin_secondsdatabase,uuidmemgraph_commit_lock_wait_secondsdatabase,uuidmemgraph_commit_secondsdatabase,uuidRead-only transactions are not counted in the commit histograms.
SHOW METRICS INFOreports them asTransactionBeginLatency,CommitLockWaitLatency, andCommitLatency, each as p50, p90, and p99 rows.