From cbd520a6fbb4affdaff53863487b7b4445b11a46 Mon Sep 17 00:00:00 2001 From: Xuefeng Chen Date: Tue, 9 Jul 2024 11:32:46 -0700 Subject: [PATCH] MINOR: support thread pin on frontend/status --- pkg/controller/controller.go | 8 ++++--- pkg/controller/handler.go | 18 +++++++++------- pkg/handler/http-bind.go | 42 +++++++++++++++++++++++++----------- pkg/utils/flags.go | 3 +++ 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index 670d2dd1..96439b35 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -225,7 +225,8 @@ func (c *HAProxyController) setToReady() { return c.haproxy.FrontendBindCreate("healthz", models.Bind{ BindParams: models.BindParams{ - Name: "v4", + Name: "v4", + Thread: c.osArgs.HealthzBindThread, }, Address: fmt.Sprintf("0.0.0.0:%d", healthzPort), }) @@ -235,8 +236,9 @@ func (c *HAProxyController) setToReady() { return c.haproxy.FrontendBindCreate("healthz", models.Bind{ BindParams: models.BindParams{ - Name: "v6", - V4v6: true, + Name: "v6", + V4v6: true, + Thread: c.osArgs.HealthzBindThread, }, Address: fmt.Sprintf(":::%d", healthzPort), }) diff --git a/pkg/controller/handler.go b/pkg/controller/handler.go index 928b8440..372e404b 100644 --- a/pkg/controller/handler.go +++ b/pkg/controller/handler.go @@ -96,14 +96,16 @@ func (c *HAProxyController) startupHandlers() error { handlers := []UpdateHandler{ handler.GlobalCfg{}, handler.HTTPBind{ - HTTP: !c.osArgs.DisableHTTP, - HTTPS: !c.osArgs.DisableHTTPS, - IPv4: !c.osArgs.DisableIPV4, - IPv6: !c.osArgs.DisableIPV6, - HTTPPort: c.osArgs.HTTPBindPort, - HTTPSPort: c.osArgs.HTTPSBindPort, - IPv4Addr: c.osArgs.IPV4BindAddr, - IPv6Addr: c.osArgs.IPV6BindAddr, + HTTP: !c.osArgs.DisableHTTP, + HTTPS: !c.osArgs.DisableHTTPS, + IPv4: !c.osArgs.DisableIPV4, + IPv6: !c.osArgs.DisableIPV6, + HTTPPort: c.osArgs.HTTPBindPort, + HTTPSPort: c.osArgs.HTTPSBindPort, + IPv4Addr: c.osArgs.IPV4BindAddr, + IPv6Addr: c.osArgs.IPV6BindAddr, + HTTPBindThread: c.osArgs.HTTPBindThread, + HTTPSBindThread: c.osArgs.HTTPSBindThread, }, } diff --git a/pkg/handler/http-bind.go b/pkg/handler/http-bind.go index 04d75e6b..2f841b12 100644 --- a/pkg/handler/http-bind.go +++ b/pkg/handler/http-bind.go @@ -25,25 +25,38 @@ import ( ) type HTTPBind struct { - IPv4Addr string - IPv6Addr string - HTTPPort int64 - HTTPSPort int64 - HTTP bool - HTTPS bool - IPv4 bool - IPv6 bool + IPv4Addr string + IPv6Addr string + HTTPPort int64 + HTTPSPort int64 + HTTP bool + HTTPS bool + IPv4 bool + IPv6 bool + HTTPBindThread string + HTTPSBindThread string +} + +type PortAndThread struct { + Port int64 + Thread string } func (handler HTTPBind) Update(k store.K8s, h haproxy.HAProxy, a annotations.Annotations) (err error) { var errors utils.Errors - frontends := make(map[string]int64, 2) + frontends := make(map[string]PortAndThread, 2) protos := make(map[string]string, 2) if handler.HTTP { - frontends[h.FrontHTTP] = handler.HTTPPort + frontends[h.FrontHTTP] = PortAndThread{ + Port: handler.HTTPPort, + Thread: handler.HTTPBindThread, + } } if handler.HTTPS { - frontends[h.FrontHTTPS] = handler.HTTPSPort + frontends[h.FrontHTTPS] = PortAndThread{ + Port: handler.HTTPSPort, + Thread: handler.HTTPSBindThread, + } } if handler.IPv4 { protos["v4"] = handler.IPv4Addr @@ -61,11 +74,14 @@ func (handler HTTPBind) Update(k store.K8s, h haproxy.HAProxy, a annotations.Ann Address: ":::1024", })) } - for ftName, ftPort := range frontends { + for ftName, ftPortAndThread := range frontends { + ftPort := ftPortAndThread.Port + thread := ftPortAndThread.Thread for proto, addr := range protos { bind := models.Bind{ BindParams: models.BindParams{ - Name: proto, + Name: proto, + Thread: thread, }, Address: addr, Port: utils.PtrInt64(ftPort), diff --git a/pkg/utils/flags.go b/pkg/utils/flags.go index 7aea083d..7e71370b 100644 --- a/pkg/utils/flags.go +++ b/pkg/utils/flags.go @@ -92,9 +92,12 @@ type OSArgs struct { ControllerPort int `long:"controller-port" description:"port to listen on for controller data: prometheus, pprof" default:"6060"` HTTPBindPort int64 `long:"http-bind-port" default:"8080" description:"port to listen on for HTTP traffic"` HTTPSBindPort int64 `long:"https-bind-port" default:"8443" description:"port to listen on for HTTPS traffic"` + HTTPBindThread string `long:"http-bind-thread" description:"default http service bind thread params eg: 1-1" default:""` + HTTPSBindThread string `long:"https-bind-thread" description:"default https service bind thread params eg: 1-1" default:""` SyncPeriod time.Duration `long:"sync-period" default:"5s" description:"Sets the period at which the controller syncs HAProxy configuration file"` CacheResyncPeriod time.Duration `long:"cache-resync-period" default:"10m" description:"Sets the underlying Shared Informer resync period: resyncing controller with informers cache"` HealthzBindPort int64 `long:"healthz-bind-port" default:"1042" description:"port to listen on for probes"` + HealthzBindThread string `long:"healthz-bind-thread" description:"default healthz service bind thread params eg: 1-1" default:""` LogLevel LogLevelValue `long:"log" default:"info" description:"level of log messages you can see"` DisableIPV4 bool `long:"disable-ipv4" description:"toggle to disable the IPv4 protocol from all frontends"` External bool `short:"e" long:"external" description:"use as external Ingress Controller (out of k8s cluster)"`