Skip to content

Commit a642174

Browse files
first pass edits
1 parent 1d722b9 commit a642174

6 files changed

Lines changed: 153 additions & 115 deletions

File tree

content/learning-paths/servers-and-cloud-computing/nginx_tune/_index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ learning_objectives:
1515
prerequisites:
1616
- A cloud or bare-metal installation of an NGINX file server, reverse proxy, or API gateway.
1717
- 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/).
18+
- If you don't already have an NGINX setup, see [Learn how to deploy NGINX](/learning-paths/servers-and-cloud-computing/nginx/).
1919

2020
author: Julio Suarez
2121

content/learning-paths/servers-and-cloud-computing/nginx_tune/before_and_after.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Measure NGINX tuning impact"
2+
title: Measure the impact of NGINX tuning
33
description: Learn how to approach NGINX performance tuning as a measurement-driven process and compare baseline results with tuned results.
44
weight: 2
55
layout: "learningpathall"
@@ -15,7 +15,7 @@ Whatever method you use, keep the measurements repeatable. Record the system con
1515

1616
## Why tune NGINX
1717

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.
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. By tuning, you can use the available compute, memory, storage, and network resources more efficiently.
1919

2020
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.
2121

@@ -26,3 +26,9 @@ The following example shows `wrk` throughput before and after tuning for an NGIN
2626
![Bar chart comparing normalized NGINX API gateway wrk throughput before and after tuning. The out-of-box configuration is normalized to 1.00, and the tuned configuration reaches 1.13, showing about 13% higher RPS after tuning.#center](nginxoobvstuned.png "NGINX API gateway throughput before and after tuning")
2727

2828
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.
29+
30+
## What you've learned and what's next
31+
32+
You've now learned why tuning NGINX is useful and reviewed an example benchmark demonstrating improvement in `wrk` throughput after tuning.
33+
34+
Next, you'll learn about kernel, compiler, and library optimizations.
Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: "Kernel, compiler, and libraries"
2+
title: Tune kernel, compiler, and library settings for performance
33
weight: 3
44
layout: "learningpathall"
55
---
@@ -34,55 +34,65 @@ sudo sysctl -w net.ipv4.tcp_wmem="4096 8388608 8388608"
3434

3535
These values are intentionally large. Size them for your expected connection rate, request pattern, and available memory.
3636

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.
37+
- `net.core.somaxconn`:
38+
- 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+
- 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 set a value for this parameter.
45+
- `net.core.wmem_max`:
46+
- 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 set a value for this parameter.
49+
- `net.ipv4.tcp_max_syn_backlog`:
50+
- 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+
- 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+
- 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 set a value for this parameter.
59+
- `net.ipv4.tcp_wmem`:
60+
- 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 set a value for this parameter.
6363

6464
## Compiler considerations
6565

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.
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. 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.
6767

6868
When you configure an NGINX source build, pass compiler flags with the `--with-cc-opt` option.
6969

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.
70+
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.
7171

7272
## OpenSSL
7373

7474
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.
7575

7676
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.
7777

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.
78+
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.
7979

8080
Run `nginx -V` to check the TLS library information and configure options used by your NGINX build.
8181

8282
## Perl Compatible Regular Expressions (PCRE)
8383

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.
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.
85+
86+
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).
8587

8688
## zlib for HTTP response compression
8789

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.
90+
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.
91+
92+
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).
93+
94+
## What you've learned and what's next
95+
96+
You've now learned about different kernel, compiler, and library optimizations that you can make to tune NGINX performance.
97+
98+
Next, you'll review the configuration for a static file server and learn about optimizations that you can make.

content/learning-paths/servers-and-cloud-computing/nginx_tune/test_optimizations.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
---
2-
title: "Test optimizations"
2+
title: Test NGINX optimizations
33
weight: 6
44
layout: "learningpathall"
55
---
66

7-
## Test NGINX optimizations
7+
## Use wrk to test NGINX
88

99
You can skip this section if you already have a performance test method for your NGINX deployment.
1010

11-
This section presents one method for testing NGINX with `wrk`. Use it as a starting point if you don't already have an established load test strategy. To understand the impact of tuning on your deployment, use a workload that reflects your request pattern, response size, TLS behavior, concurrency, and upstream service behavior.
11+
One method for testing NGINX is with `wrk`. Use this method as a starting point if you don't already have an established load test strategy.
1212

13-
## About wrk
13+
To understand the impact of tuning on your deployment, use a workload that reflects your request pattern, response size, TLS behavior, concurrency, and upstream service behavior.
14+
15+
### About wrk
1416

1517
[`wrk`](https://github.com/wg/wrk) is an HTTP load test tool that lets you configure the number of threads, open connections, and test duration. It reports throughput and latency statistics. Another option is [`h2load`](https://nghttp2.org/documentation/h2load-howto.html), which is useful when you want to test HTTP/2 behavior or prefer the `nghttp2` toolchain.
1618

17-
## Install wrk
19+
### Install wrk
1820

1921
You can install `wrk` by cloning the source and using `make`.
2022

@@ -35,15 +37,15 @@ cd wrk
3537
make
3638
```
3739

38-
## Example load test setup
40+
### Example load test setup
3941

4042
The following diagram shows a typical multi-node test setup. The load generator runs `wrk`. The instance under test runs the reverse proxy or API gateway. The file servers act as upstream servers for the reverse proxy or API gateway.
4143

4244
You can also run `wrk` directly against NGINX file servers, or run `wrk` on the same node as NGINX. Choose a setup that reflects your deployment and avoids making the load generator the bottleneck.
4345

4446
![Diagram showing a load generator running wrk against an NGINX reverse proxy with upstream NGINX file servers.#center](exampletestsetup.png "Example NGINX load test setup")
4547

46-
## Running a wrk test
48+
### Run a wrk test
4749

4850
The NGINX file servers need files to serve. If you are using the configuration files discussed in [Tune a static file server](/learning-paths/servers-and-cloud-computing/nginx_tune/tune_static_file_server/) or [Tune a reverse proxy or API gateway](/learning-paths/servers-and-cloud-computing/nginx_tune/tune_revprox_and_apigw/), run the following commands on each file server to create sample files. You do not need to create these files on reverse proxy or API gateway nodes because they do not serve files directly.
4951

@@ -79,3 +81,9 @@ The following sample command tests an API gateway path:
7981
```
8082

8183
The API gateway shown in [Tune a reverse proxy or API gateway](/learning-paths/servers-and-cloud-computing/nginx_tune/tune_revprox_and_apigw/) rewrites `api_old` to `api_new`. This is why the sample files are copied into `/usr/share/nginx/html/api_new` as well as the document root on the file servers.
84+
85+
## What you've accomplished
86+
87+
You've now used `wrk` to run an NGINX performance test.
88+
89+
You can use the guidance in this Learning Path to optimize the performance of your NGINX workloads on Arm-based platforms.

0 commit comments

Comments
 (0)