Skip to content
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

Allow overriding CPU Map #588

Merged
merged 1 commit into from
May 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs/content/en/docs/configuration/keys.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ The table below describes all supported configuration keys.
| [`cors-enable`](#cors) | [true\|false] | Backend | |
| [`cors-expose-headers`](#cors) | headers | Backend | |
| [`cors-max-age`](#cors) | time (seconds) | Backend | |
| [`cpu-map`](#cpu-map) | haproxy CPU Map format | Global | |
| [`dns-accepted-payload-size`](#dns-resolvers) | number | Global | `8192` |
| [`dns-cluster-domain`](#dns-resolvers) | cluster name | Global | `cluster.local` |
| [`dns-hold-obsolete`](#dns-resolvers) | time with suffix | Global | `0s` |
Expand Down Expand Up @@ -236,6 +237,7 @@ The table below describes all supported configuration keys.
| [`timeout-tunnel`](#timeout) | time with suffix | Backend | `1h` |
| [`tls-alpn`](#tls-alpn) | TLS ALPN advertisement | Global | `h2,http/1.1` |
| [`use-chroot`](#security) | [true\|false] | Global | `false` |
| [`use-cpu-map`](#cpu-map) | [true\|false] | Global | `true` |
| [`use-forwarded-proto`](#fronting-proxy-port) | [true\|false] | Global | `true` |
| [`use-haproxy-user`](#security) | [true\|false] | Global | `false` |
| [`use-htx`](#use-htx) | [true\|false] | Global | `false` |
Expand Down Expand Up @@ -1203,6 +1205,7 @@ If splitting HAProxy into two or more process and the number of threads is one,
See also:

* [nbthread](#nbthread) configuration key
* [cpu-map](#cpu-map) configuration key
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-nbproc
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#4-bind-process
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-cpu-map
Expand All @@ -1224,11 +1227,34 @@ bind each thread on its own CPU core.

See also:

* [cpu-map](#cpu-map) configuration key
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-nbthread
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-cpu-map

---

## cpu-map

| Configuration key | Scope | Default | Since |
|-------------------|----------|---------|-------|
| `use-cpu-map` | `Global` | `true` | |
| `cpu-map` | `Global` | | |


Define how processes/threads map to CPUs. The default value is generated based
on [nbthread](#nbthread) and [nbproc](#nbproc).

* `use-cpu-map`: Set to `false` to prevent any cpu mapping
* `cpu-map`: Custom override specifying the cpu mapping behaviour in the format described [here](https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-cpu-map).

See also:

* [nbthread](#nbthread) configuration key
* [nbproc](#nbproc) configuration key
* https://cbonte.github.io/haproxy-dconv/2.0/configuration.html#3.1-cpu-map

---

## OAuth

| Configuration key | Scope | Default | Since |
Expand Down
16 changes: 11 additions & 5 deletions pkg/converters/ingress/annotations/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,19 @@ func (c *updater) buildGlobalProc(d *globalData) {
} else if ssl > 1 {
bindprocSSL = fmt.Sprintf("%v-%v", balance+1, procs)
}
useCpuMap := d.mapper.Get(ingtypes.GlobalUseCpuMap).Bool()
cpumap := ""
if threads > 1 {
if procs == 1 {
cpumap = fmt.Sprintf("auto:1/1-%v 0-%v", threads, threads-1)
if useCpuMap {
cpumap = d.mapper.Get(ingtypes.GlobalCpuMap).Value
if cpumap == "" {
if threads > 1 {
if procs == 1 {
cpumap = fmt.Sprintf("auto:1/1-%v 0-%v", threads, threads-1)
}
} else if procs > 1 {
cpumap = fmt.Sprintf("auto:1-%v 0-%v", procs, procs-1)
}
}
} else if procs > 1 {
cpumap = fmt.Sprintf("auto:1-%v 0-%v", procs, procs-1)
}
d.global.Procs.Nbproc = procs
d.global.Procs.Nbthread = threads
Expand Down
53 changes: 53 additions & 0 deletions pkg/converters/ingress/annotations/global_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,3 +330,56 @@ func TestFrontingProxy(t *testing.T) {
c.teardown()
}
}

func TestDisableCpuMap(t *testing.T) {
testCases := []struct {
ann map[string]string
expected string
}{
// 0
{
ann: map[string]string{
ingtypes.GlobalUseCpuMap: "false",
ingtypes.GlobalNbthread: "1",
ingtypes.GlobalNbprocBalance: "1",
},
expected: "",
},
// 1
{
ann: map[string]string{
ingtypes.GlobalUseCpuMap: "false",
ingtypes.GlobalCpuMap: "auto 1/1 1-",
ingtypes.GlobalNbthread: "1",
ingtypes.GlobalNbprocBalance: "1",
},
expected: "",
},
// 2
{
ann: map[string]string{
ingtypes.GlobalUseCpuMap: "true",
ingtypes.GlobalCpuMap: "auto:1/1 1-",
ingtypes.GlobalNbthread: "4",
ingtypes.GlobalNbprocBalance: "1",
},
expected: "auto:1/1 1-",
},
// 3
{
ann: map[string]string{
ingtypes.GlobalUseCpuMap: "true",
ingtypes.GlobalNbthread: "2",
ingtypes.GlobalNbprocBalance: "1",
},
expected: "auto:1/1-2 0-1",
},
}
for i, test := range testCases {
c := setup(t)
d := c.createGlobalData(test.ann)
c.createUpdater().buildGlobalProc(d)
c.compareObjects("cpu map", i, d.global.Procs.CPUMap, test.expected)
c.teardown()
}
}
1 change: 1 addition & 0 deletions pkg/converters/ingress/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func createDefaults() map[string]string {
types.GlobalTimeoutClientFin: "50s",
types.GlobalTimeoutStop: "10m",
types.GlobalTLSALPN: "h2,http/1.1",
types.GlobalUseCpuMap: "true",
types.GlobalUseForwardedProto: "true",
types.GlobalUseHTX: "true",
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/converters/ingress/types/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const (
GlobalConfigFrontend = "config-frontend"
GlobalConfigGlobal = "config-global"
GlobalCookieKey = "cookie-key"
GlobalCpuMap = "cpu-map"
GlobalDNSAcceptedPayloadSize = "dns-accepted-payload-size"
GlobalDNSClusterDomain = "dns-cluster-domain"
GlobalDNSHoldObsolete = "dns-hold-obsolete"
Expand Down Expand Up @@ -88,6 +89,7 @@ const (
GlobalTimeoutStop = "timeout-stop"
GlobalTLSALPN = "tls-alpn"
GlobalUseChroot = "use-chroot"
GlobalUseCpuMap = "use-cpu-map"
GlobalUseForwardedProto = "use-forwarded-proto"
GlobalUseHAProxyUser = "use-haproxy-user"
GlobalUseHTX = "use-htx"
Expand Down