Skip to content

Commit 2a397db

Browse files
committed
consul/connect: default envoy concurrency to 1
Previously, every Envoy Connect sidecar would spawn as many worker threads as logical CPU cores. That is Envoy's default behavior when `--concurrency` is not explicitly set. Nomad now sets the concurrency flag to 1, which is sensible for the default cpu = 250 Mhz resources allocated for sidecar proxies. The concurrency value can be configured in Client configuration by setting `meta.connect.proxy_concurrency`. Closes #9341
1 parent 6a6547b commit 2a397db

File tree

5 files changed

+66
-35
lines changed

5 files changed

+66
-35
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ IMPROVEMENTS:
3030
* consul: Support Consul namespace (Consul Enterprise) in client configuration. [[GH-8849](https://github.com/hashicorp/nomad/pull/8849)]
3131
* consul/connect: Dynamically select envoy sidecar at runtime [[GH-8945](https://github.com/hashicorp/nomad/pull/8945)]
3232
* consul/connect: Enable setting `datacenter` field on connect upstreams [[GH-8964](https://github.com/hashicorp/nomad/issues/8964)]
33+
* consul/connect: Envoy concurrency now defaults to 1 rather than number of cores [[GH-9341](https://github.com/hashicorp/nomad/issues/9341)]
3334
* csi: Support `nomad volume detach` with previously garbage-collected nodes. [[GH-9057](https://github.com/hashicorp/nomad/issues/9057)]
3435
* csi: Relaxed validation requirements when checking volume capabilities with controller plugins, to accommodate existing plugin behaviors. [[GH-9049](https://github.com/hashicorp/nomad/issues/9049)]
3536
* driver/docker: Upgrade pause container and detect architecture [[GH-8957](https://github.com/hashicorp/nomad/pull/8957)]

client/client.go

+16-4
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,26 @@ const (
9898
allocSyncRetryIntv = 5 * time.Second
9999

100100
// defaultConnectSidecarImage is the image set in the node meta by default
101-
// to be used by Consul Connect sidecar tasks
102-
// Update sidecar_task.html when updating this.
101+
// to be used by Consul Connect sidecar tasks. As of Nomad 1.0, this value
102+
// is only used as a fallback when the version of Consul does not yet support
103+
// dynamic envoy versions.
103104
defaultConnectSidecarImage = "envoyproxy/envoy:v1.11.2@sha256:a7769160c9c1a55bb8d07a3b71ce5d64f72b1f665f10d81aa1581bc3cf850d09"
104105

105106
// defaultConnectGatewayImage is the image set in the node meta by default
106-
// to be used by Consul Connect Gateway tasks.
107+
// to be used by Consul Connect Gateway tasks. As of Nomad 1.0, this value
108+
// is only used as a fallback when the version of Consul does not yet support
109+
// dynamic envoy versions.
107110
defaultConnectGatewayImage = defaultConnectSidecarImage
108111

109112
// defaultConnectLogLevel is the log level set in the node meta by default
110-
// to be used by Consul Connect sidecar tasks
113+
// to be used by Consul Connect sidecar tasks.
111114
defaultConnectLogLevel = "info"
115+
116+
// defaultConnectProxyConcurrency is the default number of worker threads the
117+
// connect sidecar should be configured to use.
118+
//
119+
// https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency
120+
defaultConnectProxyConcurrency = "1"
112121
)
113122

114123
var (
@@ -1403,6 +1412,9 @@ func (c *Client) setupNode() error {
14031412
if _, ok := node.Meta["connect.log_level"]; !ok {
14041413
node.Meta["connect.log_level"] = defaultConnectLogLevel
14051414
}
1415+
if _, ok := node.Meta["connect.proxy_concurrency"]; !ok {
1416+
node.Meta["connect.proxy_concurrency"] = defaultConnectProxyConcurrency
1417+
}
14061418

14071419
return nil
14081420
}

nomad/job_endpoint_hook_connect.go

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ var (
2828
"args": []interface{}{
2929
"-c", structs.EnvoyBootstrapPath,
3030
"-l", "${meta.connect.log_level}",
31+
"--concurrency", "${meta.connect.proxy_concurrency}",
3132
"--disable-hot-restart",
3233
},
3334
}

website/pages/docs/job-specification/sidecar_task.mdx

+34-28
Original file line numberDiff line numberDiff line change
@@ -61,49 +61,54 @@ group service has a [`sidecar_service`][sidecar_service] stanza.
6161
The default sidecar task is equivalent to:
6262

6363
```hcl
64-
sidecar_task {
65-
name = "connect-proxy-<service>"
64+
sidecar_task {
65+
name = "connect-proxy-<service>"
6666
67-
lifecycle {
68-
hook = "prestart"
69-
sidecar = true
70-
}
67+
lifecycle {
68+
hook = "prestart"
69+
sidecar = true
70+
}
7171
72-
driver = "docker"
73-
config {
74-
image = "${meta.connect.sidecar_image}"
75-
args = [
76-
"-c",
77-
"${NOMAD_SECRETS_DIR}/envoy_bootstrap.json",
78-
"-l",
79-
"${meta.connect.log_level}"
80-
]
81-
}
72+
driver = "docker"
73+
config {
74+
image = "${meta.connect.sidecar_image}"
75+
args = [
76+
"-c",
77+
"${NOMAD_SECRETS_DIR}/envoy_bootstrap.json",
78+
"-l",
79+
"${meta.connect.log_level}",
80+
"--concurrency",
81+
"${meta.connect.proxy_concurrency}",
82+
"--disable-hot-restart"
83+
]
84+
}
8285
83-
logs {
84-
max_files = 2
85-
max_file_size = 2 # MB
86-
}
86+
logs {
87+
max_files = 2
88+
max_file_size = 2 # MB
89+
}
8790
88-
resources {
89-
cpu = 250 # MHz
90-
memory = 128 # MB
91-
}
91+
resources {
92+
cpu = 250 # MHz
93+
memory = 128 # MB
94+
}
9295
93-
shutdown_delay = "5s"
94-
}
96+
shutdown_delay = "5s"
97+
}
9598
```
9699

97-
The `meta.connect.sidecar_image` and `meta.connect.log_level` are [_client_
100+
The `meta.connect.sidecar_image`, `meta.connect.log_level`, and
101+
`meta.connect.proxy_concurrency` variables are [_client_
98102
configurable][nodemeta] variables with the following defaults:
99103

100104
- `sidecar_image` - `(string: "envoyproxy/envoy:v${NOMAD_envoy_version}")` - The official
101105
upstream Envoy Docker image, where `${NOMAD_envoy_version}` is resolved automatically
102106
by a query to Consul.
103107
- `log_level` - `(string: "info")` - Envoy sidecar log level. "`debug`" is useful for
104108
debugging Connect related issues.
109+
- `proxy_concurrency` - `(string: "1")` - The number of [worker threads][worker_threads] the Envoy
110+
sidecar will run.
105111

106-
`meta.connect.sidecar_image` can be configured at the job, group, or task level.
107112
Custom images can make use of Consul's preferred Envoy version by making use of
108113
Nomad's version interpolation, e.g.
109114

@@ -169,3 +174,4 @@ The following example configures resources for the sidecar task and other config
169174
[resources]: /docs/job-specification/resources 'Nomad resources Job Specification'
170175
[logs]: /docs/job-specification/logs 'Nomad logs Job Specification'
171176
[nodemeta]: /docs/configuration/client#meta
177+
[worker_threads]: https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency

website/pages/docs/upgrade/upgrade-specific.mdx

+14-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ standard upgrade flow.
1919

2020
### HCL2 for Job specification
2121

22-
Nomad 1.0.0 adopts HCL2 for parsing the job spec. HCL2 extends HCL with more
22+
Nomad v1.0.0 adopts HCL2 for parsing the job spec. HCL2 extends HCL with more
2323
expression and reuse support, but adds some stricter schema for HCL blocks (a.k.a. stanzas). Check [HCL](/docs/job-specification/hcl2) for more details.
2424

2525
### Signal used when stopping Docker tasks
@@ -73,12 +73,12 @@ Nomad. The specific configuration values replaced are:
7373

7474
### Envoy proxy versions
7575

76-
Nomad 1.0.0 changes the behavior around the selection of Envoy version used
76+
Nomad v1.0.0 changes the behavior around the selection of Envoy version used
7777
for Connect sidecar proxies. Previously, Nomad always defaulted to Envoy v1.11.2
7878
if neither the `meta.connect.sidecar_image` parameter or `sidecar_task` stanza
7979
were explicitly configured. Likewise the same version of Envoy would be used for
8080
Connect ingress gateways if `meta.connect.gateway_image` was unset. Starting with
81-
Nomad 1.0.0, each Nomad Client will query Consul for a list of supported Envoy
81+
Nomad v1.0.0, each Nomad Client will query Consul for a list of supported Envoy
8282
versions. Nomad will make use of the latest version of Envoy supported by the
8383
Consul agent when launching Envoy as a Connect sidecar proxy. If the version of
8484
the Consul agent is older than v1.7.8, v1.8.4, or v1.9.0, Nomad will fallback to
@@ -94,6 +94,15 @@ the time of the upgrade for each node will ensure Connect workloads are properly
9494
rescheduled onto nodes in such a way that the Nomad Clients, Consul agents, and
9595
Envoy sidecar tasks maintain compatibility with one another.
9696

97+
### Envoy worker threads
98+
99+
Nomad v1.0.0 changes the default behaviour around the number of worker threads
100+
created by the Envoy sidecar proxy when using Consul Connect. Previously, the
101+
Envoy [`--concurrency`][envoy_concurrency] argument was left unset, which caused
102+
Envoy to spawn as many worker threads as logical cores available on the CPU. The
103+
`--concurrency` value now defaults to `1` and can be configured by setting the
104+
[`meta.connect.proxy_concurrency`][proxy_concurrency] property in client configuration.
105+
97106
## Nomad 0.12.8
98107

99108
### Docker volume mounts
@@ -859,6 +868,7 @@ deleted and then Nomad 0.3.0 can be launched.
859868
[drain-api]: /api-docs/nodes#drain-node
860869
[drain-cli]: /docs/commands/node/drain
861870
[dst]: /docs/job-specification/periodic#daylight-saving-time
871+
[envoy_concurrency]: https://www.envoyproxy.io/docs/envoy/latest/operations/cli#cmdoption-concurrency
862872
[gh-6787]: https://github.com/hashicorp/nomad/issues/6787
863873
[gh-8457]: https://github.com/hashicorp/nomad/issues/8457
864874
[gh-9148]: https://github.com/hashicorp/nomad/issues/9148
@@ -870,6 +880,7 @@ deleted and then Nomad 0.3.0 can be launched.
870880
[plugins]: /docs/drivers/external
871881
[preemption-api]: /api-docs/operator#update-scheduler-configuration
872882
[preemption]: /docs/internals/scheduling/preemption
883+
[proxy_concurrency]: /docs/job-specification/sidecar_task#proxy_concurrency
873884
[reserved]: /docs/configuration/client#reserved-parameters
874885
[task-config]: /docs/job-specification/task#config
875886
[tls-guide]: https://learn.hashicorp.com/tutorials/nomad/security-enable-tls

0 commit comments

Comments
 (0)