Optimal Apache 2.4 MPM Prefork Tuning Guide for Ubuntu 14.04 Servers


3 views

The provided MPM prefork configuration shows several key parameters that need optimization:


    StartServers            20
    MinSpareServers         100
    MaxSpareServers         250
    MaxRequestWorkers       150
    MaxConnectionsPerChild  0

For an 8GB RAM server handling lightweight form requests, we can make these recommendations:

  • Each Apache process typically consumes 5-15MB memory
  • With 8GB RAM, we can safely allocate 6GB to Apache (leaving 2GB for OS)
  • This allows for approximately 400-600 worker processes (assuming 10MB/process)

Here's an optimized configuration based on the server specs:


    StartServers            5
    MinSpareServers         10
    MaxSpareServers         20
    ServerLimit             400
    MaxRequestWorkers       400
    MaxConnectionsPerChild  10000

StartServers: Reduced from 20 to 5 since we don't need many initial processes for a low-traffic form.

Spare Servers: Lowered significantly (100/250 → 10/20) to prevent memory waste on idle processes.

MaxRequestWorkers: Increased from 150 to 400 to handle potential traffic spikes.

MaxConnectionsPerChild: Set to 10000 to recycle processes periodically and prevent memory leaks.

Install Apache's status module to monitor performance:

sudo a2enmod status
sudo service apache2 restart

Then access server-status at http://yourserver/server-status to view:

  • Current number of workers
  • Request processing statistics
  • Memory usage patterns

For even better performance on Ubuntu 14.04:

  1. Enable KeepAlive with conservative timeout:
    KeepAlive On
    KeepAliveTimeout 2
    MaxKeepAliveRequests 100
  2. Adjust Timeout value:
    Timeout 30

If you see "server reached MaxRequestWorkers" errors:

  1. Check current connections:
    apache2ctl status | grep "requests currently being processed"
  2. Increase ServerLimit and MaxRequestWorkers incrementally
  3. Monitor memory usage during peak times:
    watch -n 1 "free -m && ps -ylC apache2 --sort:rss"

Here's a complete optimized configuration for your 8GB server:


    StartServers            5
    MinSpareServers         10
    MaxSpareServers         20
    ServerLimit             500
    MaxRequestWorkers       400
    MaxConnectionsPerChild  10000


Timeout 30
KeepAlive On
KeepAliveTimeout 2
MaxKeepAliveRequests 100

Your current Apache 2.4.7 configuration on Ubuntu 14.04 uses the following MPM prefork settings:


    StartServers            20
    MinSpareServers         100
    MaxSpareServers         250
    MaxRequestWorkers       150
    MaxConnectionsPerChild  0

This configuration is running on an 8GB RAM Amazon EC2 instance serving a lightweight three-page signup form. The error message indicates your server is hitting the MaxRequestWorkers limit during traffic spikes.

For an 8GB server, we need to consider:

# Calculate based on available memory
Total Memory = 8GB
Apache Process Size = ~50MB (average for simple PHP app)
MaxRequestWorkers = (Total Memory - System Reserve) / Apache Process Size
Recommended MaxRequestWorkers = (8000MB - 2000MB) / 50MB ≈ 120-150

However, your current settings have some inefficiencies:

  • Too high MinSpareServers (100) for your MaxRequestWorkers (150)
  • MaxSpareServers (250) exceeds MaxRequestWorkers
  • StartServers (20) is reasonable but could be lower

Here's an optimized configuration for your 8GB server:


    StartServers            5
    MinSpareServers         5
    MaxSpareServers         10
    MaxRequestWorkers       150
    MaxConnectionsPerChild  10000

After making changes, monitor with:

# Check Apache status
sudo apachectl status
# Or for more details:
sudo apachectl -V
sudo apachectl -t -D DUMP_MODULES

Use this command to monitor memory usage:

watch -n 1 "echo -n 'Apache Processes: '; ps -C apache2 --no-headers | wc -l; free -m"

For further optimization:

  1. Consider switching to MPM Event if using PHP-FPM
  2. Enable KeepAlive with conservative settings:
KeepAlive On
KeepAliveTimeout 2
MaxKeepAliveRequests 100

Remember to restart Apache after changes:

sudo service apache2 restart

If you're still seeing MaxRequestWorkers errors during campaigns:

  • Temporarily increase MaxRequestWorkers to 200
  • Consider adding CloudFront or similar CDN
  • Implement caching for static assets