-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Added upstream zone directive annotation #629
Conversation
@vrrs thanks for the PR! We'll review it shortly |
@vrrs I wonder though if it makes sense to have a configmap key Additionally, having zones enabled by default also makes sense, so that the mentioned benefits are enabled by default. The default size of Let me know what you think. |
@pleshakov Our use case requires individual resources to specify max_conn and zone since our ingress nginx is shared. Different set of upstream servers might require different zone sizes In summary, We should add a configmap key along with the annotation defaulted to 0 which will enable both use cases of having all ingresses with one zone(using configmap key) or having individual ingresses with specific zones(with annotation). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In addition, this change is backward compatible. We have already deployments without upstream zone and adding a default zone might have an impact on performance.
Thanks for thinking about backward compatibility! However, we do not expect any significant impact on performance. At the same time, we will document this change in the release notes appropriately, so that during upgrade people can set the configmap key to 0
to disable zones.
In summary, We should add a configmap key along with the annotation defaulted to 0 which will enable both use cases of having all ingresses with one zone(using configmap key) or having individual ingresses with specific zones(with annotation).
Sounds good! Just a small note -- the annotation should default to the ConfigMap key.
If you could make the default 256K
and treat 0
as a special value to turn off the zones (both for the configmap key and the annotation), that be great!
I added suggestions about the doc (which assumes the configmap key, the default and the special value to turn off zones) and a small consistency suggestion for the template.
@@ -2,6 +2,7 @@ | |||
|
|||
{{range $upstream := .Upstreams}} | |||
upstream {{$upstream.Name}} { | |||
{{if $upstream.UpstreamZoneSize }}zone {{$upstream.Name}} {{$upstream.UpstreamZoneSize}};{{end}} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{{if $upstream.UpstreamZoneSize }}zone {{$upstream.Name}} {{$upstream.UpstreamZoneSize}};{{end}} | |
{{if $upstream.UpstreamZoneSize}}zone {{$upstream.Name}} {{$upstream.UpstreamZoneSize}};{{end}} |
@pleshakov Performed the changes |
@Rulox @Dean-Coakley 👀 👀 --^ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Lgtm once: #629 (comment) is applied. Looks like it was missed.
docs/configmap-and-annotations.md
Outdated
@@ -166,6 +166,7 @@ spec: | |||
| `nginx.org/websocket-services` | N/A | Enables WebSocket for services. | N/A | [WebSocket support](../examples/websocket). | | |||
| `nginx.org/max-fails` | `max-fails` | Sets the value of the [max_fails](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_fails) parameter of the `server` directive. | `1` | | | |||
| `nginx.org/max-conns` | N\A | Sets the value of the [max_conns](https://nginx.org/en/docs/http/ngx_http_upstream_module.html#max_conns) parameter of the `server` directive. | `0` | | | |||
| `nginx.org/upstream-zone-size` | N\A | Sets the size of the shared memory [zone](https://nginx.org/en/docs/http/ngx_http_upstream_module.html?#zone). If this annotation is not present then the zone directive will not be set. | `N\A` | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like you missed #629 (comment) unless I'm mistaken?
internal/configs/config_params.go
Outdated
@@ -109,6 +110,7 @@ func NewDefaultConfigParams() *ConfigParams { | |||
SSLPorts: []int{443}, | |||
MaxFails: 1, | |||
MaxConns: 0, | |||
UpstreamZoneSize: "256k", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this is missing a run of gofmt
, not gonna block the pr for it, but would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
go fmt
should be run for consistency before merging
@Dean-Coakley Modified the documentation. |
@vrrs The format of config_params.go still isn't quite right. |
Ohh i see, check now @Dean-Coakley |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect! Thanks @vrrs
@vrrs Looks great, just 2 small things before I can merge:
Both changes are just to follow the rules and consistency with the rest of the code/repo. Once that's done I will merge it, thanks again for your time! |
|
👍 |
Proposed changes
These changes enable the zone directive on upstream block with upstream name equal to zone name and zone size equals to the annotation value. This follow the same convention as nginx-plus ingress config. For instance,
nginx.org/upstream-zone-size: "32k"
in your ingress.yaml will generate a config such asIf the annotation is not present then the zone directive will not be present on the config.
Nginx Documentation for upstream zone
Motivation
In multi worker nginx setup(worker_processes > 1), the zone directive fixes the least_conn lb method as well as max_fails, max_conns parameters. From the nginx document on load balancing:
Use case
A properly working least_conn load balancer is very useful in balancing long lived connections and limiting load on the destination servers; particularly when upstream servers are streaming web apps.
Checklist
Before creating a PR, run through this checklist and mark each as complete.