From 10cbe8a5b025c14b3c805047221f98ffabaa2e25 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 16:40:45 -0800 Subject: [PATCH 1/3] storage: a pre-copy rate sample survives an upload below the clock's tick samplePrecopy recorded a rate only when the round's payload time was nonzero, so a round whose upload ended below the clock's resolution gave no rate, and three such rounds left the estimate "samples_unknown". The payload time is now floored at the coarsest clock resolution (1 ms): the rate of a fast round is a lower bound, never missing or infinite. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/storage/chunk_precopy.go | 12 ++++++-- .../storage/chunk_precopy_rate_floor_test.go | 29 +++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 seaweed-block/core/storage/chunk_precopy_rate_floor_test.go diff --git a/seaweed-block/core/storage/chunk_precopy.go b/seaweed-block/core/storage/chunk_precopy.go index 61a746c4cd..5d9a1d037c 100644 --- a/seaweed-block/core/storage/chunk_precopy.go +++ b/seaweed-block/core/storage/chunk_precopy.go @@ -448,6 +448,11 @@ func precopyFixedPartsFromSample(s precopySample) PrecopyFixedParts { return p } +// precopyPayloadClockFloor is the least payload time a rate sample divides +// by: the coarsest clock resolution a host may have (Windows ticks about +// every 0.5 ms). It lowers the rate of an upload measured faster than that. +const precopyPayloadClockFloor = time.Millisecond + func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { // A no-op root read is not a measurement of final CAS + confirmation. if st.CASNs <= 0 { @@ -460,8 +465,11 @@ func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { } s := precopySample{at: time.Now(), fixed: time.Duration(max(int64(1), fixedNs))} s.parts = precopyFixedParts(st, s.fixed) - if st.UploadedBytes > 0 && st.PayloadNs > 0 { - s.rate = float64(st.UploadedBytes) / time.Duration(st.PayloadNs).Seconds() + if st.UploadedBytes > 0 { + // An upload can also end below the clock's resolution (its payload + // time reads zero): its rate is taken at the resolution, a lower + // bound, so a fast round is never a missing or an infinite sample. + s.rate = float64(st.UploadedBytes) / max(time.Duration(st.PayloadNs), precopyPayloadClockFloor).Seconds() } l.precopySamples = append(l.precopySamples, s) if len(l.precopySamples) > 32 { diff --git a/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go new file mode 100644 index 0000000000..0367b129a7 --- /dev/null +++ b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go @@ -0,0 +1,29 @@ +package storage + +import ( + "testing" + "time" +) + +// A round that uploaded bytes in less time than the clock resolves (its +// payload time reads zero) is still a rate sample: its rate is taken at the +// clock's resolution, a lower bound, never missing and never infinite. A +// round that uploaded nothing gives no rate, as before. +func TestPrecopyRateSampleAtTheClocksResolution(t *testing.T) { + l := &chunkLayerImpl{} + l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 16384, PayloadNs: 0}, 1000) + if len(l.precopySamples) != 1 { + t.Fatalf("%d samples, want 1", len(l.precopySamples)) + } + rate := l.precopySamples[0].rate + if most := 16384 / precopyPayloadClockFloor.Seconds(); rate <= 0 || rate > most { + t.Fatalf("a sub-resolution upload's rate is %.0f B/s, want above 0 and at most %.0f (its bytes over the clock's resolution)", rate, most) + } + l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 0, PayloadNs: 0}, 1000) + if r := l.precopySamples[1].rate; r != 0 { + t.Fatalf("a round that uploaded nothing gave rate %.0f, want none", r) + } + if precopyPayloadClockFloor < time.Microsecond || precopyPayloadClockFloor > 10*time.Millisecond { + t.Fatalf("the clock floor %s is outside any clock's resolution", precopyPayloadClockFloor) + } +} From 67f770d650a3c8c2033eb23fadc703e2c9639f0f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 16:53:21 -0800 Subject: [PATCH 2/3] storage: floor each pre-copy payload interval, not their sum The payload time sums several intervals (staging, the copy, the upload); three that each ended below the clock's tick read zero although together they took up to three ticks, so one floor on the sum overstated the rate. Each interval now adds at least one tick to an unexported floored sum that the rate divides by; the reported payload time is unchanged. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/storage/chunk_layer.go | 6 ++-- seaweed-block/core/storage/chunk_precopy.go | 17 ++++++++--- .../storage/chunk_precopy_rate_floor_test.go | 29 +++++++++++++++++++ seaweed-block/core/storage/chunk_seam.go | 5 ++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 580ffddaec..a67bc42dbd 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1150,7 +1150,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if !guestFrozen { staged, err = l.stage(ctx, &st, spill.bytes) } - st.PayloadNs += time.Since(stageStart).Nanoseconds() + st.addPayload(time.Since(stageStart).Nanoseconds()) if err != nil { return chunkCutResult{}, err } @@ -1334,7 +1334,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.CopyNs = time.Since(copyStart).Nanoseconds() if st.UploadedBytes > bytesBeforeCopy { - st.PayloadNs += st.CopyNs + st.addPayload(st.CopyNs) } else { st.NonPayloadCopyNs += st.CopyNs } @@ -1417,7 +1417,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch return chunkCutResult{}, fmt.Errorf("storage: capture upload: %w", errors.Join(errChunkRemoteUnavailable, errCutUpload, err)) } if len(uploads) > 0 { - st.PayloadNs += time.Since(payloadStart).Nanoseconds() + st.addPayload(time.Since(payloadStart).Nanoseconds()) } prepareStart = time.Now() for _, u := range uploads { diff --git a/seaweed-block/core/storage/chunk_precopy.go b/seaweed-block/core/storage/chunk_precopy.go index 5d9a1d037c..c3f03d9a1d 100644 --- a/seaweed-block/core/storage/chunk_precopy.go +++ b/seaweed-block/core/storage/chunk_precopy.go @@ -453,6 +453,13 @@ func precopyFixedPartsFromSample(s precopySample) PrecopyFixedParts { // every 0.5 ms). It lowers the rate of an upload measured faster than that. const precopyPayloadClockFloor = time.Millisecond +// addPayload adds one payload interval (d nanoseconds as measured) to the +// cut's payload time, and to its tick-floored sum. +func (st *chunkCutStats) addPayload(d int64) { + st.PayloadNs += d + st.payloadFloorNs += max(d, int64(precopyPayloadClockFloor)) +} + func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { // A no-op root read is not a measurement of final CAS + confirmation. if st.CASNs <= 0 { @@ -466,10 +473,12 @@ func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { s := precopySample{at: time.Now(), fixed: time.Duration(max(int64(1), fixedNs))} s.parts = precopyFixedParts(st, s.fixed) if st.UploadedBytes > 0 { - // An upload can also end below the clock's resolution (its payload - // time reads zero): its rate is taken at the resolution, a lower - // bound, so a fast round is never a missing or an infinite sample. - s.rate = float64(st.UploadedBytes) / max(time.Duration(st.PayloadNs), precopyPayloadClockFloor).Seconds() + // Each payload interval can end below the clock's resolution (and + // read zero): the rate divides by the intervals each counted at least + // one tick, a lower bound, so a fast round is never a missing or an + // overstated sample. + div := max(time.Duration(st.payloadFloorNs), time.Duration(st.PayloadNs), precopyPayloadClockFloor) + s.rate = float64(st.UploadedBytes) / div.Seconds() } l.precopySamples = append(l.precopySamples, s) if len(l.precopySamples) > 32 { diff --git a/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go index 0367b129a7..cd73bb31bc 100644 --- a/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go +++ b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go @@ -27,3 +27,32 @@ func TestPrecopyRateSampleAtTheClocksResolution(t *testing.T) { t.Fatalf("the clock floor %s is outside any clock's resolution", precopyPayloadClockFloor) } } + +// The payload time sums several intervals (staging, the copy, the upload). +// Three intervals that each ended below the clock's resolution read zero +// although together they took up to three ticks: the rate divides by three +// ticks, never one, so it stays a lower bound. An interval longer than a +// tick counts as measured. +func TestPrecopyRateFloorsEachPayloadInterval(t *testing.T) { + const bytes = 1 << 20 + var st chunkCutStats + st.CASNs, st.CASResult, st.UploadedBytes = 5, "ok", bytes + for i := 0; i < 3; i++ { + st.addPayload(0) // a sub-tick interval, read as zero + } + l := &chunkLayerImpl{} + l.samplePrecopy(st, 1000) + if most := bytes / (3 * precopyPayloadClockFloor).Seconds(); l.precopySamples[0].rate > most+1 { + t.Fatalf("three sub-tick intervals gave rate %.0f B/s, want at most %.0f (bytes over three ticks)", l.precopySamples[0].rate, most) + } + var measured chunkCutStats + measured.CASNs, measured.CASResult, measured.UploadedBytes = 5, "ok", bytes + measured.addPayload(int64(5 * time.Millisecond)) + l.samplePrecopy(measured, 1000) + if want := bytes / (5 * time.Millisecond).Seconds(); l.precopySamples[1].rate < want-1 || l.precopySamples[1].rate > want+1 { + t.Fatalf("a measured 5 ms interval gave rate %.0f B/s, want %.0f", l.precopySamples[1].rate, want) + } + if measured.PayloadNs != int64(5*time.Millisecond) || st.PayloadNs != 0 { + t.Fatalf("the reported payload time changed: %d and %d", measured.PayloadNs, st.PayloadNs) + } +} diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index dc02640da8..ba12327c37 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -422,6 +422,11 @@ type chunkCutStats struct { NonPayloadCopyNs int64 PayloadNs int64 // disjoint streaming/copy/upload wall intervals + // payloadFloorNs is PayloadNs with each interval counted at least one + // clock tick (precopyPayloadClockFloor): an interval that ended below + // the clock's resolution reads zero, so the rate a sample takes from + // PayloadNs would be too high. Only the pre-copy rate reads it. + payloadFloorNs int64 // Local validated WAL attempts and local copy duration, including savers. COWWALReadAttempts uint64 From a6d1f4d93bd198602511ef0926d5eb94f643bc56 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Tue, 1 Dec 2026 18:06:22 -0800 Subject: [PATCH 3/3] storage: keep the floored payload sum out of the cut statistics The tick-floored payload sum was an unexported field of ChunkCutStats, so the layer statistics grew a field the cut body does not mirror (the mirror test counts every field). The cut now keeps the sum locally and hands it to samplePrecopy; ChunkCutStats is unchanged from main. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/storage/chunk_layer.go | 15 +++++++++++---- seaweed-block/core/storage/chunk_precopy.go | 17 +++++++++-------- .../chunk_precopy_cold_estimator_test.go | 6 +++--- .../storage/chunk_precopy_fixed_commit_test.go | 6 +++--- .../storage/chunk_precopy_rate_floor_test.go | 13 +++++++------ .../storage/chunk_precopy_sample_bound_test.go | 2 +- seaweed-block/core/storage/chunk_seam.go | 5 ----- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index fe23c15049..cb1cf4ed23 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -1133,6 +1133,13 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch start := time.Now() recoveredPublication := l.pending != nil var st chunkCutStats + // payloadFloor is the cut's payload intervals each floored at a clock + // tick, for the pre-copy rate only (st.PayloadNs stays as measured). + var payloadFloor int64 + addPayload := func(d int64) { + st.PayloadNs += d + payloadFloor += flooredPayload(d) + } work := &cutAttemptObservation{} ctx = context.WithValue(ctx, cutObservationKey{}, work) persistCapturedMap := func(versions map[uint64]uint64) { @@ -1179,7 +1186,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch res.Stats = st if !pauseStart.IsZero() { fixed := time.Since(pauseStart).Nanoseconds() - st.PayloadNs + payloadBeforeBarrier - l.samplePrecopy(st, fixed) + l.samplePrecopy(st, fixed, payloadFloor) } res.CandidateTail = l.estimateCandidateTail(tailBytes) } @@ -1266,7 +1273,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if !guestFrozen { staged, err = l.stage(ctx, &st, spill.bytes) } - st.addPayload(time.Since(stageStart).Nanoseconds()) + addPayload(time.Since(stageStart).Nanoseconds()) if err != nil { return chunkCutResult{}, err } @@ -1450,7 +1457,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.CopyNs = time.Since(copyStart).Nanoseconds() if st.UploadedBytes > bytesBeforeCopy { - st.addPayload(st.CopyNs) + addPayload(st.CopyNs) } else { st.NonPayloadCopyNs += st.CopyNs } @@ -1533,7 +1540,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch return chunkCutResult{}, fmt.Errorf("storage: capture upload: %w", errors.Join(errChunkRemoteUnavailable, errCutUpload, err)) } if len(uploads) > 0 { - st.addPayload(time.Since(payloadStart).Nanoseconds()) + addPayload(time.Since(payloadStart).Nanoseconds()) } prepareStart = time.Now() for _, u := range uploads { diff --git a/seaweed-block/core/storage/chunk_precopy.go b/seaweed-block/core/storage/chunk_precopy.go index c3f03d9a1d..a55ffda7f9 100644 --- a/seaweed-block/core/storage/chunk_precopy.go +++ b/seaweed-block/core/storage/chunk_precopy.go @@ -453,14 +453,15 @@ func precopyFixedPartsFromSample(s precopySample) PrecopyFixedParts { // every 0.5 ms). It lowers the rate of an upload measured faster than that. const precopyPayloadClockFloor = time.Millisecond -// addPayload adds one payload interval (d nanoseconds as measured) to the -// cut's payload time, and to its tick-floored sum. -func (st *chunkCutStats) addPayload(d int64) { - st.PayloadNs += d - st.payloadFloorNs += max(d, int64(precopyPayloadClockFloor)) -} +// flooredPayload is one payload interval (d nanoseconds as measured) counted +// at least one clock tick: an interval that ended below the clock's +// resolution reads zero, so a rate taken from the raw sum would be too high. +func flooredPayload(d int64) int64 { return max(d, int64(precopyPayloadClockFloor)) } -func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { +// samplePrecopy records one cut's pre-copy sample. payloadFloorNs is the +// cut's payload intervals each floored (flooredPayload), which the rate +// divides by; st.PayloadNs stays the measured sum the cut reports. +func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs, payloadFloorNs int64) { // A no-op root read is not a measurement of final CAS + confirmation. if st.CASNs <= 0 { if st.CASNs != 0 || (st.CASResult != "ok" && st.CASResult != "resolved-by-reread") { @@ -477,7 +478,7 @@ func (l *chunkLayerImpl) samplePrecopy(st chunkCutStats, fixedNs int64) { // read zero): the rate divides by the intervals each counted at least // one tick, a lower bound, so a fast round is never a missing or an // overstated sample. - div := max(time.Duration(st.payloadFloorNs), time.Duration(st.PayloadNs), precopyPayloadClockFloor) + div := max(time.Duration(payloadFloorNs), time.Duration(st.PayloadNs), precopyPayloadClockFloor) s.rate = float64(st.UploadedBytes) / div.Seconds() } l.precopySamples = append(l.precopySamples, s) diff --git a/seaweed-block/core/storage/chunk_precopy_cold_estimator_test.go b/seaweed-block/core/storage/chunk_precopy_cold_estimator_test.go index 6dfa04fcf0..894bab1150 100644 --- a/seaweed-block/core/storage/chunk_precopy_cold_estimator_test.go +++ b/seaweed-block/core/storage/chunk_precopy_cold_estimator_test.go @@ -70,12 +70,12 @@ func TestPrecopyColdNonemptyTailUsesFirstMeasuredRound(t *testing.T) { func TestPrecopySuccessfulCASBelowClockResolutionIsMeasured(t *testing.T) { layer := &chunkLayerImpl{} st := chunkCutStats{CASResult: "ok", CASNs: 0, UploadedBytes: ctChunkBytes, PayloadNs: int64(10 * time.Millisecond)} - layer.samplePrecopy(st, int64(20*time.Millisecond)) + layer.samplePrecopy(st, int64(20*time.Millisecond), 0) if len(layer.precopySamples) != 1 || layer.precopySamples[0].rate <= 0 { t.Fatalf("successful zero-ns CAS lost its measured upload: %+v", layer.precopySamples) } - layer.samplePrecopy(chunkCutStats{CASNs: 0, UploadedBytes: ctChunkBytes, PayloadNs: st.PayloadNs}, st.PayloadNs) - layer.samplePrecopy(chunkCutStats{CASResult: "precondition", CASNs: 0, UploadedBytes: ctChunkBytes, PayloadNs: st.PayloadNs}, st.PayloadNs) + layer.samplePrecopy(chunkCutStats{CASNs: 0, UploadedBytes: ctChunkBytes, PayloadNs: st.PayloadNs}, st.PayloadNs, 0) + layer.samplePrecopy(chunkCutStats{CASResult: "precondition", CASNs: 0, UploadedBytes: ctChunkBytes, PayloadNs: st.PayloadNs}, st.PayloadNs, 0) if len(layer.precopySamples) != 1 { t.Fatalf("no-op or refused CAS became a sample: %+v", layer.precopySamples) } diff --git a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go index 53d4b89ac8..2b692cf1e2 100644 --- a/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go +++ b/seaweed-block/core/storage/chunk_precopy_fixed_commit_test.go @@ -112,11 +112,11 @@ func TestPrecopyFixedPartsStayWithLargestObservation(t *testing.T) { _, _, l, _ := precopyLayer(t, 1024, 0) l.precopySamples = nil for i := 0; i < 3; i++ { - l.samplePrecopy(chunkCutStats{CASNs: 1}, int64(time.Millisecond)) + l.samplePrecopy(chunkCutStats{CASNs: 1}, int64(time.Millisecond), 0) } st := chunkCutStats{CASNs: 1, DrainNs: int64(10 * time.Millisecond), LockWaitNs: int64(30 * time.Millisecond), SyncNs: int64(40 * time.Millisecond), CASWriteNs: int64(50 * time.Millisecond), HeadReadbackNs: int64(60 * time.Millisecond), MapPersistNs: int64(10 * time.Millisecond)} - l.samplePrecopy(st, int64(200*time.Millisecond)) - l.samplePrecopy(chunkCutStats{CASNs: 1, SyncNs: int64(100 * time.Millisecond)}, int64(150*time.Millisecond)) + l.samplePrecopy(st, int64(200*time.Millisecond), 0) + l.samplePrecopy(chunkCutStats{CASNs: 1, SyncNs: int64(100 * time.Millisecond)}, int64(150*time.Millisecond), 0) r := l.precopyEstimate(0, 0) p := r.FixedParts if r.Fixed != 200*time.Millisecond || p.Drain != 10*time.Millisecond || p.StoreLock != 20*time.Millisecond || p.DataSync != 40*time.Millisecond || p.HeadCAS != 50*time.Millisecond || p.HeadReadback != 60*time.Millisecond || p.MapPersist != 10*time.Millisecond || p.Other != 10*time.Millisecond { diff --git a/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go index cd73bb31bc..09b386b4d3 100644 --- a/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go +++ b/seaweed-block/core/storage/chunk_precopy_rate_floor_test.go @@ -11,7 +11,7 @@ import ( // round that uploaded nothing gives no rate, as before. func TestPrecopyRateSampleAtTheClocksResolution(t *testing.T) { l := &chunkLayerImpl{} - l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 16384, PayloadNs: 0}, 1000) + l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 16384, PayloadNs: 0}, 1000, 0) if len(l.precopySamples) != 1 { t.Fatalf("%d samples, want 1", len(l.precopySamples)) } @@ -19,7 +19,7 @@ func TestPrecopyRateSampleAtTheClocksResolution(t *testing.T) { if most := 16384 / precopyPayloadClockFloor.Seconds(); rate <= 0 || rate > most { t.Fatalf("a sub-resolution upload's rate is %.0f B/s, want above 0 and at most %.0f (its bytes over the clock's resolution)", rate, most) } - l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 0, PayloadNs: 0}, 1000) + l.samplePrecopy(chunkCutStats{CASNs: 5, CASResult: "ok", UploadedBytes: 0, PayloadNs: 0}, 1000, 0) if r := l.precopySamples[1].rate; r != 0 { t.Fatalf("a round that uploaded nothing gave rate %.0f, want none", r) } @@ -37,18 +37,19 @@ func TestPrecopyRateFloorsEachPayloadInterval(t *testing.T) { const bytes = 1 << 20 var st chunkCutStats st.CASNs, st.CASResult, st.UploadedBytes = 5, "ok", bytes + var floor int64 for i := 0; i < 3; i++ { - st.addPayload(0) // a sub-tick interval, read as zero + floor += flooredPayload(0) // a sub-tick interval, read as zero } l := &chunkLayerImpl{} - l.samplePrecopy(st, 1000) + l.samplePrecopy(st, 1000, floor) if most := bytes / (3 * precopyPayloadClockFloor).Seconds(); l.precopySamples[0].rate > most+1 { t.Fatalf("three sub-tick intervals gave rate %.0f B/s, want at most %.0f (bytes over three ticks)", l.precopySamples[0].rate, most) } var measured chunkCutStats measured.CASNs, measured.CASResult, measured.UploadedBytes = 5, "ok", bytes - measured.addPayload(int64(5 * time.Millisecond)) - l.samplePrecopy(measured, 1000) + measured.PayloadNs = int64(5 * time.Millisecond) + l.samplePrecopy(measured, 1000, flooredPayload(measured.PayloadNs)) if want := bytes / (5 * time.Millisecond).Seconds(); l.precopySamples[1].rate < want-1 || l.precopySamples[1].rate > want+1 { t.Fatalf("a measured 5 ms interval gave rate %.0f B/s, want %.0f", l.precopySamples[1].rate, want) } diff --git a/seaweed-block/core/storage/chunk_precopy_sample_bound_test.go b/seaweed-block/core/storage/chunk_precopy_sample_bound_test.go index 5be9c0093f..bd87e33ae4 100644 --- a/seaweed-block/core/storage/chunk_precopy_sample_bound_test.go +++ b/seaweed-block/core/storage/chunk_precopy_sample_bound_test.go @@ -12,7 +12,7 @@ func TestPrecopySampleHistoryKeepsNewest32(t *testing.T) { const taken = 40 for i := 1; i <= taken; i++ { // The fixed cost carries the sample's order. - l.samplePrecopy(chunkCutStats{CASNs: 1}, int64(i)) + l.samplePrecopy(chunkCutStats{CASNs: 1}, int64(i), 0) } if len(l.precopySamples) != 32 { t.Fatalf("sample history holds %d entries, want 32", len(l.precopySamples)) diff --git a/seaweed-block/core/storage/chunk_seam.go b/seaweed-block/core/storage/chunk_seam.go index ba12327c37..dc02640da8 100644 --- a/seaweed-block/core/storage/chunk_seam.go +++ b/seaweed-block/core/storage/chunk_seam.go @@ -422,11 +422,6 @@ type chunkCutStats struct { NonPayloadCopyNs int64 PayloadNs int64 // disjoint streaming/copy/upload wall intervals - // payloadFloorNs is PayloadNs with each interval counted at least one - // clock tick (precopyPayloadClockFloor): an interval that ended below - // the clock's resolution reads zero, so the rate a sample takes from - // PayloadNs would be too high. Only the pre-copy rate reads it. - payloadFloorNs int64 // Local validated WAL attempts and local copy duration, including savers. COWWALReadAttempts uint64