mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
test: exercise chunk status and whole fsync-heavy workload
This commit is contained in:
1 parent
d42e123a89
commit
eeccf823cc
9 files changed
+132
-6
No files matched your search
@@ -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)
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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.
|
||||
|
||||
@@ -2,6 +2,7 @@ package frontend
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/iolatency"
|
||||
)
|
||||
|
||||
|
||||
@@ -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).
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user