cmd/bench: wait for load average to drop before starting
The coordinator runs tests on a freshly booted VM which may still be
running background boot tasks when bench starts.
For minimal noise, wait for the system load average to drop (indicating
background tasks have completed) before continuing with benchmarking.
For golang/go#49207.
Change-Id: I8df01592fea31d49eae54074213e202b21d5728a
Reviewed-on: https://go-review.googlesource.com/c/benchmarks/+/362375
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Pratt <mpratt@google.com>
Run-TryBot: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
diff --git a/cmd/bench/main.go b/cmd/bench/main.go
index 67d0d8b..7a3863b 100644
--- a/cmd/bench/main.go
+++ b/cmd/bench/main.go
@@ -10,6 +10,7 @@
package main
import (
+ "flag"
"fmt"
"log"
"os"
@@ -18,6 +19,8 @@
"strings"
)
+var wait = flag.Bool("wait", true, "wait for system idle before starting benchmarking")
+
func determineGOROOT() (string, error) {
g, ok := os.LookupEnv("GOROOT")
if ok {
@@ -60,6 +63,16 @@
}
func main() {
+ flag.Parse()
+
+ if *wait {
+ // We may be on a freshly booted VM. Wait for boot tasks to
+ // complete before continuing.
+ if err := waitForIdle(); err != nil {
+ log.Fatalf("Failed to wait for idle: %v", err)
+ }
+ }
+
goroot, err := determineGOROOT()
if err != nil {
log.Fatalf("Unable to determine GOROOT: %v", err)