Webserver Buckling under Benchmark

6 posts / 0 new
Last post
#1 Fri, 06/04/2010 - 14:56
ZeroT3K

Webserver Buckling under Benchmark

So, before I start, I want to say that I'm a novice when it comes to Apache, PHP, CGI, etc configuration. I'm pretty much learning this as I go. I currently have a MediaTemple (VE) server, which is cloud VPS provisioned currently with 1GB memory burstable up to 2GB.

Yesterday, I did an Apache Benchmark test on my site. I had a top command up via ssh watching my memory. I executed the benchmark.

My server died.

A service outside of my server's control essentially took out my websites. When checking my Plesk Power Panel, I was getting resource errors galore.

The site that I tested this on was a very heavy PHP site using Wordpress and Gallery2. Thus, I'm assuming my issue is with the site's PHP settings. Checking top, I notice that I'll normally have 7-10 processes (php5-cgi) accepting connections at anytime. During peak time's I'd expect this, but this was at around 4AM-5AM.

My main issue is the knowledge that someone could EASILY take out my site with a benchmark. So I f'ed up somewhere, obviously. I'm unsure if I have memory settings misconfigured for PHP, if I have allowed too many processes to run for apache and my php wrapper, or if I simply have a shoddy VPS.

Any ideas on what I can do? My goal honestly is just for the site to not crash like that again.

Apologies for the n00b-factors. Like I said, learning as I go.

Fri, 06/04/2010 - 18:38
andreychek

Howdy,

What is the output of "free -m" on your server?

As far as running Apache/PHP goes -- the key is simply to set things up such that you can never have more Apache/PHP processes running than you have available RAM.

One way to help with that is to remove any Apache and PHP modules that you aren't using, so that the processes all use up less RAM.

Another other thing to look into is to make sure the MaxClients in your Apache config is set appropriately low. It tends to default to 150 -- which is pretty high, especially for a VPS.

One other thought is that you can setup a limit of how many processes a given Virtual Server can have running at any moment. You can do that in Administrative Options -> Edit Resource Limits -- you can set "Maximum number of processes".

-Eric

Mon, 06/07/2010 - 19:52
ZeroT3K

http://pastebin.com/MbAU8gWe

Currently, I'm assuming that traffic to the site is minimal at the moment. The main site itself is a photo blog that is normally bombarded on days we upload photos from people logging in to see previous events and such. During these times I'm normally sitting very close to the "Red Zone" in Parallel's Power Panel.

For a server running virtualmin with 1GB dedicated + 1GB burst, how many max clients should I have? I don't want to set it too low where connections start to be denied, but at the same time I don't want the server biting more than it can chew.

Thanks again for the help, Eric

Cory

Mon, 06/07/2010 - 20:21
andreychek

Well, the question is -- how many Apache processes can you run before you run out of RAM?

That's dependent on the amount of RAM you have, as well as the amount of RAM each Apache process and PHP process takes up.

If MaxClients is set too high, your server can die, as you experienced. If it's set to low, it may end up rejecting some connections -- or at least making them wait until a process is available.

So, I'd suggest erroring on the side of caution :-)

How to set MaxClients is a bit of an art... but where I'd suggest starting is to:

  • Look at how much RAM is free when Apache isn't running (assume you have 1GB of total RAM, don't include your burst)

  • Determine how much RAM each Apache process uses (by viewing the memory size in the "ps" output)

  • Use that info to figure out how many Apache processes can run before you run out of RAM

The above is a bit of an over simplification, but it's a good starting place.

So if you have 700MB of available RAM, and each Apache process takes 20MB, you're looking at a limit of 35 Apache processes that can run at once (700 / 35). If more Apache processes start than you have available RAM, you'll run into significant problems :-)

You do seem a bit memory constrained -- your burstable RAM isn't guaranteed, and you don't have swap, so as things stand today, you only have about 220MB of RAM to play with according to your current "free" output. I'd definitely go through and do what you can to reduce memory consumption.

-Eric

Mon, 01/06/2014 - 07:36
wocul

you can also just download & run the "apachetuner.sh" script which will help you come up with suitable values: https://github.com/gusmaskowitz/apachetuner

Mon, 01/06/2014 - 11:32
Chris_C

Thanks wocul for this.

EDIT: apachetuner is for redhat/centos only. Fails on debian/ubuntu.

I see from the apachetuner github that it's superseded by "apachebuddy" which was written by a proper apache expert. https://github.com/gusmaskowitz/apachebuddy.pl

However I'm getting a perl crash bug running apachebuddy on debian:

# Apache Buddy v 0.3 #

Gathering information... We are checking the service running on port 80 The process listening on port 80 is /usr/sbin/apache2 The process running on port 80 is Apache/2.2.16 (Debian) Apache has been running 0d 0h 10m 22s The full path to the Apache config file is: /etc/apache2/apache2.conf Apache is using prefork model

Examining your Apache configuration... Uncaught exception from user code: Unable to open file: /etc/apache2/conf.d/* at apachebuddy.pl line 91 main::find_included_files('ARRAY(0x5f03280)', 'ARRAY(0x5f020e0)', '/etc/apache2') called at apachebuddy.pl line 65 main::build_config_array('/etc/apache2/apache2.conf', '/etc/apache2') called at apachebuddy.pl line 1001

Any suggestions?

Topic locked