mirror of
https://github.com/superseriousbusiness/gotosocial
synced 2024-12-26 20:53:10 +00:00
acc333c40b
When GTS is running in a container runtime which has configured CPU or memory limits or under an init system that uses cgroups to impose CPU and memory limits the values the Go runtime sees for GOMAXPROCS and GOMEMLIMIT are still based on the host resources, not the cgroup. At least for the throttling middlewares which use GOMAXPROCS to configure their queue size, this can result in GTS running with values too big compared to the resources that will actuall be available to it. This introduces 2 dependencies which can pick up resource contraints from the current cgroup and tune the Go runtime accordingly. This should result in the different queues being appropriately sized and in general more predictable performance. These dependencies are a no-op on non-Linux systems or if running in a cgroup that doesn't set a limit on CPU or memory. The automatic tuning of GOMEMLIMIT can be disabled by either explicitly setting GOMEMLIMIT yourself or by setting AUTOMEMLIMIT=off. The automatic tuning of GOMAXPROCS can similarly be counteracted by setting GOMAXPROCS yourself.
89 lines
2.7 KiB
Go
89 lines
2.7 KiB
Go
package dbus
|
|
|
|
import (
|
|
"strconv"
|
|
"strings"
|
|
)
|
|
|
|
// MatchOption specifies option for dbus routing match rule. Options can be constructed with WithMatch* helpers.
|
|
// For full list of available options consult
|
|
// https://dbus.freedesktop.org/doc/dbus-specification.html#message-bus-routing-match-rules
|
|
type MatchOption struct {
|
|
key string
|
|
value string
|
|
}
|
|
|
|
func formatMatchOptions(options []MatchOption) string {
|
|
items := make([]string, 0, len(options))
|
|
for _, option := range options {
|
|
items = append(items, option.key+"='"+option.value+"'")
|
|
}
|
|
return strings.Join(items, ",")
|
|
}
|
|
|
|
// WithMatchOption creates match option with given key and value
|
|
func WithMatchOption(key, value string) MatchOption {
|
|
return MatchOption{key, value}
|
|
}
|
|
|
|
// doesn't make sense to export this option because clients can only
|
|
// subscribe to messages with signal type.
|
|
func withMatchType(typ string) MatchOption {
|
|
return WithMatchOption("type", typ)
|
|
}
|
|
|
|
// WithMatchSender sets sender match option.
|
|
func WithMatchSender(sender string) MatchOption {
|
|
return WithMatchOption("sender", sender)
|
|
}
|
|
|
|
// WithMatchSender sets interface match option.
|
|
func WithMatchInterface(iface string) MatchOption {
|
|
return WithMatchOption("interface", iface)
|
|
}
|
|
|
|
// WithMatchMember sets member match option.
|
|
func WithMatchMember(member string) MatchOption {
|
|
return WithMatchOption("member", member)
|
|
}
|
|
|
|
// WithMatchObjectPath creates match option that filters events based on given path
|
|
func WithMatchObjectPath(path ObjectPath) MatchOption {
|
|
return WithMatchOption("path", string(path))
|
|
}
|
|
|
|
// WithMatchPathNamespace sets path_namespace match option.
|
|
func WithMatchPathNamespace(namespace ObjectPath) MatchOption {
|
|
return WithMatchOption("path_namespace", string(namespace))
|
|
}
|
|
|
|
// WithMatchDestination sets destination match option.
|
|
func WithMatchDestination(destination string) MatchOption {
|
|
return WithMatchOption("destination", destination)
|
|
}
|
|
|
|
// WithMatchArg sets argN match option, range of N is 0 to 63.
|
|
func WithMatchArg(argIdx int, value string) MatchOption {
|
|
if argIdx < 0 || argIdx > 63 {
|
|
panic("range of argument index is 0 to 63")
|
|
}
|
|
return WithMatchOption("arg"+strconv.Itoa(argIdx), value)
|
|
}
|
|
|
|
// WithMatchArgPath sets argN path match option, range of N is 0 to 63.
|
|
func WithMatchArgPath(argIdx int, path string) MatchOption {
|
|
if argIdx < 0 || argIdx > 63 {
|
|
panic("range of argument index is 0 to 63")
|
|
}
|
|
return WithMatchOption("arg"+strconv.Itoa(argIdx)+"path", path)
|
|
}
|
|
|
|
// WithMatchArg0Namespace sets arg0namespace match option.
|
|
func WithMatchArg0Namespace(arg0Namespace string) MatchOption {
|
|
return WithMatchOption("arg0namespace", arg0Namespace)
|
|
}
|
|
|
|
// WithMatchEavesdrop sets eavesdrop match option.
|
|
func WithMatchEavesdrop(eavesdrop bool) MatchOption {
|
|
return WithMatchOption("eavesdrop", strconv.FormatBool(eavesdrop))
|
|
}
|