From f28b4f271c0e56a7856cfc33df4e5fcd4fbed5e0 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 03:47:27 -0800 Subject: [PATCH] storage: measure disjoint pre-copy payload and fixed costs --- seaweed-block/core/storage/chunk_layer.go | 12 ++++++++++++ seaweed-block/core/storage/chunk_precopy.go | 13 +++++++------ seaweed-block/core/storage/chunk_seam.go | 2 ++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index dd204b694f..c22152366f 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -875,7 +875,11 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch // Pre-copy large native dirty sets outside the barrier, bounded by the // remaining COW exposure rather than a fixed candidate count. + stageStart := time.Now() staged, intents, err := l.stage(ctx, &st) + if st.UploadedBytes > 0 { + st.precopyPayloadNs += time.Since(stageStart).Nanoseconds() + } if err != nil { l.dropIntents(ctx, intents) return chunkCutResult{}, err @@ -976,6 +980,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.CandidateChunks = len(candidates) var copyErr error copyStart := time.Now() + bytesBeforeCopy := st.UploadedBytes if l.usesOwnedMapV3() { var w *cutCOWWindow w, copyErr = l.installCOWWindow(candidates, useStaged, baseHead.Chunks) @@ -1018,6 +1023,9 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.BarrierPauseNs = time.Since(pauseStart).Nanoseconds() } st.CopyNs = time.Since(copyStart).Nanoseconds() + if st.UploadedBytes > bytesBeforeCopy { + st.precopyPayloadNs += st.CopyNs + } if l.usesOwnedMapV3() { st.UploadNs = st.CopyNs } @@ -1085,6 +1093,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } intents = append(intents, id) } + payloadStart := time.Now() if err := l.uploadBatch(ctx, len(uploads), func(ctx context.Context, i int) error { u := uploads[i] return l.putCaptured(ctx, u.key, u.c.data) @@ -1093,6 +1102,9 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch l.dropIntents(ctx, intents) return chunkCutResult{}, fmt.Errorf("storage: capture upload: %w", errors.Join(errChunkRemoteUnavailable, errCutUpload, err)) } + if len(uploads) > 0 { + st.precopyPayloadNs += time.Since(payloadStart).Nanoseconds() + } for _, u := range uploads { next.Chunks[u.c.idx] = chunkRef{Key: u.key, SHA256: u.c.sum, Encoding: "full", BirthLSN: u.c.birth} newKeys[u.c.idx] = u.key diff --git a/seaweed-block/core/storage/chunk_precopy.go b/seaweed-block/core/storage/chunk_precopy.go index bdd5adbf97..1d639d8c77 100644 --- a/seaweed-block/core/storage/chunk_precopy.go +++ b/seaweed-block/core/storage/chunk_precopy.go @@ -49,6 +49,7 @@ func (l *chunkLayerImpl) PrecopyDetach(ctx context.Context, stopIO func() bool) l.capMu.Lock() defer l.capMu.Unlock() if r, ok := l.storedDetach(); ok { + r.Precopy.Frozen = true return r, nil } ctx, cancel := context.WithTimeout(ctx, precopyDuration) @@ -79,7 +80,7 @@ func (l *chunkLayerImpl) PrecopyDetach(ctx context.Context, stopIO func() bool) } if err != nil { // An unresolved publication or lost authority is never another rolling point. - if errors.Is(err, errChunkCASOutcomeUnknown) || errors.Is(err, errChunkLayerFenced) || errors.Is(err, errChunkLayerClosed) || ctx.Err() != nil { + if errors.Is(err, errChunkCASOutcomeUnknown) || errors.Is(err, errChunkLayerFenced) || errors.Is(err, errChunkLayerClosed) || ctx.Err() != nil || !(errors.Is(err, errCutCOWAborted) || errors.Is(err, errChunkRemoteUnavailable) || errors.Is(err, errChunkHeadPrecondition)) { return r, err } } @@ -104,8 +105,8 @@ func (l *chunkLayerImpl) precopyEstimate(tail uint64, attempts int) PrecopyRepor r.SampleAge = age } // With at most 32 observations the maximum is a conservative empirical - // p99 envelope. Whole-cut time includes transfer too, so it overcharges, - // rather than omitting, manifest/read-back/local work. The stop is drained. + // p99 envelope of the measured non-payload path (including final + // metadata, CAS/read-back and settlement). The stop is already drained. if s.fixed > r.Fixed { r.Fixed = s.fixed } @@ -144,9 +145,9 @@ func (l *chunkLayerImpl) precopyEstimate(tail uint64, attempts int) PrecopyRepor } func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats) { - s := precopySample{at: time.Now(), fixed: time.Duration(st.TotalNs)} - if st.UploadedBytes > 0 && st.UploadNs > 0 { - s.rate = float64(st.UploadedBytes) / time.Duration(st.UploadNs).Seconds() + s := precopySample{at: time.Now(), fixed: time.Duration(max(int64(1), st.TotalNs-st.precopyPayloadNs))} + if st.UploadedBytes > 0 && st.precopyPayloadNs > 0 { + s.rate = float64(st.UploadedBytes) / time.Duration(st.precopyPayloadNs).Seconds() } l.precopySamples = append(l.precopySamples, s) if len(l.precopySamples) > 32 { diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index f21eb65044..3795ce8294 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -397,6 +397,8 @@ type chunkLayerConfig struct { // chunkCutStats describes one cut. The periodic-cut work fills it; a zero // value means "not measured". type chunkCutStats struct { + precopyPayloadNs int64 // disjoint streaming/copy/upload wall intervals + // Local validated WAL attempts and local copy duration, including savers. COWWALReadAttempts uint64 COWLocalReadNs int64