Skip to content

feat(analytics): expose write/read transaction queue depth (count) metrics#1689

Open
kriszyp wants to merge 2 commits into
mainfrom
kris/txn-queue-depth-metrics-592
Open

feat(analytics): expose write/read transaction queue depth (count) metrics#1689
kriszyp wants to merge 2 commits into
mainfrom
kris/txn-queue-depth-metrics-592

Conversation

@kriszyp

@kriszyp kriszyp commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

Adds write-transaction-queue-depth and read-transaction-queue-depth gauges (instantaneous depth + per-sampling-window maxDepth high-water mark) through the analytics pipeline. Write depth counts write commits handed to the storage engine but not yet resolved; read depth counts open read-snapshot transactions (trackedTxns).

Purpose

Secondary/optional to #592. The primary leading indicator for the queue-overload 503 ships separately in #1688 (transaction-commit-time, a latency distribution measured on the same clock the overload check uses).

Open question for the reviewer — is this metric worth shipping at all? A per-thread count doesn't capture transaction size/duration, and each thread's queue is local while the real bottleneck is the shared storage-engine write path — so count can tell you which thread is submitting more, but not how close the system is to the 503. Kris raised this tradeoff; #1688 is the metric he considers the better predictor. This PR is offered as a complementary, cheap signal (concurrency-by-thread), not a replacement — happy to close it if the added surface area (2 more metric names, getTransactionQueueDepths call every sampling period) isn't judged worth it standalone.

Attention

Generated by Claude Opus 4.8.

…trics

Secondary/supplementary metric for #592 (the primary leading indicator ships
separately as the transaction-commit-time latency distribution). Emits
write-transaction-queue-depth and read-transaction-queue-depth through the
analytics pipeline as a per-thread concurrency signal.

Write depth counts in-flight write commits (handed to the storage engine but
not yet resolved); read depth is the count of open read-snapshot transactions
(trackedTxns). Each gauge reports both the instantaneous depth and a
per-sampling-window high-water mark, since the queue can fill and drain within
a single (~1s) analytics period.

Caveat (see PR description): a per-thread count does not capture transaction
size/duration or the shared storage-engine write path, so latency
(transaction-commit-time) is the better predictor of the overload error; this
count is complementary (which worker is submitting more), not the primary signal.

Relates to #592

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
gemini-code-assist[bot]

This comment was marked as resolved.

@claude

claude Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

… hardening

- Skip both queue-depth assertions under HARPER_STORAGE_ENGINE=lmdb: LMDB
  writes/reads route through the separate LMDBTransaction overrides
  (resources/LMDBTransaction.ts), which maintain their own unrelated
  trackedTxns set and do not feed this accounting -- matching the existing
  RocksDB-only carve-outs in transaction.test.js. This is what failed CI
  (all 3 Node versions, via the npm run test:unit:all -> test:unit:lmdb pass).
- leaveWriteQueue() floors at zero, per Gemini review feedback -- cheap
  insurance against a future call-site imbalance corrupting every
  subsequent sample.
- Guard commitResolution as thenable before calling .then(), per Gemini
  review feedback -- defensive against a future caller passing a
  non-Promise value (today's only caller, rocksdb-js's async
  Transaction.commit(), always returns a real Promise).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@kriszyp kriszyp marked this pull request as ready for review July 7, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant