# NGINX Benchmarking

## In this learning path

- [Introduction](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/)
- [Overview of Azure Cobalt 200 and NGINX](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/backgroud/)
- [Create an Arm-based Azure VM with Cobalt 200](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/instance/)
- [Install NGINX](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/deploy/)
- [NGINX Baseline Testing](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/baseline/)
- [NGINX Benchmarking](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/benchmarking/)
- [Next Steps](https://learn.arm.com/learning-paths/servers-and-cloud-computing/nginx-on-azure/_next-steps/)

## Benchmark NGINX with ApacheBench on Arm
Use ApacheBench (**ab**) to measure NGINX performance on your Arm64 Azure VM. This section shows you how to install the tool, run a basic benchmark, interpret key metrics, and review a sample result from an Azure **D4ps_v7** instance.

## Install ApacheBench
On **Ubuntu 24.04 LTS**, ApacheBench is provided by the **apache2-utils** package:

```bash
sudo apt update
sudo apt install -y apache2-utils
```

Verify the installation:

```bash
ab -V
```

Expected output:

```
__output__
This is ApacheBench, Version 2.3 <$Revision: 1903618 $>
__output__
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
__output__
Licensed to The Apache Software Foundation, http://www.apache.org/
```

## Run a basic benchmark
The general syntax for running an ApacheBench test is:

```bash
ab -n <total_requests> -c <concurrent_clients> <http://host:port/path>
```

Example (1,000 requests, 50 concurrent, to your static website on localhost):

```bash
ab -n 1000 -c 50 http://localhost/
```

This command sends 1,000 total requests with 50 concurrent connections to `http://localhost/`.

Sample output:

```
__output__
Server Software:        nginx/1.24.0
__output__
Server Hostname:        localhost
__output__
Server Port:            80

__output__
Document Path:          /
__output__
Document Length:        880 bytes

__output__
Concurrency Level:      50
__output__
Time taken for tests:   0.025 seconds
__output__
Complete requests:      1000
__output__
Failed requests:        0
__output__
Total transferred:      1122000 bytes
__output__
HTML transferred:       880000 bytes
__output__
Requests per second:    40196.16 [#/sec] (mean)
__output__
Time per request:       1.244 [ms] (mean)
__output__
Time per request:       0.025 [ms] (mean, across all concurrent requests)
__output__
Transfer rate:          44043.06 [Kbytes/sec] received

__output__
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       1
Processing:     0    1   0.2      1       2
Waiting:        0    1   0.2      1       1
Total:          1    1   0.1      1       2

__output__
Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      2
  99%      2
 100%      2 (longest request)
```

## Interpret benchmark results
ApacheBench produces a variety of metrics, but the most useful ones highlight how well your server handles load. The requests per second value shows the average throughput, while the first time per request value is calculated as concurrency multiplied by test duration divided by completed requests. The second time per request value divides test duration by completed requests. Use the connection timings and percentiles to examine request latency. Ideally, the failed requests metric should remain at zero to confirm reliability. Finally, the transfer rate measures the effective bandwidth used by the responses, giving you insight into overall data flow efficiency.

## Benchmark summary on Arm64
The following results were collected on an Azure Cobalt 200 **Standard_D4ps_v7** VM (4 vCPUs) in **West US 2**, running **Ubuntu 24.04 LTS** with **NGINX 1.24.0**. ApacheBench ran on the same VM against the 880-byte static page created in the previous section.

| Metric                             | Value          |
|------------------------------------|----------------|
| Concurrency                        | 50             |
| Complete requests                  | 1,000          |
| Failed requests                    | 0              |
| Time taken                         | 0.025 seconds  |
| Requests per second                | 40,196.16      |
| Time per request (mean)           | 1.244 ms       |
| Time per request (mean, across concurrent requests) | 0.025 ms       |
| Total transferred                  | 1,122,000 bytes|
| HTML transferred                   | 880,000 bytes  |
| Transfer rate                      | 44,043.06 Kbytes/sec |

## Summary
Your NGINX deployment on Azure Cobalt 200 successfully handled all 1,000 requests with 50 concurrent connections and no failures. You now have a working static website and an initial performance baseline to guide further testing.

ApacheBench ran on the same VM as NGINX, so these results reflect local request handling. To evaluate production capacity, run longer, repeated tests from a separate load generator using representative content and traffic patterns. Keep the test conditions consistent when comparing configurations or VM types.
