You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/nginx_tune/_index.md
+30-13Lines changed: 30 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,21 @@
1
1
---
2
-
title: Learn how to tune Nginx
2
+
title: Tune NGINX performance on Arm-based platforms
3
+
description: Learn how to tune NGINX, Linux network settings, and supporting libraries to improve web server, reverse proxy, and API gateway performance on Arm-based platforms.
3
4
4
5
minutes_to_complete: 60
5
6
6
-
who_is_this_for: This is an advanced topic for software developers who want to use Nginx on Arm.
7
+
who_is_this_for: This Learning Path is for software developers and system administrators who want to optimize NGINX performance on Arm-based platforms.
7
8
8
9
learning_objectives:
9
-
- Describe how kernel parameters can impact Nginx performance.
10
-
- Describe how compilers and libraries can impact Nginx performance.
11
-
- Tune a Nginx file server configuration file.
12
-
- Tune a Nginx Reverse Proxy and API Gateway configuration file.
13
-
- Describe how to test Nginx performance.
10
+
- Configure Linux network settings that affect NGINX connection handling.
11
+
- Tune NGINX directives for static file server, reverse proxy, and API gateway workloads.
12
+
- Evaluate compiler, OpenSSL, PCRE, and zlib choices that can affect NGINX performance.
13
+
- Measure NGINX performance before and after tuning.
14
14
15
15
prerequisites:
16
-
- A cloud or bare-metal installation of a Nginx file server or load balancer.
17
-
- If you do not already have a Nginx setup, a review of [Learn how to deploy Nginx](/learning-paths/servers-and-cloud-computing/nginx/).
16
+
- A cloud or bare-metal installation of an NGINX file server, reverse proxy, or API gateway.
17
+
- A repeatable HTTP workload or load test that you can run before and after tuning.
18
+
- If you do not already have an NGINX setup, review [Learn how to deploy NGINX](/learning-paths/servers-and-cloud-computing/nginx/).
description: Learn how to approach NGINX performance tuning as a measurement-driven process and compare baseline results with tuned results.
3
4
weight: 2
4
5
layout: "learningpathall"
5
6
---
6
7
7
-
## Importance of tuning
8
+
## About performance tuning
8
9
9
-
Application tuning allows you to gain performance without scaling your deployment up (bigger machines/nodes) or out (more machines/nodes). This gained performance can either be used, or traded for cost savings by reducing the amount of compute resources provisioned. The graphs below shows the performance gains of an Nginx file server, Reverse Proxy, and API Gateway when they are tuned.
10
+
Performance tuning is most useful when you treat it as a measurement process, not a fixed checklist. You can tune by changing one parameter at a time, running a designed experiment, comparing profiles, or using automation and AI-assisted tools to explore a larger configuration space.
10
11
11
-

12
+
There isn't a universal set of tuning parameters that works best for every application. The right settings depend on the request profile, response size, TLS configuration, cache behavior, upstream service behavior, network path, software version, system architecture, operating system, and other application-specific factors.
12
13
13
-

14
+
Whatever method you use, keep the measurements repeatable. Record the system configuration, workload, software versions, and tuning parameters so you can identify which changes improved performance and which changes had little effect.
14
15
15
-

16
+
## Why tune NGINX
16
17
17
-
Requirements vary based on the use case. In the example shown above, the AWS m7g.2xlarge instance type could be down sized to a m7g.xlarge to gain cost savings.
18
+
NGINX performance can be limited by connection handling, kernel network settings, TLS processing, file I/O, upstream connection reuse, cache behavior, logging, or regular expression processing. Tuning helps you use the available compute, memory, storage, and network resources more efficiently.
19
+
20
+
Improved performance can give you higher throughput, lower latency, or better cost efficiency. A tuned configuration can increase capacity on the same system, or help you meet the same performance target with fewer compute resources.
21
+
22
+
## Example performance result
23
+
24
+
The following example shows `wrk` throughput before and after tuning for an NGINX API gateway on an Arm Neoverse V3 system. The result is normalized to the out-of-box configuration, so `1.00` represents the baseline.
25
+
26
+

27
+
28
+
This result is an example, not a guaranteed improvement for every workload. Your results depend on the NGINX version, request rate, response size, TLS settings, client concurrency, upstream services, network configuration, and system resources.
Copy file name to clipboardExpand all lines: content/learning-paths/servers-and-cloud-computing/nginx_tune/kernel_comp_lib.md
+47-43Lines changed: 47 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,81 +4,85 @@ weight: 3
4
4
layout: "learningpathall"
5
5
---
6
6
7
-
## Kernel configuration
7
+
## Kernel configuration
8
8
9
-
The profile of requests made by clients will differ based on the use case. This means there is no one size fits all set of tuning parameters for Nginx. Use the information below as general guidance to tune Nginx.
9
+
NGINX tuning doesn't stop at `nginx.conf`. Foundational settings such as kernel network queues, socket buffers, compiler choices, and TLS libraries can affect throughput and latency. Treat these settings as part of the same measurement process you use for NGINX directives.
10
10
11
-
### Linux Network Stack
11
+
### Linux network stack
12
12
13
-
The Linux Network stack settings can be changed in the `/etc/sysctl.conf` file, or by using the `sysctl` command.
13
+
You can change Linux network stack settings in `/etc/sysctl.conf`, or by using the `sysctl` command.
14
14
15
-
Documentation on each of the parameters discussed below can be found in the [admin-guide](https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/net.rst) and [networking](https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.rst) documentation within the Linux source.
15
+
For details about these parameters, see the Linux kernel [sysctl network adminguide](https://github.com/torvalds/linux/blob/master/Documentation/admin-guide/sysctl/net.rst) and [IP sysctl documentation](https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.rst).
16
16
17
-
Run the command below to list all kernel parameters.
17
+
Run the following command to list all kernel parameters:
18
18
19
19
```bash
20
20
sudo sysctl -a
21
21
```
22
22
23
-
Shown below are the network stack settings used for performance testing.
23
+
The following commands show example network settings for high-connection workloads:
These settings open up the network stack to make sure it is not a bottleneck.
35
+
These values are intentionally large. Size them for your expected connection rate, request pattern, and available memory.
36
36
37
37
*`net.core.somaxconn`:
38
-
* This setting is used to select the maximum number of connections the kernel will allow.
39
-
* If the Nginx server is expected to support a large number of clients, it may be helpful to increase this parameter.
40
-
* A value of 65535 is probably excessively large for production. In practice, this just needs to be large enough to support the peak number of connections that will be made.
38
+
* This setting selects the maximum number of queued connections the kernel allows.
39
+
* If the NGINX server needs to support a large number of clients, it can be helpful to increase this parameter.
40
+
* A value of 65535 is likely excessive for many deployments. In practice, this value needs to be large enough to support the peak number of queued connections.
41
41
*`net.core.rmem_max`:
42
-
* This setting is used to set the maximum read socket buffer size.
43
-
*8MB is likely more than enough for most use cases.
44
-
*Socket buffer utilization can be checked with a tool like `ss`(Socket Statistics). The information provided by this tool can be used to select a value for this parameter.
42
+
* This setting selects the maximum read socket buffer size.
43
+
*`8 MiB` is likely more than enough for most use cases.
44
+
*Use a tool such as `ss`to check socket buffer utilization and select a value for this parameter.
45
45
*`net.core.wmem_max`:
46
-
* This setting is used to set the maximum write socket buffer size.
47
-
*8MB is likely more than enough for most use cases.
48
-
*Socket buffer utilization can be checked with a tool like `ss`(Socket Statistics). The information provided by this tool can be used to select a value for this parameter.
46
+
* This setting selects the maximum write socket buffer size.
47
+
*`8 MiB` is likely more than enough for most use cases.
48
+
*Use a tool such as `ss`to check socket buffer utilization and select a value for this parameter.
49
49
*`net.ipv4.tcp_max_syn_backlog`:
50
-
* This setting is used to select the maximum number of connection requests that are pending but not established yet.
51
-
* A value of 65535 is probably excessively large for production. In practice, this just needs to be large enough to support the peak number of connection requests that will be made.
50
+
* This setting selects the maximum number of connection requests that are pending but not established yet.
51
+
* A value of 65535 is likely excessive for many deployments. In practice, this value needs to be large enough to support the peak number of pending connection requests.
52
52
*`net.ipv4.ip_local_port_range`:
53
-
* This setting is used to select the range of ports the kernel can use.
54
-
* The port range is expanded above. Typically the default range is sufficient.
53
+
* This setting selects the range of local ports the kernel can use.
54
+
* The example expands the port range. The default range is sufficient for many deployments.
55
55
*`net.ipv4.tcp_rmem`:
56
-
* This setting is used to set the maximum TCP read socket buffer size.
57
-
*8MB is likely more than enough for most use cases.
58
-
*TCP buffer utilization can be checked with a tool like `ss`(Socket Statistics). The information provided by this tool can be used to select a value for this parameter.
56
+
* This setting selects the TCP read socket buffer size.
57
+
*`8 MiB` is likely more than enough for most use cases.
58
+
*Use a tool such as `ss`to check TCP buffer utilization and select a value for this parameter.
59
59
*`net.ipv4.tcp_wmem`:
60
-
* This setting is used to set the maximum TCP write socket buffer size.
61
-
* 8MB is likely more than enough for most use cases.
62
-
* TCP buffer utilization can be checked with a tool like `ss` (Socket Statistics). The information provided by this tool can be used to select a value for this parameter.
60
+
* This setting selects the TCP write socket buffer size.
61
+
*`8 MiB` is likely more than enough for most use cases.
62
+
* Use a tool such as `ss` to check TCP buffer utilization and select a value for this parameter.
63
+
64
+
## Compiler considerations
65
+
66
+
If you build NGINX from source, the compiler version and optimization flags can affect performance. Use a recent version of GCC, and consider flags such as `-mcpu` and `-flto` for additional optimization. These flags are explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/) Learning Path.
63
67
64
-
## Compiler Considerations
68
+
When you configure an NGINX source build, pass compiler flags with the `--with-cc-opt` option.
65
69
66
-
The easiest way to gain performance is to use the latest version of GCC. Aside from that, the flag `-mcpu` can be used to potentially gain additional performance. Usage of this flag is explained in the [Migrating C/C++ applications](/learning-paths/servers-and-cloud-computing/migration/c/) section of the [Migrating applications to Arm servers](/learning-paths/servers-and-cloud-computing/migration/)learning path.
70
+
To understand how to configure an NGINX build, review the [build NGINX from source](/learning-paths/servers-and-cloud-computing/nginx/build_from_source/) section of the [Learn how to deploy NGINX](/learning-paths/servers-and-cloud-computing/nginx/)Learning Path.
67
71
68
-
If you need to understand how to configure a build of Nginx. Please review the [build Nginx from source](/learning-paths/servers-and-cloud-computing/nginx/build_from_source/) section of the [Learn to deploy Nginx learning path](/learning-paths/servers-and-cloud-computing/nginx/).
72
+
## OpenSSL
69
73
70
-
## OpenSSL
74
+
NGINX relies on [OpenSSL](https://www.openssl.org/) for cryptographic operations. The OpenSSL version, GCC version, and compiler switches used to build OpenSSL can affect TLS performance. The Linux distribution default version of OpenSSL is sufficient for many deployments.
71
75
72
-
Nginx relies on [OpenSSL](https://www.openssl.org/)for cryptographic operations. Thus, the version of OpenSSL used with Nginx (and the GCC version and switches used to compile it) can impact performance. Typically using the Linux distribution default version of OpenSSL is sufficient.
76
+
Newer versions of OpenSSL might improve performance for some TLS workloads. To use a specific OpenSSL source tree, pass the `--with-openssl` switch when configuring the NGINX build. Point this switch to the directory that contains the source code of the OpenSSL version you want NGINX to link to. You can also use `--with-openssl-opt` to pass options to the OpenSSL build.
73
77
74
-
However, it is possible to use newer versions of OpenSSL which could yield performance improvements. This is achieved by using the `--with-openssl` switch when configuring the Nginx build. Point this switch to the directory that contains the source code of the version of OpenSSL you'd like to have Nginx link to. The Nginx build system takes care of the rest. There is also a `--with-openssl-opt` switch which allows you to add options to the build for OpenSSL.
78
+
NGINX can also be built with OpenSSL-compatible alternatives for some use cases. For example, the NGINX [QUIC and HTTP/3 documentation](https://nginx.org/en/docs/quic.html) shows how to configure NGINX with BoringSSL, LibreSSL, or QuicTLS. Consider this when you have a specific TLS or QUIC reason to evaluate another library, and measure the result with your workload.
75
79
76
-
The version of OpenSSL Nginx is using can be verified by running the command `nginx -V`.
80
+
Run `nginx -V` to check the TLS library information and configure options used by your NGINX build.
77
81
78
-
## Perl Compatible Regular Expressions (PCRE)
82
+
## Perl Compatible Regular Expressions (PCRE)
79
83
80
-
Nginx relies on [PCRE](https://www.pcre.org/) for regular expression processing. One scenario where regular expressions are used is for an API Gateway. Typically, using the Linux distribution default version of PCRE is sufficient. However, it is possible to use a newer version of PCRE to potentially gain performance. The Nginx[installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source) explain how to build the latest version of PCRE if this is something you want to explore.
84
+
NGINX relies on [PCRE](https://www.pcre.org/) for regular expression processing. One scenario where regular expressions are used is an API gateway path rewrite. The Linux distribution default version of PCRE is sufficient for many deployments. A newer version of PCRE might improve performance for regular expression-heavy configurations. The NGINX[installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source) explain how to build PCRE with NGINX from source.
81
85
82
-
## zlib for HTTP response compression
86
+
## zlib for HTTP response compression
83
87
84
-
Nginx relies on [zlib](https://zlib.net/) for HTTP response compression (when the `ngx_http_gzip_module` directives are used). Typically, using the Linux distribution default version of zlib is sufficient. However, it is possible to use a newer version of zlib to potentially gain performance. The Nginx[installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source) explain how to build the latest version of zlib if this is something you want to explore.
88
+
NGINX relies on [zlib](https://zlib.net/) for HTTP response compression when the `ngx_http_gzip_module` directives are used. The Linux distribution default version of zlib is sufficient for many deployments. A newer version of zlib might improve performance for compression-heavy workloads. The NGINX[installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source) explain how to build zlib with NGINX from source.
0 commit comments