|
1 | 1 | --- |
2 | | -title: "Kernel, compiler, and libraries" |
| 2 | +title: Tune kernel, compiler, and library settings for performance |
| 3 | +description: Tune Linux network settings and evaluate compiler, OpenSSL, PCRE, and zlib choices that can affect NGINX performance on Arm-based platforms. |
3 | 4 | weight: 3 |
4 | 5 | layout: "learningpathall" |
5 | 6 | --- |
6 | 7 |
|
7 | | -## Kernel configuration |
| 8 | +## Optimize kernel network stack settings |
8 | 9 |
|
9 | 10 | 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 | 11 |
|
@@ -34,55 +35,58 @@ sudo sysctl -w net.ipv4.tcp_wmem="4096 8388608 8388608" |
34 | 35 |
|
35 | 36 | These values are intentionally large. Size them for your expected connection rate, request pattern, and available memory. |
36 | 37 |
|
37 | | -* `net.core.somaxconn`: |
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 | | -* `net.core.rmem_max`: |
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 | | -* `net.core.wmem_max`: |
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 | | -* `net.ipv4.tcp_max_syn_backlog`: |
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 | | -* `net.ipv4.ip_local_port_range`: |
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 | | -* `net.ipv4.tcp_rmem`: |
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 | | -* `net.ipv4.tcp_wmem`: |
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. |
| 38 | +- `net.core.somaxconn`: Selects the maximum number of queued connections the kernel allows. If the NGINX server needs to support a large number of clients, it can be helpful to increase this parameter. |
| 39 | + |
| 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 | +- `net.core.rmem_max`: Selects the maximum read socket buffer size. `8 MiB` is likely more than enough for most use cases. |
| 42 | + |
| 43 | + Use a tool such as `ss` to check socket buffer utilization and set a value for this parameter. |
| 44 | +- `net.core.wmem_max`: Selects the maximum write socket buffer size. `8 MiB` is likely more than enough for most use cases. |
| 45 | + |
| 46 | + Use a tool such as `ss` to check socket buffer utilization and set a value for this parameter. |
| 47 | +- `net.ipv4.tcp_max_syn_backlog`: Selects the maximum number of connection requests that are pending but not established yet. |
| 48 | + |
| 49 | + 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. |
| 50 | +- `net.ipv4.ip_local_port_range`: Selects the range of local ports the kernel can use. The example expands the port range. The default range is sufficient for many deployments. |
| 51 | +- `net.ipv4.tcp_rmem`: Selects the TCP read socket buffer size. `8 MiB` is likely more than enough for most use cases. |
| 52 | + |
| 53 | + Use a tool such as `ss` to check TCP buffer utilization and set a value for this parameter. |
| 54 | +- `net.ipv4.tcp_wmem`: Selects the TCP write socket buffer size. `8 MiB` is likely more than enough for most use cases. |
| 55 | + |
| 56 | + Use a tool such as `ss` to check TCP buffer utilization and set a value for this parameter. |
63 | 57 |
|
64 | 58 | ## Compiler considerations |
65 | 59 |
|
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. |
| 60 | +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. For more information about these flags, see 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. |
67 | 61 |
|
68 | 62 | When you configure an NGINX source build, pass compiler flags with the `--with-cc-opt` option. |
69 | 63 |
|
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. |
| 64 | +To understand how to configure an NGINX build, see 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. |
71 | 65 |
|
72 | 66 | ## OpenSSL |
73 | 67 |
|
74 | 68 | 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. |
75 | 69 |
|
76 | 70 | 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. |
77 | 71 |
|
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. |
| 72 | +You can also build NGINX 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. |
79 | 73 |
|
80 | 74 | Run `nginx -V` to check the TLS library information and configure options used by your NGINX build. |
81 | 75 |
|
82 | 76 | ## Perl Compatible Regular Expressions (PCRE) |
83 | 77 |
|
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. |
| 78 | +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. |
| 79 | + |
| 80 | +To learn how to build PCRE with NGINX from source, see the NGINX [installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source). |
85 | 81 |
|
86 | 82 | ## zlib for HTTP response compression |
87 | 83 |
|
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. |
| 84 | +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. |
| 85 | + |
| 86 | + To learn how to build zlib with NGINX from source, see the NGINX [installation instructions](https://docs.nginx.com/nginx/admin-guide/installing-nginx/installing-nginx-open-source/#compiling-and-installing-from-source). |
| 87 | + |
| 88 | +## What you've learned and what's next |
| 89 | + |
| 90 | +You've now learned how Linux network settings, compiler options, and supporting libraries can affect NGINX throughput and latency. |
| 91 | + |
| 92 | +Next, you'll review the configuration for a static file server and learn about optimizations that you can make. |
0 commit comments