mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
409e7cb522
commit
a6d1f4d93b
7 files changed
+34
-30
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in new issue
Block a user