docs: explain durable latency populations and fsync diagnosis

This commit is contained in:
pingqiu committed 2026-11-16 00:24:25 -08:00
1 parent cb17180f10
commit d42e123a89
3 files changed
+49 -5

No files matched your search

+17 -4
View File
@@ -64,10 +64,14 @@ func (h *Histogram) Snapshot() Distribution {
// Requests is the common frontend-to-backend boundary, shared by ublk and NVMe.
// AckDispatch ends before the handler returns a result, not at guest receipt.
type Requests struct {
receive, ack, total Histogram
writes, flushes, fua, failed atomic.Uint64
writeTotal, flushTotal, fuaTotal Histogram
receive, ack, total Histogram
writes, flushes, fua, failed atomic.Uint64
}
type RequestStatus struct {
WriteTotal Distribution
FlushTotal Distribution
FUATotal Distribution
ReceiveToBackend Distribution
AckDispatch Distribution
RequestTotal Distribution
@@ -78,7 +82,7 @@ type RequestStatus struct {
}
func (c *Requests) Snapshot() RequestStatus {
return RequestStatus{c.receive.Snapshot(), c.ack.Snapshot(), c.total.Snapshot(), c.writes.Load(), c.flushes.Load(), c.fua.Load(), c.failed.Load()}
return RequestStatus{WriteTotal: c.writeTotal.Snapshot(), FlushTotal: c.flushTotal.Snapshot(), FUATotal: c.fuaTotal.Snapshot(), ReceiveToBackend: c.receive.Snapshot(), AckDispatch: c.ack.Snapshot(), RequestTotal: c.total.Snapshot(), Writes: c.writes.Load(), Flushes: c.flushes.Load(), FUAWrites: c.fua.Load(), Failed: c.failed.Load()}
}
type requestKey struct{}
@@ -86,6 +90,7 @@ type requestKey struct{}
// Request is owned by one synchronous frontend dispatch. No request IDs, payloads
// or unbounded sample buffers are retained.
type Request struct {
kind string
owner *Requests
start, backendEnd time.Time
entered bool
@@ -103,7 +108,7 @@ func (c *Requests) Begin(ctx context.Context, kind string) (context.Context, *Re
default:
return ctx, nil
}
r := &Request{owner: c, start: time.Now()}
r := &Request{owner: c, start: time.Now(), kind: kind}
return context.WithValue(ctx, requestKey{}, r), r
}
func BackendEnter(ctx context.Context) {
@@ -123,6 +128,14 @@ func (r *Request) Finish(failed bool) {
}
end := time.Now()
r.owner.total.Observe(end.Sub(r.start))
switch r.kind {
case "write":
r.owner.writeTotal.Observe(end.Sub(r.start))
case "flush":
r.owner.flushTotal.Observe(end.Sub(r.start))
case "fua":
r.owner.fuaTotal.Observe(end.Sub(r.start))
}
if !r.backendEnd.IsZero() {
r.owner.ack.Observe(end.Sub(r.backendEnd))
}
+1 -1
View File
@@ -56,7 +56,7 @@ func TestRequestKindsAndMissingBackend(t *testing.T) {
}
r.Finish(false)
s := c.Snapshot()
if s.Writes != 2 || s.Flushes != 1 || s.FUAWrites != 1 || s.Failed != 1 || s.RequestTotal.Count != 3 || s.ReceiveToBackend.Count != 3 || s.AckDispatch.Count != 3 {
if s.Writes != 2 || s.Flushes != 1 || s.FUAWrites != 1 || s.Failed != 1 || s.RequestTotal.Count != 3 || s.FlushTotal.Count != 1 || s.FUATotal.Count != 1 || s.WriteTotal.Count != 1 || s.ReceiveToBackend.Count != 3 || s.AckDispatch.Count != 3 {
t.Fatal(s)
}
_, r = c.Begin(context.Background(), "flush")
+31
View File
@@ -0,0 +1,31 @@
# Fsync latency breakdown
For walstore and walstore-chunk, read the existing volume-host endpoint:
```sh
curl -fsS 'http://127.0.0.1:PORT/status/durable?volume=VOLUME'
```
Find `WriteProfile.DurabilityLatency` in the returned volume status. Instrumentation is on by default, cumulative for this open backend/store, bounded in memory, and does not change batching, Sync dedup, write acknowledgement, replication or checkpoint ordering. A missing `WAL` object means that backend does not expose walstore timing; it does not mean zero latency. Restart/reopen starts a new series. Capture before/after bucket counters for an isolated workload, then calculate interval quantiles from bucket differences; do not subtract cumulative p99 values.
| Field | Sample and boundary |
|---|---|
| `Frontend.ReceiveToBackend` | Each write/FUA/Flush that enters StorageBackend: handler dispatch start to first backend call, before admission/fence checks. No socket/uring/kernel/guest scheduling before the handler. |
| `WAL.WALAppend` | Each local single/grouped append attempt (including errors): encode, WAL lock, wrap/padding and file writes inside the append call. A batch is one sample, not one per block. Excludes publication/admission wait before that call. |
| `WAL.GroupCommitWait` | Each waiter selected for dispatch: insertion into the committer queue to batch dispatch, before physical Sync. Includes scheduling/batching delay, excludes syscall time. Shutdown-drained requests have no dispatch sample. |
| `WAL.FileSync` | Each attempted physical WAL file `Sync` call, including errors; one per shared batch. This is Go's file Sync/fsync path, not a claim that fdatasync is used. Deduplicated Sync requests add no physical sample. |
| `BackendSync` | Every adapter Sync attempt, including gate refusal and errors: admission, local/group commit, direct-frontier metadata and any replication-observer barrier. Encloses other stages; it is not an additional summand. |
| `Frontend.AckDispatch` | Last backend Write/Sync return to handler completion/result construction, for requests that entered a backend. Includes failure-result dispatch. Ends before actual CQE/socket completion and guest receipt. |
| `Frontend.WriteTotal`, `FlushTotal`, `FUATotal` | Handler-dispatch-to-result latency separately for ordinary writes, Flush and FUA. Includes refused requests. `RequestTotal` pools all three; use the separate Flush/FUA distributions for fsync diagnosis. |
Each distribution exposes `Count`, `SumNanos`, 64 non-cumulative `Buckets`, `P50UpperNanos` and `P99UpperNanos`. Bucket 0 holds 0 ns; bucket i>0 holds [2^(i-1), 2^i) ns. Quantiles report conservative power-of-two upper bounds, not exact samples. Zero samples have zero quantiles. Concurrent snapshots are best-effort, not transactional; quiesce the workload for exact counts. Atomic storage is fixed size: no per-volume unbounded labels, request logs or payloads.
`Frontend.Writes` includes FUA, `FUAWrites` is its subset, `Flushes` counts Flush commands and `Failed` counts unsuccessful handler results. Invalid requests are counted without inventing backend or disk samples. Non-durable backends retain their existing dispatch behavior. ublk and NVMe/TCP use the same optional backend timing seam; no guest filesystem or hardware is required for accounting tests.
A guest fsync may produce two Flush commands; compare command counts and physical Sync samples before attributing two disk syncs. Shared physical Sync and per-request queue samples have different populations. Do not add p50/p99 values, or subtract one stage's p99 from another's. Large queue time suggests batching/scheduling; large FileSync suggests local file/disk latency; large BackendSync with small local stages can include replication or metadata work. This diagnostic does not separately time each replication/checkpoint operation. Kernel transport completion and guest scheduling require the M5 external measurement. No frontend tuning or durability-policy change is included.
## Verification and overhead scope
Unit controls cover known histogram quantiles, concurrent counters, failed/refused requests, both frontend dispatchers, batch waiter-versus-physical counts and dedup. The initial status contract test fails on unmodified main because the existing JSON has no durability histograms.
The PR records an interleaved main-versus-instrumented comparison of the existing file-backed TCP paired-Flush proxy (`SW_BLOCK_SYNC_PERF=1`, `TestNVMePairedFlushLatency`), using prebuilt binaries on tp04. It measures request-path default-on overhead; it is not mounted fio, a guest fsync result, or a device-specific latency promise. M5 may proceed independently if this PR has not landed.