Max Clients Causing Slow Server?

After taking the advice in the linode library and on this forum, I've lowered my max clients significantly (I've experimented with 12 and 15) and it has successfully kept my server from crashing.

My question is can having such a low max clients cause your server to be really slow?

Many of my users are complaining of slow load times of over 20 seconds. A few are basically getting timed out, or clicking away before the site loads. Could this be caused by max clients or is it something else?

Here's my site url: http://thewritepractice.com

Thanks!

5 Replies

Have you disabled KeepAlives?

-Chris

Yes, I set "KeepAlive Off".

Now that things are stable, you can possibly adjust your MaxClients setting upwards. First, find out how much memory each Apache process is using with top.

top - 23:06:58 up 24 days, 23:23,  1 user,  load average: 0.24, 0.53, 0.44
Tasks:  97 total,   2 running,  95 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.8%us,  0.2%sy,  0.0%ni, 97.9%id,  1.1%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:    524512k total,   459528k used,    64984k free,    19512k buffers
Swap:   262136k total,       48k used,   262088k free,   285840k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND            
 8597 www-data  15   0 24240 7368 3452 S    1  1.4   0:02.53 apache2            
 8601 www-data  15   0 24052 7252 3408 S    1  1.4   0:00.90 apache2            
 8562 www-data  15   0 24936 8184 3512 S    0  1.6   0:05.41 apache2            
 1434 mysql     23   0 61136  39m 4708 S    0  7.7 268:55.03 mysqld             
 8574 www-data  15   0 24004 7256 3452 S    0  1.4   0:03.30 apache2            
 8581 www-data  16   0 24780 7780 3432 S    0  1.5   0:05.31 apache2            
 8657 www-data  16   0 23972 7124 3364 S    0  1.4   0:00.02 apache2            
 8655 www-data  15   0 25288 8248 3408 S    0  1.6   0:00.12 apache2
...

The RES value is the physical memory used by the process, and SHR is memory potentially shared with other processes. So RES minus SHR gives you a rough idea of how much memory each additional apache2 process will need (in this case, around to 3800 to 4800 KB or 3.7 to 4.7 MB).

Now you need to determine how much additional memory is available on your system.

$ ps aux | grep -c '^www-data' ; free -m
11
             total       used       free     shared    buffers     cached
Mem:           512        444         67          0         18        280
-/+ buffers/cache:        145        367
Swap:          255          0        255

The ps aux | grep -c '^www-data' tells you how many Apache processes are running (on Debian and Ubuntu servers; on CentOS use ps aux | grep -c '^apache'). In this case, there are 11. As explained by http://www.linuxatemyram.com/ , the free command shows us we have 367 MB unused. Doing 367 divided by 4.7 tells us we could potentially run 78 more processes, for a total MaxClients setting of 89.

Of course, you probably are running other services (e-mail, database, etc.) on this machine and don't want to fill the memory completely with Apache processes, so leave yourself a cushion. I have MaxClients set to 60 on this example machine and that keeps it from running into swap.

You can check this by running free -m during a time when your server is getting lots of traffic (either naturally, or you can use a tool like ab to make it busy) and seeing that you still have some memory left in the "free" column.

Also, your site itself may just be slow. Certain Wordpress plugins (or combinations of plugins) can cause this. Some people report improvement with caching plugins, but take note that they use memory too, so you may have to adjust MaxClients back downward. It's a balancing act.

Note that readers are also downloading the following CSS and javascript files:

/wp-content/themes/Tribe/style.css

/wp-content/plugins/contact-form-7/includes/css/styles.css?ver=3.3.1

/wp-content/plugins/jetpack/modules/widgets/widgets.css?ver=20121003

/wp-content/plugins/jetpack/modules/sharedaddy/sharing.css?ver=2.0.2

/wp-content/plugins/wp-greet-box/css/style.css?ver=3.4.2

/wp-includes/js/jquery/jquery.js?ver=1.7.2

/wp-content/plugins/wp-greet-box/js/functions.js?ver=3.4.2

/wp-content/plugins/wp-greet-box/js/js-mode.js?ver=3.4.2

/wp-content/themes/Tribe/js/jquery.js

/wp-content/themes/Tribe/js/site.js

/wp-content/themes/Tribe/js/lavalamp.js

/wp-content/plugins/contact-form-7/includes/js/jquery.form.min.js?ver=3.18

/wp-content/plugins/contact-form-7/includes/js/scripts.js?ver=3.3.1

/wp-content/themes/genesis/lib/js/menu/superfish.js?ver=1.4.8

/wp-content/themes/genesis/lib/js/menu/superfish.args.js?ver=1.8.2

…plus additional scripts from Google, Twitter, Facebook, Disqus, etc. I haven't bothered checking how much this all adds up to, but it might be slowing things down for people.

Looking at that site, my browser downloaded 77 objects totaling 1.25 MB and it took about 7.15 seconds. The page itself was only 10.2 KB in 2.41 seconds, so the rest is just… cruft.

Your browser's developer tools will have a "Network" tab which will show this in real time.

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct