Skip to content

Commit d96b3f0

Browse files
authored
Add a flag to enable or disable aio_write (#10394)
* Add a flag to enable or disable aio_write Signed-off-by: z1cheng <[email protected]> * Fix e2e test for aio_write Signed-off-by: z1cheng <[email protected]> * Remove redundant spaces to fix the 2e test Signed-off-by: z1cheng <[email protected]> --------- Signed-off-by: z1cheng <[email protected]>
1 parent ac2923b commit d96b3f0

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

docs/user-guide/nginx-configuration/configmap.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ The following table shows a configuration option's name, type, and the default v
9797
|[ssl-buffer-size](#ssl-buffer-size)|string|"4k"||
9898
|[use-proxy-protocol](#use-proxy-protocol)|bool|"false"||
9999
|[proxy-protocol-header-timeout](#proxy-protocol-header-timeout)|string|"5s"||
100+
|[enable-aio-write](#enable-aio-write)|bool|"true"||
100101
|[use-gzip](#use-gzip)|bool|"false"||
101102
|[use-geoip](#use-geoip)|bool|"true"||
102103
|[use-geoip2](#use-geoip2)|bool|"false"||
@@ -709,6 +710,10 @@ Enables or disables the [PROXY protocol](https://www.nginx.com/resources/admin-g
709710
Sets the timeout value for receiving the proxy-protocol headers. The default of 5 seconds prevents the TLS passthrough handler from waiting indefinitely on a dropped connection.
710711
_**default:**_ 5s
711712

713+
## enable-aio-write
714+
715+
Enables or disables the directive [aio_write](https://nginx.org/en/docs/http/ngx_http_core_module.html#aio_write) that writes files asynchronously. _**default:**_ true
716+
712717
## use-gzip
713718

714719
Enables or disables compression of HTTP responses using the ["gzip" module](https://nginx.org/en/docs/http/ngx_http_gzip_module.html). MIME types to compress are controlled by [gzip-types](#gzip-types). _**default:**_ false

internal/ingress/controller/config/config.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,10 @@ type Configuration struct {
424424
// Example '60s'
425425
ProxyProtocolHeaderTimeout time.Duration `json:"proxy-protocol-header-timeout,omitempty"`
426426

427+
// Enables or disables the directive aio_write that writes files files asynchronously
428+
// https://nginx.org/en/docs/http/ngx_http_core_module.html#aio_write
429+
EnableAioWrite bool `json:"enable-aio-write,omitempty"`
430+
427431
// Enables or disables the use of the nginx module that compresses responses using the "gzip" method
428432
// http://nginx.org/en/docs/http/ngx_http_gzip_module.html
429433
UseGzip bool `json:"use-gzip,omitempty"`
@@ -938,6 +942,7 @@ func NewDefault() Configuration {
938942
SSLSessionTickets: false,
939943
SSLSessionTimeout: sslSessionTimeout,
940944
EnableBrotli: false,
945+
EnableAioWrite: true,
941946
UseGzip: false,
942947
UseGeoIP: true,
943948
UseGeoIP2: false,

rootfs/etc/nginx/template/nginx.tmpl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,10 @@ http {
296296
{{ end }}
297297

298298
aio threads;
299+
300+
{{ if $cfg.EnableAioWrite }}
299301
aio_write on;
302+
{{ end }}
300303

301304
tcp_nopush on;
302305
tcp_nodelay on;

test/e2e/settings/aio_write.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package settings
18+
19+
import (
20+
"strings"
21+
22+
"github.com/onsi/ginkgo/v2"
23+
24+
"k8s.io/ingress-nginx/test/e2e/framework"
25+
)
26+
27+
var _ = framework.DescribeSetting("aio-write", func() {
28+
f := framework.NewDefaultFramework("aio-write")
29+
30+
ginkgo.It("should be enabled by default", func() {
31+
f.WaitForNginxConfiguration(
32+
func(cfg string) bool {
33+
return strings.Contains(cfg, "aio_write on")
34+
})
35+
})
36+
37+
ginkgo.It("should be enabled when setting is true", func() {
38+
f.UpdateNginxConfigMapData("enable-aio-write", "true")
39+
40+
f.WaitForNginxConfiguration(
41+
func(cfg string) bool {
42+
return strings.Contains(cfg, "aio_write on")
43+
})
44+
})
45+
46+
ginkgo.It("should be disabled when setting is false", func() {
47+
f.UpdateNginxConfigMapData("enable-aio-write", "false")
48+
49+
f.WaitForNginxConfiguration(
50+
func(cfg string) bool {
51+
return !strings.Contains(cfg, "aio_write on")
52+
})
53+
})
54+
})

0 commit comments

Comments
 (0)