-
Notifications
You must be signed in to change notification settings - Fork 456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dbnode] Add process limits validation (and docs) #1118
Changes from all commits
0038132
6a4f3ce
f3ce416
b67dc9a
6334edb
8b9be43
84f708d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Kernel Configuration | ||
==================== | ||
|
||
This document lists the Kernel tweaks M3DB needs to run well. | ||
|
||
## vm.max_map_count | ||
M3DB uses a lot of mmap-ed files for performance, as a result, you might need to bump `vm.max_map_count`. We suggest setting this value to `262144`, so you don’t have to come back and debug issues later. | ||
|
||
On Linux, you can increase the limits by running the following command as root: | ||
``` | ||
sysctl -w vm.max_map_count=262144 | ||
``` | ||
|
||
To set this value permanently, update the `vm.max_map_count` setting in `/etc/sysctl.conf`. | ||
|
||
## vm.swappiness | ||
`vm.swappiness` controls how much the virtual memory subsystem will try to swap to disk. By default, the kernel configures this value to `60`, and will try to swap out items in memory even when there is plenty of RAM available to the system. | ||
|
||
We recommend sizing clusters such that M3DB is running on a substrate (hosts/containers) such that no-swapping is necessary, i.e. the process is only using 30-50% of the maximum available memory. And therefore recommend setting the value of `vm.swappiness` to `1`. This tells the kernel to swap as little as possible, without altogether disabling swapping. | ||
|
||
On Linux, you can configure this by running the following as root: | ||
``` | ||
sysctl -w vm.swappiness=1 | ||
``` | ||
|
||
To set this value permanently, update the `vm.swappiness` setting in `/etc/sysctl.conf`. | ||
|
||
|
||
## rlimits | ||
M3DB also can use a high number of files and we suggest setting a high max open number of files due to per partition fileset volumes. | ||
|
||
On Linux you can set a high limit for maximum number of open files in `/etc/security/limits.conf`: | ||
``` | ||
your_m3db_user hard nofile 500000 | ||
your_m3db_user soft nofile 500000 | ||
``` | ||
|
||
Alternatively, if you wish to have M3DB run under `systemd` you can use our [service example](https://github.com/m3db/m3/tree/master/integrations/systemd/m3dbnode.service) which will set sane defaults. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh ok I see it is here. Can any of the other values go in there? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. naw the rest of it is specific to systemd |
||
|
||
Before running the process make sure the limits are set, if running manually you can raise the limit for the current user with `ulimit -n 500000`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package server | ||
|
||
import ( | ||
"fmt" | ||
|
||
xos "github.com/m3db/m3/src/x/os" | ||
xerror "github.com/m3db/m3x/errors" | ||
) | ||
|
||
const ( | ||
// TODO: determine these values based on topology/namespace configuration. | ||
minNoFile = 500000 | ||
minVMMapCount = 262144 | ||
maxSwappiness = 1 | ||
) | ||
|
||
func validateProcessLimits() error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we were gonna emit these log messages at regular intervals as well if they were misconfigured? Seems like a long-lived struct with an internal goroutine that might be useful There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
limits, err := xos.GetProcessLimits() | ||
if err != nil { | ||
return fmt.Errorf("unable to determine process limits: %v", err) | ||
} | ||
|
||
var multiErr xerror.MultiError | ||
if limits.NoFileCurr < minNoFile { | ||
multiErr = multiErr.Add(fmt.Errorf( | ||
"current value for RLIMIT_NOFILE(%d) is below recommended threshold(%d)", | ||
limits.NoFileCurr, minNoFile, | ||
)) | ||
} | ||
|
||
if limits.NoFileMax < minNoFile { | ||
multiErr = multiErr.Add(fmt.Errorf( | ||
"max value for RLIMIT_NOFILE(%d) is below recommended threshold(%d)", | ||
limits.NoFileMax, minNoFile, | ||
)) | ||
} | ||
|
||
if limits.VMMaxMapCount < minVMMapCount { | ||
multiErr = multiErr.Add(fmt.Errorf( | ||
"current value for vm.max_map_count(%d) is below recommended threshold(%d)", | ||
limits.VMMaxMapCount, minVMMapCount, | ||
)) | ||
} | ||
|
||
if limits.VMSwappiness > maxSwappiness { | ||
multiErr = multiErr.Add(fmt.Errorf( | ||
"current value for vm.swappiness(%d) is above recommended threshold(%d)", | ||
limits.VMSwappiness, maxSwappiness, | ||
)) | ||
} | ||
|
||
return multiErr.FinalError() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,6 +65,7 @@ import ( | |
"github.com/m3db/m3/src/dbnode/ts" | ||
"github.com/m3db/m3/src/dbnode/x/tchannel" | ||
"github.com/m3db/m3/src/dbnode/x/xio" | ||
xdocs "github.com/m3db/m3/src/x/docs" | ||
"github.com/m3db/m3/src/x/mmap" | ||
"github.com/m3db/m3/src/x/serialize" | ||
xconfig "github.com/m3db/m3x/config" | ||
|
@@ -81,8 +82,10 @@ import ( | |
) | ||
|
||
const ( | ||
bootstrapConfigInitTimeout = 10 * time.Second | ||
serverGracefulCloseTimeout = 10 * time.Second | ||
bootstrapConfigInitTimeout = 10 * time.Second | ||
serverGracefulCloseTimeout = 10 * time.Second | ||
bgProcessLimitInterval = 10 * time.Second | ||
maxBgProcessLimitMonitorDuration = 5 * time.Minute | ||
) | ||
|
||
// RunOptions provides options for running the server | ||
|
@@ -134,6 +137,7 @@ func Run(runOpts RunOptions) { | |
os.Exit(1) | ||
} | ||
|
||
go bgValidateProcessLimits(logger) | ||
debug.SetGCPercent(cfg.GCPercentage) | ||
|
||
scope, _, err := cfg.Metrics.NewRootScope() | ||
|
@@ -632,6 +636,29 @@ func interrupt() <-chan os.Signal { | |
return c | ||
} | ||
|
||
func bgValidateProcessLimits(logger xlog.Logger) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is annoying, but should we add a signal to stop this goroutine at some point? Just because if we start using this more in integration tests having a dangling goroutine may become annoying to deal with. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. talked offline: added max monitor duration to control this |
||
start := time.Now() | ||
t := time.NewTicker(bgProcessLimitInterval) | ||
defer t.Stop() | ||
for { | ||
// only monitor for first `maxBgProcessLimitMonitorDuration` of process lifetime | ||
if time.Since(start) > maxBgProcessLimitMonitorDuration { | ||
return | ||
} | ||
|
||
err := validateProcessLimits() | ||
if err == nil { | ||
return | ||
} | ||
|
||
logger.WithFields( | ||
xlog.NewField("url", xdocs.Path("operational_guide/kernel_configuration")), | ||
).Warnf(`invalid configuration found [%v], refer to linked documentation for more information`, err) | ||
|
||
<-t.C | ||
} | ||
} | ||
|
||
func kvWatchNewSeriesLimitPerShard( | ||
store kv.Store, | ||
logger xlog.Logger, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package docs | ||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
// Path returns the url to the given section of documentation. | ||
func Path(section string) string { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lol nice |
||
return fmt.Sprintf("https://m3db.github.io/m3/%s", section) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package xos | ||
|
||
// ProcessLimits captures the different process limits. | ||
type ProcessLimits struct { | ||
NoFileCurr uint64 // RLIMIT_NOFILE Current | ||
NoFileMax uint64 // RLIMIT_NOFILE Max | ||
VMMaxMapCount int64 // corresponds to /proc/sys/vm/max_map_count | ||
VMSwappiness int64 // corresponds to /proc/sys/vm/swappiness | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package xos | ||
|
||
import ( | ||
"fmt" | ||
"io/ioutil" | ||
"strconv" | ||
"strings" | ||
"syscall" | ||
) | ||
|
||
const ( | ||
sysctlDir = "/proc/sys/" | ||
vmMaxMapCountKey = "vm.max_map_count" | ||
vmSwappinessKey = "vm.swappiness" | ||
) | ||
|
||
// GetProcessLimits returns the known process limits. | ||
func GetProcessLimits() (ProcessLimits, error) { | ||
var noFile syscall.Rlimit | ||
err := syscall.Getrlimit(syscall.RLIMIT_NOFILE, &noFile) | ||
if err != nil { | ||
return ProcessLimits{}, err | ||
} | ||
|
||
maxMap, err := sysctlInt64(vmMaxMapCountKey) | ||
if err != nil { | ||
return ProcessLimits{}, err | ||
} | ||
|
||
swap, err := sysctlInt64(vmSwappinessKey) | ||
if err != nil { | ||
return ProcessLimits{}, err | ||
} | ||
|
||
return ProcessLimits{ | ||
NoFileCurr: noFile.Cur, | ||
NoFileMax: noFile.Max, | ||
VMMaxMapCount: maxMap, | ||
VMSwappiness: swap, | ||
}, nil | ||
} | ||
|
||
func sysctlInt64(key string) (int64, error) { | ||
str, err := sysctl(key) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
num, err := strconv.Atoi(str) | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return int64(num), nil | ||
} | ||
|
||
func sysctl(key string) (string, error) { | ||
path := sysctlDir + strings.Replace(key, ".", "/", -1) | ||
data, err := ioutil.ReadFile(path) | ||
if err != nil { | ||
return "", fmt.Errorf("could not find the given sysctl file: %v, err: %v", path, err) | ||
} | ||
return strings.TrimSpace(string(data)), nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build !linux | ||
// | ||
// Copyright (c) 2018 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package xos | ||
|
||
import "errors" | ||
|
||
var ( | ||
errUnableToDetermineProcessLimits = errors.New("unable to determine process limits on non-linux os") | ||
) | ||
|
||
// GetProcessLimits returns the known process limits. | ||
func GetProcessLimits() (ProcessLimits, error) { | ||
return ProcessLimits{}, errUnableToDetermineProcessLimits | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doc: https://github.com/m3db/m3/blob/cece4eae36f72767fe107b5ce1e015d9ac9548dd/docs/how_to/cluster_hard_way.md
references this file:
https://github.com/m3db/m3/blob/master/integrations/systemd/m3dbnode.service
Do we need to add any of these other configs in there?