Apache Lounge



Forum Index Downloads Search Register Log in  RSS Apache Lounge

Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.



A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Apache Lounge is not sponsored.

Your donations will help to keep this site alive and well, and continuing building binaries.

Best settings for high load Linux server

Post new topic   Reply to topic    Apache Forum Index -> Apache

View previous topic :: View next topic  
Author Message

Joined: 27 Sep 2017
Posts: 26

PostPosted: Wed 06 Dec '17 14:15    Post subject: Best settings for high load Linux server Reply with quote

Hello, what are the best settings I should use for a streaming Webserver that will be accessed by hundreds of users accessing hundreds of files all at the same time? Thanks

If my Server has 32 GB RAM what settings from below would you recommend?

Limit the Number of Apache Processes and Children

Most operating systems' default Apache configurations are not well suited for smaller servers-- 25 child processes or more is common. If each of your Apache child processes uses 120MB of RAM, then your VPS would need 3GB just for Apache.

One visitor's web browser may request 4 items from the website at once, so with only 7 or 8 people trying to load a page at the same time your cloud server can become overloaded. This causes the web page to hang in a constantly loading state for what seems like an eternity.

It is often the case that the server will keep these dead Apache processes active, attempting to serve content long after the user gave up, which reduces the number of processes available to serve users and reduces the amount of system RAM available. This causes what is commonly known as a downward spiral that ends in a bad experience for both you and your site's visitors.

What you should do is figure out how much RAM your application needs, and then figure out how much is left, and allocate most of that to Apache.

For example, if you have three php-fpm processes handling dynamic content, and each can use up to 70MB of RAM, and your MySQL server may use up to 120MB of RAM, that combines for a total of 330MB used by the application. This allows you to allocate about 150MB to Apache.

While Apache is running open the top command on the server. I'll paste a little bit of what you'd see, trimming out most of the lines that aren't pertinent:

top -bn 1
15015 www-data 20 0 232m 9644 1900 S 0.0 1.6 0:00.02 apache2
15016 www-data 20 0 232m 9644 1900 S 0.0 1.6 0:00.01 apache2
15017 www-data 20 0 232m 9644 1900 S 0.0 1.6 0:00.02 apache2

Notice the RES column for an Apache child process and make note of its RES value. For example, on my virtual server which has been well optimized, the value is 9,644, which means it's using not quite 10MB of RAM. If I limit Apache to a maximum of 15 child processes, then it should max out at about 150MB of RAM.

Edit your cloud server's apache config file, which on Ubuntu and Debian is /etc/apache2/apache2.conf and locate the section for the mpmpreforkmodule configuration. Look for the MaxClients line and set it to 15, then save and restart Apache.

Here is an example of what you'll look for in Ubuntu:

<IfModule mpm_prefork_module>
StartServers 3
MinSpareServers 3
MaxSpareServers 5
MaxClients 30
MaxRequestsPerChild 0

See the MaxClients line there? We need to change that value to a lower number.

If your VPS gets overloaded, and reaches the maximum number of clients it can serve at once, it will serve those and other users will simply get a quick failure. They can then reload the page and maybe have greater success on the second try.

This sounds bad, but believe me, it's much better to have these connections close quickly but leave the server in a healthy state rather than hanging open for an eternity. Surprisingly you can get better performance from a server that has fewer child processes but responds faster than it is to have a server with more child processes that it is unable to handle.

Case in point, a Wordpress site I manage is hosted on a 1GB droplet using 4 php-fpm processes and is able to serve over 950 simultaneous users at one time. This translate to a peak capacity of about 42 million page views per day, should this website ever become popular enough!
Consider Alternate MPM Configuration

Most Apache configurations have historically used the prefork mpm, which is thread safe and therefore suitable for use with PHP and other embedded languages.

If you get rid of external modules such as PHP or Rails then you can consider the worker MPM, which often is faster than prefork.

In order to enable the worker module you have to install it.

sudo apt-get install apache2-mpm-worker

Which will show you a message like this:

The following packages will be REMOVED:
apache2-mpm-prefork libapache2-mod-php5
The following NEW packages will be installed:
0 upgraded, 1 newly installed, 2 to remove and 2 not upgraded.
Need to get 2,284 B of archives.
After this operation, 8,718 kB disk space will be freed.
Do you want to continue [Y/n]?

Take careful note, on Ubuntu, if you install the worker mpm it will uninstall the prefork mpm and it will uninstall mod_php and other incompatible add-on modules.

Here we've discussed four optimizations you can make to Apache that should greatly boost your application performance, even if you have a small droplet.

I strongly suggest trying this out on a test droplet rather than your production server. The beauty of DigitalOcean's service is that you can spin up a new droplet for just the amount of time you need to test the changes, and shut it down when you're done. With hourly billing, it is a low-risk, low-cost way to find the perfect configuration for your VPS.
Back to top
James Blond

Joined: 19 Jan 2006
Posts: 6484
Location: Germany, Next to Hamburg

PostPosted: Mon 18 Dec '17 23:12    Post subject: Reply with quote

Why not use event_mpm ? How do you serve php now? mod_fcgid?
Back to top

Post new topic   Reply to topic    Apache Forum Index -> Apache
Page 1 of 1