Skip to content

Commit

Permalink
Merge pull request #193 from nginxinc/cpu-affinity
Browse files Browse the repository at this point in the history
Add worker-cpu-affinity configmap key
  • Loading branch information
pleshakov authored Oct 2, 2017
2 parents a7d8e30 + b51cbc3 commit 84d7163
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 4 deletions.
1 change: 1 addition & 0 deletions examples/customization/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ The table below summarizes some of the options. More options (extensions) are av
| `nginx.org/listen-ports` | N/A | Configures HTTP ports that NGINX will listen on. | `[80]` |
| `nginx.org/listen-ports-ssl` | N/A | Configures HTTPS ports that NGINX will listen on. | `[443]` |
| N/A | `worker-processes` | Sets the value of the [worker_processes](http://nginx.org/en/docs/ngx_core_module.html#worker_processes) directive. | `auto` |
| N/A | `worker-cpu-affinity` | Sets the value of the [worker_cpu_affinity](http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity) directive. | N/A |

## Using ConfigMaps

Expand Down
1 change: 1 addition & 0 deletions examples/customization/nginx-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ data:
proxy_temp_path /var/nginx/proxy_temp;
charset koi8-r;
worker-processes: "1" # default is "auto". Sets the value of the worker_processes directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_processes
worker-cpu-affinity: "auto" # No default. Sets the value of the worker_cpu_affinity directive. See http://nginx.org/en/docs/ngx_core_module.html#worker_cpu_affinity
3 changes: 3 additions & 0 deletions nginx-controller/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,9 @@ func (lbc *LoadBalancerController) syncCfgm(task Task) {
cfg.MainWorkerProcesses = cfgm.Data["worker-processes"]
}
}
if workerCPUAffinity, exists := cfgm.Data["worker-cpu-affinity"]; exists {
cfg.MainWorkerCPUAffinity = workerCPUAffinity
}
}

var ingExes []*nginx.IngressEx
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type Config struct {
HSTSIncludeSubdomains bool
LBMethod string
MainWorkerProcesses string
MainWorkerCPUAffinity string

// http://nginx.org/en/docs/http/ngx_http_realip_module.html
RealIPHeader string
Expand Down
9 changes: 5 additions & 4 deletions nginx-controller/nginx/configurator.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,10 +663,11 @@ func (cnf *Configurator) UpdateConfig(config *Config, ingExes []*IngressEx) erro
SSLCiphers: config.MainServerSSLCiphers,
SSLDHParam: config.MainServerSSLDHParam,
SSLPreferServerCiphers: config.MainServerSSLPreferServerCiphers,
HTTP2: config.HTTP2,
ServerTokens: config.ServerTokens,
ProxyProtocol: config.ProxyProtocol,
WorkerProcesses: config.MainWorkerProcesses,
HTTP2: config.HTTP2,
ServerTokens: config.ServerTokens,
ProxyProtocol: config.ProxyProtocol,
WorkerProcesses: config.MainWorkerProcesses,
WorkerCPUAffinity: config.MainWorkerCPUAffinity,
}

cnf.nginx.UpdateMainConfigFile(mainCfg)
Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/nginx.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ type NginxMainConfig struct {
ServerTokens string
ProxyProtocol bool
WorkerProcesses string
WorkerCPUAffinity string
}

// NewUpstreamWithDefaultServer creates an upstream with the default server.
Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/templates/nginx-plus.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

user nginx;
worker_processes {{.WorkerProcesses}};
{{- if .WorkerCPUAffinity}}
worker_cpu_affinity {{.WorkerCPUAffinity}};{{end}}

daemon off;

Expand Down
2 changes: 2 additions & 0 deletions nginx-controller/nginx/templates/nginx.tmpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

user nginx;
worker_processes {{.WorkerProcesses}};
{{- if .WorkerCPUAffinity}}
worker_cpu_affinity {{.WorkerCPUAffinity}};{{end}}

daemon off;

Expand Down
1 change: 1 addition & 0 deletions nginx-controller/nginx/templates/templates_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ var mainCfg = nginx.NginxMainConfig{
ServerNamesHashMaxSize: "512",
ServerTokens: "off",
WorkerProcesses: "auto",
WorkerCPUAffinity: "auto",
}

func TestIngressForNGINXPlus(t *testing.T) {
Expand Down

0 comments on commit 84d7163

Please sign in to comment.