From eeccf823cc8c59f871a5fc317d79377d4080b58e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Mon, 16 Nov 2026 00:27:36 -0800 Subject: [PATCH] test: exercise chunk status and whole fsync-heavy workload --- .../frontend/durable/latency_perf_test.go | 62 +++++++++++++++++++ .../frontend/durable/latency_status_test.go | 24 +++++++ .../core/frontend/durable/write_profile.go | 5 +- seaweed-block/core/frontend/latency.go | 1 + seaweed-block/core/frontend/ublk/dispatch.go | 3 +- .../core/host/volume/status_latency_test.go | 34 ++++++++++ seaweed-block/core/storage/group_commit.go | 3 +- seaweed-block/core/storage/walstore.go | 3 +- .../core/storage/write_instrumentation.go | 3 +- 9 files changed, 132 insertions(+), 6 deletions(-) create mode 100644 seaweed-block/core/frontend/durable/latency_perf_test.go create mode 100644 seaweed-block/core/host/volume/status_latency_test.go diff --git a/seaweed-block/core/frontend/durable/latency_perf_test.go b/seaweed-block/core/frontend/durable/latency_perf_test.go new file mode 100644 index 0000000000..1127a7ad80 --- /dev/null +++ b/seaweed-block/core/frontend/durable/latency_perf_test.go @@ -0,0 +1,62 @@ +package durable_test + +import ( + "context" + "encoding/json" + "fmt" + "os" + "sort" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/frontend/nvme" + "github.com/seaweedfs/seaweed-block/core/storage" +) + +// Identical file compiled on main and the feature head. Includes the full +// 4K write plus paired Flush, handler and backend, not only the fsync syscall. +func TestDurabilityLatencyPerf(t *testing.T) { + if os.Getenv("SW_BLOCK_LATENCY_PERF") != "1" { + t.Skip("opt-in file-backed fsync-heavy proxy") + } + for _, kind := range []string{"walstore", "walstore-chunk"} { + t.Run(kind, func(t *testing.T) { + var b *durable.StorageBackend + if kind == "walstore" { + b = openDurableBackend(t, durable.ImplWALStore, 256, 4096) + } else { + p := chunkProvider(t, t.TempDir(), storage.NewMemChunkRemote(), v1View(), 0) + openRecovered(t, p) + if _, err := p.Open(context.Background(), "v1"); err != nil { + t.Fatal(err) + } + b = p.Backend("v1") + } + h := nvme.NewIOHandler(nvme.HandlerConfig{Backend: b, BlockSize: 4096, VolumeSize: 256 * 4096, NSID: 1}) + data := make([]byte, 4096) + ns := make([]int64, 0, 100) + for i := 0; i < 110; i++ { + data[0] = byte(i) + start := time.Now() + cmds := []nvme.IOCommand{{Opcode: 1, NSID: 1, NLB: 1, SLBA: uint64(i % 128), Data: data}, {Opcode: 0, NSID: 1}, {Opcode: 0, NSID: 1}} + for _, cmd := range cmds { + if r := h.Handle(context.Background(), cmd); r.AsError() != nil { + t.Fatal(r.AsError()) + } + } + if i >= 10 { + ns = append(ns, time.Since(start).Nanoseconds()) + } + } + sort.Slice(ns, func(i, j int) bool { return ns[i] < ns[j] }) + var sum int64 + for _, n := range ns { + sum += n + } + report := map[string]any{"impl": kind, "samples": 100, "mean_ns": sum / 100, "p50_ns": ns[49], "p99_ns": ns[98], "scope": "file-backed 4K Write + paired Flush; no guest/frontend transport"} + encoded, _ := json.Marshal(report) + fmt.Printf("LATENCY_WORKLOAD %s\n", encoded) + }) + } +} diff --git a/seaweed-block/core/frontend/durable/latency_status_test.go b/seaweed-block/core/frontend/durable/latency_status_test.go index a4866a2e1f..af93f37f9b 100644 --- a/seaweed-block/core/frontend/durable/latency_status_test.go +++ b/seaweed-block/core/frontend/durable/latency_status_test.go @@ -6,6 +6,7 @@ import ( "testing" "github.com/seaweedfs/seaweed-block/core/frontend/nvme" + "github.com/seaweedfs/seaweed-block/core/storage" ) func TestDurabilityLatencyStatusPresent(t *testing.T) { @@ -47,3 +48,26 @@ func TestDurabilityLatencyNVMeRequests(t *testing.T) { t.Fatal("missing WAL stages", s) } } + +func TestDurabilityLatencyChunkProviderStatus(t *testing.T) { + p := chunkProvider(t, t.TempDir(), storage.NewMemChunkRemote(), v1View(), 0) + openRecovered(t, p) + if _, err := p.Open(context.Background(), "v1"); err != nil { + t.Fatal(err) + } + b := p.Backend("v1") + if _, err := b.Write(context.Background(), 0, make([]byte, 4096)); err != nil { + t.Fatal(err) + } + if err := b.Sync(context.Background()); err != nil { + t.Fatal(err) + } + statuses := p.DurableStatuses() + if len(statuses) != 1 { + t.Fatal(statuses) + } + l := statuses[0].WriteProfile.DurabilityLatency + if l.WAL == nil || l.WAL.WALAppend.Count == 0 || l.WAL.GroupCommitWait.Count == 0 || l.WAL.FileSync.Count == 0 || l.BackendSync.Count == 0 { + t.Fatal(l) + } +} diff --git a/seaweed-block/core/frontend/durable/write_profile.go b/seaweed-block/core/frontend/durable/write_profile.go index c32d5acc75..6a2906f655 100644 --- a/seaweed-block/core/frontend/durable/write_profile.go +++ b/seaweed-block/core/frontend/durable/write_profile.go @@ -1,10 +1,11 @@ package durable import ( - "github.com/seaweedfs/seaweed-block/core/iolatency" - "github.com/seaweedfs/seaweed-block/core/storage" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/core/iolatency" + "github.com/seaweedfs/seaweed-block/core/storage" ) // WriteProfileStatus is a read-only diagnostic snapshot for write-path gates. diff --git a/seaweed-block/core/frontend/latency.go b/seaweed-block/core/frontend/latency.go index 97d7877aa4..22945b1a7a 100644 --- a/seaweed-block/core/frontend/latency.go +++ b/seaweed-block/core/frontend/latency.go @@ -2,6 +2,7 @@ package frontend import ( "context" + "github.com/seaweedfs/seaweed-block/core/iolatency" ) diff --git a/seaweed-block/core/frontend/ublk/dispatch.go b/seaweed-block/core/frontend/ublk/dispatch.go index cfcd03637f..0bba24c5b8 100644 --- a/seaweed-block/core/frontend/ublk/dispatch.go +++ b/seaweed-block/core/frontend/ublk/dispatch.go @@ -2,9 +2,10 @@ package ublk import ( "context" - "github.com/seaweedfs/seaweed-block/core/frontend" "sync/atomic" "syscall" + + "github.com/seaweedfs/seaweed-block/core/frontend" ) // ublk request operations and flags (include/uapi/linux/ublk_cmd.h). diff --git a/seaweed-block/core/host/volume/status_latency_test.go b/seaweed-block/core/host/volume/status_latency_test.go new file mode 100644 index 0000000000..d6c9d5b107 --- /dev/null +++ b/seaweed-block/core/host/volume/status_latency_test.go @@ -0,0 +1,34 @@ +package volume + +import ( + "context" + "encoding/json" + "github.com/seaweedfs/seaweed-block/core/frontend/durable" + "github.com/seaweedfs/seaweed-block/core/iolatency" + "net/http" + "testing" +) + +func TestDurabilityLatencyExistingHTTPEndpoint(t *testing.T) { + var h iolatency.Histogram + h.Observe(100) + s := NewStatusServer(NewAdapterProjectionView(stubProjector{}, "v1", "r1", nil)) + s.SetDurableStatusSource(stubDurableStatusSource{vols: []durable.VolumeStatus{{VolumeID: "v1", WriteProfile: durable.WriteProfileStatus{DurabilityLatency: durable.DurabilityLatencyStatus{BackendSync: h.Snapshot()}}}}}) + addr, err := s.Start("127.0.0.1:0") + if err != nil { + t.Fatal(err) + } + defer s.Close(context.Background()) + r, err := http.Get("http://" + addr + "/status/durable?volume=v1") + if err != nil { + t.Fatal(err) + } + defer r.Body.Close() + var body struct{ Volumes []durable.VolumeStatus } + if err := json.NewDecoder(r.Body).Decode(&body); err != nil { + t.Fatal(err) + } + if r.StatusCode != 200 || len(body.Volumes) != 1 || body.Volumes[0].WriteProfile.DurabilityLatency.BackendSync.Count != 1 || body.Volumes[0].WriteProfile.DurabilityLatency.BackendSync.P99UpperNanos != 128 { + t.Fatal(body) + } +} diff --git a/seaweed-block/core/storage/group_commit.go b/seaweed-block/core/storage/group_commit.go index a79de75dbb..67b8de0921 100644 --- a/seaweed-block/core/storage/group_commit.go +++ b/seaweed-block/core/storage/group_commit.go @@ -2,10 +2,11 @@ package storage import ( "errors" - "github.com/seaweedfs/seaweed-block/core/iolatency" "sync" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/core/iolatency" ) var ErrGroupCommitShutdown = errors.New("storage: group committer shut down") diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 52412c4688..6028d9f68b 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -3,12 +3,13 @@ package storage import ( "errors" "fmt" - "github.com/seaweedfs/seaweed-block/core/iolatency" "os" "path/filepath" "sync" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/core/iolatency" ) // WALStore is a crash-safe block store backed by one preallocated diff --git a/seaweed-block/core/storage/write_instrumentation.go b/seaweed-block/core/storage/write_instrumentation.go index 4378b60b93..d51a641d53 100644 --- a/seaweed-block/core/storage/write_instrumentation.go +++ b/seaweed-block/core/storage/write_instrumentation.go @@ -1,9 +1,10 @@ package storage import ( - "github.com/seaweedfs/seaweed-block/core/iolatency" "sync/atomic" "time" + + "github.com/seaweedfs/seaweed-block/core/iolatency" ) // WriteInstrumentationStatus is a read-only snapshot of storage-internal write