mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 18:47:20 +01:00
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 <noreply@anthropic.com>
This commit is contained in:
1 parent
578827ff1e
commit
10cbe8a5b0
2 files changed
+39
-2
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user