blob: 0cfa88108467017d8a9bb62dd0f4a5e945c453e0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
// Author: arnej
package util
import (
"os"
"strconv"
"strings"
"github.com/vespa-engine/vespa/client/go/internal/admin/envvars"
"github.com/vespa-engine/vespa/client/go/internal/admin/trace"
)
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.")
}
os.Setenv(envvars.VESPA_TIMER_HZ, "100")
}
}
}
func TuneResourceLimits() {
var numfiles uint64 = 262144
var numprocs uint64 = 409600
if env := os.Getenv(envvars.FILE_DESCRIPTOR_LIMIT); env != "" {
n, err := strconv.Atoi(env)
if err != nil {
numfiles = uint64(n)
}
}
if env := os.Getenv(envvars.NUM_PROCESSES_LIMIT); env != "" {
n, err := strconv.Atoi(env)
if err != nil {
numprocs = uint64(n)
}
}
SetResourceLimit(RLIMIT_CORE, NO_RLIMIT)
SetResourceLimit(RLIMIT_NOFILE, numfiles)
SetResourceLimit(RLIMIT_NPROC, numprocs)
}
|