4

This question already has an answer here:

I want to set an optimum value for MaxClient in apache for my production server. What are the parameters that I should consider while calculating this value ?

marked as duplicate by Jenny D, womble Oct 5 '17 at 23:24

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

Refer to the Apache Performance Tuning guide.

Quote

"You can, and should, control the MaxClients setting so that your server does not spawn   
so many children it starts swapping. This procedure for doing this is simple: determine 
the size of your average Apache process, by looking at your process list via a tool such 
as top, and divide this into your total available memory, leaving some room for other 
processes."
7

Complementing @Sameer answer, I read a lot of this theme and what I do is this:

  1. Get the Apache process average size:

    server# ps -ylC apache2 --sort:rss
    
    S   UID   PID  PPID  C PRI  NI   RSS    SZ WCHAN  TTY          TIME CMD
    S    33  6233 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6250 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6278 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2  
    S    33  6280 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2 
    S    33  6577 25895  0  80   0  7432 72802 poll_s ?        00:00:00 apache2
    S    33  6299 25895  0  80   0  7772 72891 poll_s ?        00:00:00 apache2
    S    33  6295 25895  0  80   0  7776 72891 poll_s ?        00:00:00 apache2
    

    As you can see in the SZ column my Apache process size is about 73 MB

  2. Make the following formula

    MaxClients: ((Total_Memory)(1024)(MB) - Other_processes_memory) / 73
    

    For Example: I have 16 GB RAM, I might leave free 2 GB for any other processes

    MaxClients: ((16*1024) - 2048) / 73
    MaxClient: 196 
    

This is what I use & my server is going great.

You have to consider that my Apache processes are a little heavy, so you could have processes about 50 MB or less.

Regards,

Your SZ is slightly the same for all Apache processes. In my case I have values between 23 and 212 Mb

enter image description here

What value should I use in your formula ?

By the way in Apache 2.4 MaxClients has been renamed to MaxRequestWorkers. Is your formula still valid for this new parameter ?

Regards

  • Not necessarily a global solution as there are many many other factors and programming to consider. – mdpc May 28 '14 at 16:27
3

The answer from tachomi is not overly comprehensive, but seems like a reasonable way to begin estimating.

In addition to that, this will help you to figure out some of the resources Apache is currently consuming:

ps aux | grep 'httpd' | awk '{count = NR;} END {print count " Apache processes";}'
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{sum += $1;} END {print sum " MB total mem usage";}'
ps aux | grep 'httpd' | awk '{print $6/1024;}' | awk '{avg += ($1 - avg) / NR;} END {print avg " MB avg mem usage";}'

Not the answer you're looking for? Browse other questions tagged or ask your own question.