Server crashes during peak traffic are every sysadmin's nightmare. When Apache starts failing without clear error logs, systematic stress testing becomes crucial. Here's how to methodically identify the breaking point using Linux-native tools.
These battle-tested tools should be in every infrastructure engineer's arsenal:
# Install basic stress testing suite
sudo apt-get install apache2-utils siege httperf ab
The simplest way to test request capacity:
ab -n 10000 -c 500 http://yourserver.com/test_page.php
Key parameters:
-n = total requests
-c = concurrent connections
-k = enable HTTP keepalive
For more realistic traffic patterns that mimic actual users:
siege -b -t5M -c250 -f urls.txt
Where urls.txt contains your target URLs, one per line. The -b flag enables benchmark mode (no delays).
Always watch these metrics in parallel:
watch -n 1 "ps -eo pid,user,comm,pcpu,pmem --sort=-pcpu | head -n 10"
And Apache's server-status:
lynx http://localhost/server-status
When you need massive scale from multiple client machines:
<?xml version="1.0"?>
<!DOCTYPE tsung SYSTEM "/usr/share/tsung/tsung-1.0.dtd">
<tsung loglevel="notice" version="1.0">
<clients>
<client host="client1" cpu="4" maxusers="1000"/>
</clients>
<servers>
<server host="yourserver.com" port="80" type="tcp"/>
</servers>
<load duration="5" unit="minute">
<arrivalphase phase="1" duration="1" unit="minute">
<users arrivalrate="10" unit="second"/>
</arrivalphase>
</load>
</tsung>
Key failure patterns to watch for:
- Connection timeouts → Check MaxClients and KeepAlive settings
- Memory exhaustion → Review process sizes with pmap
- CPU saturation → Profile with perf top
Common Apache settings to adjust:
# In httpd.conf
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 0
Remember to restart Apache after changes:
sudo systemctl restart apache2
When your Apache server keeps crashing unexpectedly, the first step is to determine whether it's caused by resource exhaustion (CPU/RAM), script execution issues, or connection overload. We'll focus on load testing methodologies that help identify breaking points.
Linux offers several powerful benchmarking tools for Apache stress testing:
# Install common benchmarking tools on Debian/Ubuntu
sudo apt-get install apache2-utils siege ab httperf wrk
# For RHEL/CentOS
sudo yum install httpd-tools siege httperf wrk
The simplest way to test basic request handling:
# Basic test (1000 requests with 10 concurrent connections)
ab -n 1000 -c 10 http://yourserver.com/testpage.html
# Comprehensive test with Keep-Alive
ab -k -n 50000 -c 100 http://yourserver.com/dynamic-script.php
For more realistic user simulation:
# Run for 60 seconds with 25 concurrent users
siege -b -t60s -c25 http://yourserver.com
# Test with URL list file
siege -f urls.txt -c100 -i -t2M
Always monitor server metrics while testing:
# Real-time monitoring (run in separate terminal)
watch -n 1 "echo -n 'Apache Processes: '; ps -ef | grep httpd | wc -l; echo 'Memory:'; free -m; echo 'CPU:'; top -bn1 | grep 'Cpu(s)'"
Check these critical Apache settings in httpd.conf:
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 256
MaxClients 256
MaxRequestsPerChild 4000
Here's a bash script that gradually increases load until failure:
#!/bin/bash
URL="http://yourserver.com"
LOG="loadtest.log"
CONCURRENT_USERS=10
while true; do
echo "Testing with $CONCURRENT_USERS concurrent users..."
ab -n 100000 -c $CONCURRENT_USERS $URL >> $LOG
if [ $? -ne 0 ]; then
echo "Server crashed at $CONCURRENT_USERS users"
break
fi
CONCURRENT_USERS=$((CONCURRENT_USERS+10))
done
Key metrics to analyze:
- Requests per second
- Time per request
- Failed requests percentage
- Connection timing breakdown
- Server resource usage patterns