0x1B. Web stack debugging #4
DevOps - SysAdmin - Scripting - Debugging -ApacheBench - load testing
Intro
ApacheBench, often referred to as "ab," is a command-line tool for benchmarking the performance of web servers. It is part of the Apache HTTP Server project and is designed to simulate a large number of requests to a web server, measuring various aspects of the server's performance, such as how many requests per second it can handle and the time taken for each request.
Here are some key features and uses of ApacheBench:
1. **Load Testing:** ApacheBench is commonly used for load testing web servers by generating a specified number of requests or a specified level of concurrency. This helps developers and system administrators understand how well their web server performs under different levels of stress.
2. **Simple Configuration:** It is easy to use with a straightforward command-line interface. You can specify the number of requests, the concurrency level, and other parameters to tailor the testing scenario to your needs.
3. **HTTP Method Support:** ApacheBench supports various HTTP methods, including GET and POST, allowing you to test different types of requests.
4. **Output Formats:** The tool provides output in both human-readable format and machine-readable format, making it convenient for both quick analysis and automated processing of results.
5. **SSL/TLS Support:** ApacheBench has support for testing secure HTTPS connections by incorporating SSL/TLS.
When using ApacheBench, keep in mind that it's a tool for generating synthetic load and measuring server performance under that load. It's not a complete solution for testing real-world scenarios, but it's valuable for gaining insights into how a web server handles different levels of concurrent requests.
Perform a benchmark test on a web server running on a local machine
The command you provided, `ab -c 100 -n 2000 localhost/
`, is using ApacheBench (`ab`) to perform a benchmark test on a web server running on your local machine (localhost). Let's break down the command:
- `-c 100`: This option specifies the number of multiple requests to perform concurrently. In this case, it's set to 100 concurrent requests.
- `-n 2000`: This option sets the total number of requests to perform during the test. Here, it's set to 2000 total requests.
- `localhost/`: This is the URL of the server you want to test. In this case, it's the web server running on your local machine.
So, the command is essentially saying, "Send 2000 requests to the local web server, with a concurrency of 100 requests at a time."
When you run this command, ApacheBench will simulate 100 clients (concurrent connections) repeatedly making requests to the specified URL until a total of 2000 requests have been completed. After the test is finished, ApacheBench will provide you with statistics on the performance of the web server, including requests per second, connection times, and more.
ApacheBench Failure :(Too many open files)
1. Check Current Limits:
ulimit -a

ulimit -a
command provides a comprehensive overview of the resource limits for the user associated with the current shell session, helping you understand and manage process resource usage.The `ulimit -a` command shows the current resource limits for the user associated with the shell session. Let's break down the output:
- **core file size (blocks, -c):** Unlimited
- This specifies the maximum size of core dump files that can be created. In this case, it's set to unlimited, meaning core dump files can be of any size.
- **data seg size (kbytes, -d):** Unlimited
- This represents the maximum size of the data segment of a process, in kilobytes. Setting it to unlimited allows processes to use as much data as needed.
- **scheduling priority (-e):** 0
- This indicates the scheduling priority of the process. A priority of 0 is the default.
- **file size (blocks, -f):** Unlimited
- This specifies the maximum size of files that a process can create.
- **pending signals (-i):** 62761
- It shows the number of signals that are currently pending for the process.
- **max locked memory (kbytes, -l):** 65536
- This is the maximum amount of memory that can be locked in RAM.
- **max memory size (kbytes, -m):** Unlimited
- This sets the maximum data size that a process can use in kilobytes.
- **open files (-n):** 1048576
- This is the maximum number of file descriptors that a process can have open simultaneously. It was set to 1048576 in your case.
- **pipe size (512 bytes, -p):** 8
- Specifies the maximum size of pipes in bytes.
- **POSIX message queues (bytes, -q):** 819200
- Sets the maximum number of bytes in POSIX message queues.
- **real-time priority (-r):** 0
- This indicates the real-time scheduling priority.
- **stack size (kbytes, -s):** 8192
- Specifies the stack size of the process in kilobytes.
- **cpu time (seconds, -t):** Unlimited
- Sets the maximum amount of CPU time that a process can consume.
- **max user processes (-u):** Unlimited
- Specifies the maximum number of processes a user can create.
- **virtual memory (kbytes, -v):** Unlimited
- Sets the limit on the use of virtual memory by the process.
- **file locks (-x):** Unlimited
- Specifies the maximum number of file locks.
2. Increase File Descriptor Limits:
Edit the file /etc/default/nginx
and add or modify the following lines:
# Note: You may want to look at the following page before setting the ULIMIT.
# http://wiki.nginx.org/CoreModule#worker_rlimit_nofile
# Set the ulimit variable if you need defaults to change.
# Example: ULIMIT="-n 4096"
ULIMIT="-n 15"
The variable ULIMIT="-n 15"
is typically associated with the soft limit. In this context, it's setting the soft limit for the number of file descriptors (file handles) that a process can have simultaneously.
To provide a bit more detail:
Soft Limit: This is the current limit that can be adjusted by the user or process within the constraints of the hard limit. In the provided script,
ULIMIT="-n 15"
sets the soft limit for the number of file descriptors to 15.hard
- This is the hard limit, which is the maximum limit set by the system administrator. Users/processes cannot exceed this limit.
Restart Nginx:
After making these changes, restart Nginx:
systemctl restart nginx
5. Verify Changes:
Check Nginx error logs and system logs for any issues:
cat /var/log/nginx/error.log
Resources:
https://stackoverflow.com/questions/27849331/how-to-set-nginx-max-open-files