-
Notifications
You must be signed in to change notification settings - Fork 435
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
Add cgroups v2 support to resourcemanager #1744
Changes from 1 commit
5c1d6c7
0009f06
232ded2
42a4693
7146e9e
bace811
33f6343
89acabd
a007e25
325566f
56a6f11
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 |
---|---|---|
|
@@ -23,6 +23,7 @@ var ( | |
limitCheckDurationHistogram = metrics.NewRegisteredHistogram("arb/rpc/limitcheck/duration", nil, metrics.NewBoundedHistogramSample()) | ||
limitCheckSuccessCounter = metrics.NewRegisteredCounter("arb/rpc/limitcheck/success", nil) | ||
limitCheckFailureCounter = metrics.NewRegisteredCounter("arb/rpc/limitcheck/failure", nil) | ||
errNotSupported = errors.New("not supported") | ||
) | ||
|
||
// Init adds the resource manager's httpServer to a custom hook in geth. | ||
|
@@ -33,7 +34,15 @@ var ( | |
func Init(conf *Config) { | ||
if conf.MemoryLimitPercent > 0 { | ||
node.WrapHTTPHandler = func(srv http.Handler) (http.Handler, error) { | ||
return newHttpServer(srv, newLimitChecker(conf)), nil | ||
var c limitChecker | ||
var err error | ||
c, err = newCgroupsMemoryLimitCheckerIfSupported(conf) | ||
if errors.Is(err, errNotSupported) { | ||
log.Error("No method for determining memory usage and limits was discovered, disabled memory limit RPC throttling") | ||
c = &trivialLimitChecker{} | ||
} | ||
|
||
return newHttpServer(srv, c), nil | ||
} | ||
} | ||
} | ||
|
@@ -95,25 +104,22 @@ func isSupported(c limitChecker) bool { | |
return err == nil | ||
} | ||
|
||
// newLimitChecker attempts to auto-discover the mechanism by which it | ||
// can check system limits. Currently Cgroups V1 and V2 are supported. | ||
// If no supported mechanism is discovered, it logs an error and | ||
// fails open, ie it creates a trivialLimitChecker that does no checks. | ||
func newLimitChecker(conf *Config) limitChecker { | ||
// newCgroupsMemoryLimitCheckerIfSupported attempts to auto-discover whether | ||
// Cgroups V1 or V2 is supported for checking system memory limits. | ||
func newCgroupsMemoryLimitCheckerIfSupported(conf *Config) (*cgroupsMemoryLimitChecker, 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. nit: go tends to encourage shorter names. You can drop "IfSupported" suffix and just add in the comment above the function that this returns errNotSupported if it's not supported. 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'm not sure what to rename it to since |
||
c := newCgroupsMemoryLimitChecker(cgroupsV1MemoryFiles, conf.MemoryLimitPercent) | ||
if isSupported(c) { | ||
log.Info("Cgroups v1 detected, enabling memory limit RPC throttling") | ||
return c | ||
return c, nil | ||
} | ||
|
||
c = newCgroupsMemoryLimitChecker(cgroupsV2MemoryFiles, conf.MemoryLimitPercent) | ||
if isSupported(c) { | ||
log.Info("Cgroups v2 detected, enabling memory limit RPC throttling") | ||
return c | ||
return c, nil | ||
} | ||
|
||
log.Error("No method for determining memory usage and limits was discovered, disabled memory limit RPC throttling") | ||
return &trivialLimitChecker{} | ||
return nil, errNotSupported | ||
} | ||
|
||
// trivialLimitChecker checks no limits, so its limits are never exceeded. | ||
|
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.
nit: any reason why not just c,err := ... ; and drop declaration of those variables (two lines above this one) ?
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.
I wanted to have c be of the
limitChecker
interface type so I can assign thetrivialLimitChecker
to it. I moved the declarationerr
into the same line as the limit checker creation.