summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorMartin Polden <mpolden@mpolden.no>2023-11-22 10:18:38 +0100
committerMartin Polden <mpolden@mpolden.no>2023-11-22 10:19:26 +0100
commit2416c1698a5262abbe66c7201e1f9bb90d4947cd (patch)
treeddc768e769e94f04eca19f4669e3efe5dfabdbed /client
parente8c0a04b67b632ea3f98327d8f39cd0293ad8581 (diff)
Reduce timer frequency when QEMU virtualization is used
Diffstat (limited to 'client')
-rw-r--r--client/go/internal/util/tuning.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/client/go/internal/util/tuning.go b/client/go/internal/util/tuning.go
index b36c0a431da..cca314247ab 100644
--- a/client/go/internal/util/tuning.go
+++ b/client/go/internal/util/tuning.go
@@ -15,19 +15,29 @@ import (
func OptionallyReduceTimerFrequency() {
if os.Getenv(envvars.VESPA_TIMER_HZ) == "" {
backticks := BackTicksIgnoreStderr
- out, _ := backticks.Run("uname", "-r")
- if strings.Contains(out, "linuxkit") {
- if os.Getenv(envvars.VESPA_TIMER_HZ) != "100" {
- trace.Trace(
- "Running docker on macos.",
- "Reducing base frequency from 1000hz to 100hz due to high cost of sampling time.",
- "This will reduce timeout accuracy.")
+ uname, _ := backticks.Run("uname", "-r")
+ if strings.Contains(uname, "linuxkit") {
+ setTimerHZ("Docker on macOS detected.", "100")
+ } else {
+ virt, _ := backticks.Run("systemd-detect-virt", "--vm")
+ if strings.TrimSpace(virt) == "qemu" {
+ setTimerHZ("QEMU virtualization detected.", "100")
}
- os.Setenv(envvars.VESPA_TIMER_HZ, "100")
}
}
}
+func setTimerHZ(description, timerHZ string) {
+ if os.Getenv(envvars.VESPA_TIMER_HZ) == timerHZ {
+ return
+ }
+ trace.Trace(
+ description,
+ "Reducing base frequency from 1000hz to "+timerHZ+"hz due to high cost of sampling time.",
+ "This will reduce timeout accuracy.")
+ os.Setenv(envvars.VESPA_TIMER_HZ, timerHZ)
+}
+
func TuneResourceLimits() {
var numfiles uint64 = 262144
var numprocs uint64 = 409600