3 files changed,
+46
−4
internal/console/opstore_test.go
+3 −4
internal/console/scalecost_linux_test.go
+30 −0
internal/console/scalecost_other_test.go
+13 −0
| index 1126775e4..dec2bdb71 100644 |
| --- a/internal/console/opstore_test.go |
| +++ b/internal/console/opstore_test.go |
| @@ -890,13 +890,12 @@ func TestOperatorCountsAtScale(t *testing.T) { |
| // 102.5 ms against 100), so one run measures the worker, not the query. |
| const scaleTimingRuns = 5 |
| |
| -// bestOfScaleRuns runs run scaleTimingRuns times and returns the fastest. |
| +// bestOfScaleRuns runs run scaleTimingRuns times and returns the fastest, |
| +// each timed by scaleCost. |
| func bestOfScaleRuns(run func()) time.Duration { |
| var best time.Duration |
| for i := 0; i < scaleTimingRuns; i++ { |
| - start := time.Now() |
| - run() |
| - if took := time.Since(start); i == 0 || took < best { |
| + if took := scaleCost(run); i == 0 || took < best { |
| best = took |
| } |
| } |
| new file mode 100644 |
| index 000000000..126da6b0c |
| --- /dev/null |
| +++ b/internal/console/scalecost_linux_test.go |
| @@ -0,0 +1,30 @@ |
| +package console |
| + |
| +import ( |
| + "runtime" |
| + "time" |
| + |
| + "golang.org/x/sys/unix" |
| +) |
| + |
| +// scaleCost is the CPU time run takes on its own OS thread. A scale |
| +// query's budget is what the query costs, and the gate runs many test |
| +// processes side by side, so on a saturated CI worker even the best of |
| +// several wall-clock runs measured the scheduler: OperatorCounts' reads |
| +// came to 183 ms against 150 on CI and 54 ms on an idle machine (#897). |
| +// The thread's CPU clock leaves out the time the thread waited to run. |
| +func scaleCost(run func()) time.Duration { |
| + runtime.LockOSThread() |
| + defer runtime.UnlockOSThread() |
| + var before, after unix.Timespec |
| + if unix.ClockGettime(unix.CLOCK_THREAD_CPUTIME_ID, &before) != nil { |
| + start := time.Now() |
| + run() |
| + return time.Since(start) |
| + } |
| + run() |
| + if unix.ClockGettime(unix.CLOCK_THREAD_CPUTIME_ID, &after) != nil { |
| + panic("CLOCK_THREAD_CPUTIME_ID failed after succeeding") |
| + } |
| + return time.Duration(after.Nano() - before.Nano()) |
| +} |
| new file mode 100644 |
| index 000000000..7ca54d1aa |
| --- /dev/null |
| +++ b/internal/console/scalecost_other_test.go |
| @@ -0,0 +1,13 @@ |
| +//go:build !linux |
| + |
| +package console |
| + |
| +import "time" |
| + |
| +// scaleCost is wall-clock time where there is no per-thread CPU clock; |
| +// the budgets are enforced on CI, which is Linux. |
| +func scaleCost(run func()) time.Duration { |
| + start := time.Now() |
| + run() |
| + return time.Since(start) |
| +} |