Skip to content

Commit

Permalink
agent: Change monitor queue size default
Browse files Browse the repository at this point in the history
The existing default of 0.5M entries for the buffered go channel wastes a lot
of of memory in smaller environments. Reduce it to 32K and allow to customize
it for bigger environments via --monitor-queue-size=INT

Signed-off-by: Thomas Graf <thomas@cilium.io>
  • Loading branch information
tgraf committed Dec 18, 2018
1 parent 4868cae commit fdf644b
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions Documentation/cmdref/cilium-agent.md
Expand Up @@ -78,6 +78,7 @@ cilium-agent
--logstash-probe-timer uint32 Logstash probe timer (seconds) (default 10)
--masquerade Masquerade packets from endpoints leaving the host (default true)
--monitor-aggregation string Level of monitor aggregation for traces from the datapath (default "None")
--monitor-queue-size int Size of the event queue when reading monitor events (default 32768)
--mtu int Overwrite auto-detected MTU of underlying network (default 1500)
--nat46-range string IPv6 prefix to map IPv4 addresses to (default "0:0:0:0:0:FFFF::/96")
--pprof Enable serving the pprof debugging API
Expand Down
1 change: 1 addition & 0 deletions daemon/config.go
Expand Up @@ -49,4 +49,5 @@ func populateConfig() {
option.Config.K8sNamespace = viper.GetString(option.K8sNamespaceName)
option.Config.EnableIPv4 = getIPv4Enabled()
option.Config.EnableIPv6 = viper.GetBool(option.EnableIPv6Name)
option.Config.MonitorQueueSize = viper.GetInt(option.MonitorQueueSizeName)
}
2 changes: 1 addition & 1 deletion daemon/daemon.go
Expand Up @@ -859,7 +859,7 @@ func NewDaemon() (*Daemon, *endpointRestoreState, error) {
k8sSvcCache: k8s.NewServiceCache(),
policy: policy.NewPolicyRepository(),
uniqueID: map[uint64]context.CancelFunc{},
nodeMonitor: monitorLaunch.NewNodeMonitor(),
nodeMonitor: monitorLaunch.NewNodeMonitor(option.Config.MonitorQueueSize),
prefixLengths: createPrefixLengthCounter(),

buildEndpointSem: semaphore.NewWeighted(int64(numWorkerThreads())),
Expand Down
3 changes: 3 additions & 0 deletions daemon/daemon_main.go
Expand Up @@ -474,6 +474,9 @@ func init() {
flags.String(option.MonitorAggregationName, "None",
"Level of monitor aggregation for traces from the datapath")
viper.BindEnv(option.MonitorAggregationName, "CILIUM_MONITOR_AGGREGATION_LEVEL")
flags.Int(option.MonitorQueueSizeName, defaults.MonitorQueueSize,
"Size of the event queue when reading monitor events")
viper.BindEnv(option.MonitorQueueSizeName, option.MonitorQueueSizeNameEnv)
flags.IntVar(&option.Config.MTU,
option.MTUName, mtu.AutoDetect(), "Overwrite auto-detected MTU of underlying network")
flags.Bool(option.PrependIptablesChainsName, true, "Prepend custom iptables chains instead of appending")
Expand Down
5 changes: 1 addition & 4 deletions monitor/launch/launcher.go
Expand Up @@ -38,9 +38,6 @@ var log = logging.DefaultLogger.WithField(logfields.LogSubsys, "monitor-launcher

const (
targetName = "cilium-node-monitor"

// queueSize is the size of the message queue
queueSize = 524288
)

// NodeMonitor is used to wrap the node executable binary.
Expand All @@ -59,7 +56,7 @@ type NodeMonitor struct {
}

// NewNodeMonitor returns a new node monitor
func NewNodeMonitor() *NodeMonitor {
func NewNodeMonitor(queueSize int) *NodeMonitor {
nm := &NodeMonitor{
queue: make(chan []byte, queueSize),
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/defaults/defaults.go
Expand Up @@ -114,4 +114,7 @@ const (

// EnableIPv6 is the default value for IPv6 enablement
EnableIPv6 = true

// MonitorQueueSize is the default value for the monitor queue size
MonitorQueueSize = 32768
)
7 changes: 7 additions & 0 deletions pkg/option/config.go
Expand Up @@ -166,6 +166,10 @@ const (
// EnableIPv6Name is the name of the option to enable IPv6 support
EnableIPv6Name = "enable-ipv6"
EnableIPv6NameEnv = "CILIUM_ENABLE_IPV6"

// MonitorQueueSizeName is the name of the option MonitorQueueSize
MonitorQueueSizeName = "monitor-queue-size"
MonitorQueueSizeNameEnv = "CILIUM_MONITOR_QUEUE_SIZE"
)

// Available option for daemonConfig.Tunnel
Expand Down Expand Up @@ -375,6 +379,9 @@ type daemonConfig struct {

// EnableIPv6 is true when IPv6 is enabled
EnableIPv6 bool

// MonitorQueueSize is the size of the monitor event queue
MonitorQueueSize int
}

var (
Expand Down

0 comments on commit fdf644b

Please sign in to comment.