Help - Search - Members - Calendar
Full Version: HOWTO Tune Apache and PHP for Speed on Unix
The Planet Forums > System Administration > HOWTOs
Pages: 1, 2
aussie
If you haven't read this document i highly recommend that you do. Its give some great tips on tuning PHP on an Apache web server. It may just help bring down the loads on some peoples web server that i have been reading about in the forums.

http://php.weblogs.com/tuning_apache_unix

Also, consider adding the directive;

output_handler = ob_gzhandler

to your php.ini scripts. It compresses outgoing html and dynamic contect outbound which mod_gzip does not do. If your using sub.domains i would highly recommend that you test your links, especially if your linking to a forum, after adding the above directive to php.ini. Don't forget to /etc/rc.d/init.d/httpd restart after doing so.

Since im running a powerful server, dual pentium with 1.5gb memory i can afford the luxury of tweaking my httpd.conf file by increasing the following values: You should test this on your server if you decided to make the changes. I have noticed a big decrease in cpu usage according to my mrtg logs over a 12hr period. I then set these options back to the default and noticed a big increase in LOAD proveing that the default installation on our servers is definately not the optimum setting and not tweaked for best performance:

Find the following in httpd.conf

On Ensim these are the default values:

MaxClients: 150
StartServers: 5
MinSpareServers: 5
MaxSpareServers: 10
#MaxRequestsPerChild: 30

For larger, busier sites, values close to the following might be better:

MaxClients: 256
StatServers: 5
MinSpareServers 32
MaxSpareServers 64
MaxRequestsPerChild: 0

Dont forget to restart httpd

If you have some kind of monitor source like mrtg etc keep and eye on your cpu loads, memory consumption etc. As i said i noticed a significant decrease with my max cpu being 11 and 12% utilization over a period of 6 hours.

Dont forget to keep a copy of your httpd.conf incase you need it.

Happy surfing!
aussie
WOW! i cannot get the above links to be recognized. Whats up with that?

Ok, do this, cut and paste the above document

http://php.weblogs.com/tuning_apache_unix

into your browser. The last three words in the link look like this: tuning_apache_unix there are UNDERSCORES.

Vbulletin doesnt recognize underscores?
mouse
worked for me.. Mouse
Albo
Thanks for the info. I have a question though.

Do you keep KeepAlive on what value do you use for MaxKeepAliveRequest?

I just tested it and the load is 50% down.
aussie
QUOTE
Originally posted by Albo
Thanks for the info. I have a question though.

Do you keep KeepAlive on what value do you use for MaxKeepAliveRequest?

I just tested it and the load is 50% down.


Wow, thats sound great! Btw, leave it at 100
daveman692
Thanks for finding this!

I am interested in using lingerd since my server only serves php pages but am not sure if I can because of ensim.
jaume
QUOTE
Originally posted by aussie

MaxClients: 256
StatServers: 5
MinSpareServers 32  
MaxSpareServers 64
MaxRequestsPerChild: 0


Why only 256 maxclients?? ... I have all my p4 1gb ram with 350 maxclients and difference about speed at peak hour is huge. CPU load average is keeping stable under 3.

I would be always reaching the maxclients limit if I set it lower than 300 and httpd requests would be queued and server slowed.
Albo
God, Am I Happy!

Look at this beaty:

3:04am up 39 min, 1 user, load average: 0.07, 0.06, 0.18


Not easy to keep it low with all my sites being dynamic php/mysql sites. I have been testing and reading a lot on how to optimize apache and the things I have learned from experience are:

1. KeepAlive Off

If you have KeepAlive On, this is a server killer!!! That is why I asked the question above about KeepAlive.

2. mod_gzip is a MUST !

I was having problems with mod_gzip because as I found out (the hard way) VBulletin has its own compression thingie going and it is not compatible with mod_gzip. If you have mod_zgip loaded, I recommend you turn output compression from admin CP in vbulletin OFF ! If you keep this on, your load will sky rocket and you will blame it on mod_gzip which is not the case.

The second thing with mod_gzip, (I didn't know this) it doesn't compress by default the dynamic out generated by PHP or perl. The only way to make this happen is by redirecting PHP output to mod_gzip by making the change to /etc/php.ini :

QUOTE
; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to "ob_gzhandler", output will be
; transparently compressed for browsers that support gzip or deflate encoding.
; Setting an output handler automatically turns on output buffering.
output_handler = ob_gzhandler



3. Lingering httpd processes

Keep an eye on the number of TIME_WAIT processes from netstat. I have yet to figure out a wait to keep the number low. I have monitored the server and I have noticed that the load is directly related to the number of TIME_WAIT. I use the script below to monitor httpd/mysql/network on my box. It will tell you the number of each process in total. I got it from vbulletin.com forums and you can copy it from here .

You can use it to monitor your server along with /server-status generated by apache. This script will give you stats not just listed processes.

Keep the discussion rolling on this topic by sharing your tips and tricks on optimizing apache.
Albo
QUOTE
Originally posted by jaume


Why only 256 maxclients?? ... I have all my p4 1gb ram with 350 maxclients and difference about speed at peak hour is huge. CPU load average is keeping stable under 3.

I would be always reaching the maxclients limit if I set it lower than 300 and httpd requests would be queued and server slowed.


According to Apache.org documentation, the max allowed value for MaxClients is 256 by default. This is used I think as a limit to the number of resourses apache should consume in the server. It prevents apache from taking the server down if it is spinning out of control due to the high load. When you increase it over 256, basically you you are ignoring this top limit for apache.

Another thing, the number of the httpd processes running doesn't necessary correspond to the number of clients. Don't confuse that. How do you know that you would reach the limit of 256 if you set MaxClients to that?
aussie
QUOTE
Originally posted by jaume


Why only 256 maxclients?? ... I have all my p4 1gb ram with 350 maxclients and difference about speed at peak hour is huge. CPU load average is keeping stable under 3.

I would be always reaching the maxclients limit if I set it lower than 300 and httpd requests would be queued and server slowed.


The MaxClients directive sets the limit on the number of simultaneous requests that can be supported; not more than this number of child server processes will be created. To configure more than 256 clients, you must edit the HARD_SERVER_LIMIT entry in httpd.h and recompile. If you have set this higher than 256, and not recompiled, then any connections above this will simply be queued.
aussie
QUOTE
Originally posted by Albo
God, Am I Happy!

Look at this beaty:  

3:04am  up 39 min,  1 user,  load average: 0.07, 0.06, 0.18


Not easy to keep it low with all my sites being dynamic php/mysql sites. I have been testing and reading a lot on how to optimize apache and the things I have learned from experience are:

1. KeepAlive Off

If you have KeepAlive On, this is a server killer!!! That is why I asked the question above about KeepAlive.

2. mod_gzip is a MUST !

I was having problems with mod_gzip because as I found out (the hard way) VBulletin has its own compression thingie going and it is not compatible with mod_gzip. If you have mod_zgip loaded, I recommend you turn output compression from admin CP in vbulletin OFF ! If you keep this on, your load will sky rocket and you will blame it on mod_gzip which is not the case.

The second thing with mod_gzip, (I didn't know this) it doesn't compress by default the dynamic out generated by PHP or perl. The only way to make this happen is by redirecting PHP output to mod_gzip by making the change to /etc/php.ini :




3. Lingering httpd processes

Keep an eye on the number of TIME_WAIT processes from netstat. I have yet to figure out a wait to keep the number low. I have monitored the server and I have noticed that the load is directly related to the number of TIME_WAIT. I use the script below to monitor httpd/mysql/network on my box. It will tell you the number of each process in total. I got it from vbulletin.com forums and you can copy it from here .

You can use it to monitor your server along with /server-status generated by apache. This script will give you stats not just listed processes.

Keep the discussion rolling on this topic by sharing your tips and tricks on optimizing apache.


Acutually, Apache recommends that you KeepAlive On and set your MaxKeepAliveRequests to a higher number than the default 100 to say 500 for maxium performance.
jaume
QUOTE
Originally posted by Albo
How do you know that you would reach the limit of 256 if you set MaxClients to that?

You'll know when your server response become slow and you find in your messages log that "Apache reached maxclients .. consider raising it ...".

Right now I have maxcliennts to 350 and server is running great:

10:10pm up 129 days, 22:11, 1 user, load average: 0.99, 0.85, 0.74
392 processes: 389 sleeping, 2 running, 1 zombie, 0 stopped

If I lower maxclients to 256 or whatever lower 300 the server starts to crawl and maxclients are reached as I can see in the log:

10:17pm up 129 days, 22:18, 1 user, load average: 2.31, 2.95, 2.11
303 processes: 298 sleeping, 4 running, 1 zombie, 0 stopped

So if you run a busy server and you reach maxclients try to raise them a little. 350 is ok for my pentium4's 1 gb ram running php + mysql applications. I have one amdXP 1900 with 400 maxclients running great and crawling if I set them under 300.

So the facts are the facts and I'm not having any problem with apache icon_smile.gif
jaume
QUOTE
Originally posted by aussie
The MaxClients directive sets the limit on the number of simultaneous requests that can be supported; not more than this number of child server processes will be created. To configure more than 256 clients, you must edit the HARD_SERVER_LIMIT entry in httpd.h and recompile. If you have set this higher than 256, and not recompiled, then any connections above this will simply be queued.


I am not an Apache expert but I see my server reacting when I raise maxclients over the 256. I don't know with what HARD_SERVER_LIMIT has been aoache complied.

If we assume that our apache has been compiled with the /usr/include/apache/httpd.h , I see that is compiled with 2048 and not using the default:
CODE
#ifndef HARD_SERVER_LIMIT

#ifdef WIN32

#define HARD_SERVER_LIMIT 1024

#else

#define HARD_SERVER_LIMIT 2048

#endif

#endif


Someone know how can we find out what HARD_SERVER_LIMIT do we have compiled in? or we assume it has been compiled with 2048 ....
martinjr76
mine also reacted badly, now quite lagging due to heavy traffics from my vbulletin forum icon_sad.gif
anders
QUOTE
Originally posted by jaume

You'll know when your server response become slow and you find in your messages log that "Apache reached maxclients .. consider raising it ...".

Right now I have maxcliennts to 350 and server is running great:

10:10pm  up 129 days, 22:11,  1 user,  load average: 0.99, 0.85, 0.74
392 processes: 389 sleeping, 2 running, 1 zombie, 0 stopped

If I lower maxclients to 256 or whatever lower 300 the server starts to crawl and maxclients are reached as I can see in the log:

10:17pm  up 129 days, 22:18,  1 user,  load average: 2.31, 2.95, 2.11
303 processes: 298 sleeping, 4 running, 1 zombie, 0 stopped

So if you run a busy server and you reach maxclients try to raise them a little. 350 is ok for my pentium4's 1 gb ram running php + mysql applications. I have one amdXP 1900 with 400 maxclients running great and crawling if I set them under 300.

So the facts are the facts and I'm not having any problem with apache icon_smile.gif



jaume...Can i ask you what you set the other settings to with 400 at maxclients?


MaxClients: 400
StatServers:
MinSpareServers:
MaxSpareServers:
MaxRequestsPerChild:
MaxKeepAliveRequests:

Im trying to find the right combination here icon_smile.gif

thanks a lot icon_smile.gif
jaume
QUOTE
Originally posted by anders



jaume...Can i ask you what you set the other settings to with 400 at maxclients?


MaxClients: 400  
StatServers:  
MinSpareServers:  
MaxSpareServers:  
MaxRequestsPerChild:  
MaxKeepAliveRequests:

Im trying to find the right combination here icon_smile.gif

thanks a lot icon_smile.gif


For my XP 1900 1 gb ram I have:

MaxClients: 400
StartServers: 5
MinSpareServers: 5
MaxSpareServers: 10
MaxRequestsPerChild: Unset
MaxKeepAliveRequests:100

I have this server stable with 2 - 3 load averages and some more at peak hour. This particular server runs some popular plain HTML sites and a PHP adserver serving over 1.4 million banners daily.

Processes are always between 400 and 460 and have had no problems.

Take a look at how heavy are your processes and tru different combos icon_smile.gif
Albo
I will share this info with you, but don't assume to get the same result I get from these apache settings. From almost 8 months that I have been playing with apache settings I have come to the conclusions:

1. KeepAlive is a resource killer and from now on it will be off

2. Increasing the number of Maxclients is not a good idea. Keeping this number low in the 100-150 range will keep the load under control.

3. MaxKeepAliveRequests=100 was my best bet.

4. MaxRequestsPerChild=1000 or higher will make a big difference on Linux servers.

Here are my httpd.conf settings:

Timeout 300
KeepAlive Off
MaxKeepAliveRequests 100
KeepAliveTimeout 30
MinSpareServers 8
MaxSpareServers 20
StartServers 5
MaxClients 150
MaxRequestsPerChild 1000
acidbox
I took your advice and tried to add this to my php.ini:

output_handler = ob_gzhandler

Now, everytime you click a link, it acts as if you are trying to "download" the page. It prompts you with the internet explorer Save File As Dialogue. has anyone had this, and know what to do?

thanks...
EOC_Jason
Using "output_handler = ob_gzhandler" uses PHP's zlib to compress your files, not mod_gzip which is the apache module. It will compress php, cgi, pl, and any other dynamic output just fine, you just have to specify it with an "include" line in the httpd.conf file. I did a little comparison with vbulletin files and other's and mod_gzip seemes to compress slightly better than using zlib.

Also, make sure you use one or the other, using both will only cause increased server load.

QUOTE
Originally posted by Albo
God, Am I Happy!

2. mod_gzip is a MUST !

I was having problems with mod_gzip because as I found out (the hard way) VBulletin has its own compression thingie going and it is not compatible with mod_gzip. If you have mod_zgip loaded, I recommend you turn output compression from admin CP in vbulletin OFF ! If you keep this on, your load will sky rocket and you will blame it on mod_gzip which is not the case.

The second thing with mod_gzip, (I didn't know this) it doesn't compress by default the dynamic out generated by PHP or perl. The only way to make this happen is by redirecting PHP output to mod_gzip by making the change to /etc/php.ini :

acidbox
how do i tell if i have mod_gzip running?
Albo
EOC_Jason:

; You can redirect all of the output of your scripts to a function. For
; example, if you set output_handler to "ob_gzhandler", output will be
; transparently compressed for browsers that support gzip or deflate encoding.
; Setting an output handler automatically turns on output buffering.
output_handler = ob_gzhandler


It doesn't explicitely say that it uses zlib to compress files. I have to look this up at php.net. My zlib is off in /etc/php.ini so I don't think I run that risk.

; Transparent output compression using the zlib library
; Valid values for this option are 'off', 'on', or a specific buffer size
; to be used for compression (default is 4KB)
;
; Note: output_handler must be empty if this is set 'On' !!!!
;
zlib.output_compression = Off

I think php compresses its output either using mod_gzip ose zlib but not both ways.
BoiTaiTui
QUOTE
Originally posted by aussie


http://php.weblogs.com/tuning_apache_unix

Also, consider adding the directive;  

output_handler = ob_gzhandler

Find the following in httpd.conf


MaxClients: 256
StatServers: 5
MinSpareServers 32  
MaxSpareServers 64
MaxRequestsPerChild: 0

! [/B]

I change the httpd.conf to the above. It didn't seem to optimize the server, but it also increases the server load and memory usage. I have ensim3.1.1 cerelon 1.3 526 RAM.

I do agree that ob_gzhandler help a lot, but some php won't work with that. When go the page with some.php, it is not displace instead the brower as user to download the page like a zip files. Therefore I have removed it.
HollyRidge
Having the same problem... Especially with invision board from what I have seen so far seems to give me the most trouble. Also zlib is off in php.ini but I do have mod_gzip installed. Any ideas on what is causing this??

QUOTE
Originally posted by acidbox
I took your advice and tried to add this to my php.ini:

output_handler = ob_gzhandler

Now, everytime you click a link, it acts as if you are trying to "download" the page.  It prompts you with the internet explorer Save File As Dialogue.  has anyone had this, and know what to do?

thanks...
Albo
QUOTE
Originally posted by HollyRidge
Having the same problem... Especially with invision board from what I have seen so far seems to give me the most trouble. Also zlib is off in php.ini but I do have mod_gzip installed. Any ideas on what is causing this??



Check the options of your board to see if you have selected a "gzip output" option. This should be turned off cause once you activate mod_gzip module in your httpd.conf all the site on your machine serve gziped pages.

I know VBulletin that I use has such an option. Once you turn it off everything should run smooth. Some boards like to compress the output on their own using other methods which causes the problem.
AC Design
Hey guys -

My Duron 1GHz/512MB box has Plesk 2.0, not Ensim... but I'm wondering if any of this stuff applies to me as well..... my server is "not" working too well lately (average load always well over 1.0 - and spikes often around 8+ and sometimes even haywire at 60+), and I think things are somehow vastly misconfigured (by default - I didn't change anything myself, other than making an /etc/my.cnf file)..... Mind if I post my config and hopefully get feedback? If there isn't supposed to be any difference in these between Ensim and Plesk, mine are "seriously" jacked up I think haha.... but I want to check first.

Timeout 300
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 15
MinSpareServers 5
MaxSpareServers 10
StartServers 5
MaxClients 2048
MaxRequestsPerChild 0
HostnameLookups Off

The server runs a lot of mysql (one main site is a popular vbulletin forum) and I would estimately around 15,000+ unique visitors/day overall to all sites on the server.

The my.cnf file has the following (recommended to me by vbulletin support):
[client]
port = 3306
socket = /tmp/mysql.sock

[mysqld]
port = 3306
socket = /tmp/mysql.sock
skip-locking
set-variable = max_connections=600
set-variable = key_buffer=16M
set-variable = myisam_sort_buffer_size=64M
set-variable = join_buffer=2M
set-variable = record_buffer=2M
set-variable = sort_buffer=3M
set-variable = table_cache=1024
set-variable = thread_cache_size=256
set-variable = wait_timeout=7200
set-variable = connect_timeout=10

[safe_mysqld]
open_files_limit=8192

[mysqldump]
quick
set-variable = max_allowed_packet=64M

[myisamchk]
set-variable = key_buffer=64M
set-variable = sort_buffer=64M
set-variable = read_buffer=16M
set-variable = write_buffer=16M


I know I need more RAM (well a new server entirely would be nice hehe)... but I have a feeling I can get a lot more mileage with what I already have, if it's just configured properly icon_biggrin.gif

Thanks in advance.
EOC_Jason
That seems a little large for the myisam_sort_buffer_size, check how full the cache is, I think you can chop it down to at least half... If your system has no free ram is has to swap to disk a lot your server load will be a lot higher...

QUOTE
Originally posted by AC Design

[client]  
port = 3306  
socket = /tmp/mysql.sock  

[mysqld]  
port = 3306  
socket = /tmp/mysql.sock  
skip-locking  
set-variable = max_connections=600  
set-variable = key_buffer=16M  
set-variable = myisam_sort_buffer_size=64M  
set-variable = join_buffer=2M  
set-variable = record_buffer=2M  
set-variable = sort_buffer=3M  
set-variable = table_cache=1024  
set-variable = thread_cache_size=256  
set-variable = wait_timeout=7200  
set-variable = connect_timeout=10  

[safe_mysqld]  
open_files_limit=8192  

[mysqldump]  
quick  
set-variable = max_allowed_packet=64M  

[myisamchk]  
set-variable = key_buffer=64M  
set-variable = sort_buffer=64M  
set-variable = read_buffer=16M  
set-variable = write_buffer=16M
Mike2522
Thank You for this thread! really needed it icon_smile.gif
phenx
i was using this config before, with only 512mb of ram, and it was increasing the load. (~2 average)

Ive just upgraded to 1Gb of ram, and the load average is around 0.3

w00t thx aussie
linenoyz
Great info in this thread. Thanks to all of you! icon_biggrin.gif
burkul
KeepAlive directive is very important here. If you want speed in persistent connections you should keep this "On". In fact KeepAliveTimeout is much more important. Keeping this low will result in increased # of TCP connections but shorter life in each TCP connection. I use ;

KeepAlive On
KeepAliveTimeout 10

meaning , a visitor comes to our website and uses different TCP connection in each 10 seconds while he/she is on our site.

I must recommend you keep KeepAlive On

cheers
aussie
QUOTE
Originally posted by [iG]
i was using this config before, with only 512mb of ram, and it was increasing the load. (~2 average)

Ive just upgraded to 1Gb of ram, and the load average is around 0.3

w00t thx aussie


How did you upgrade your memory and on what? Is there a special going?
naramation
Just a question..

Will any of thses methods speed up perl scripts very much? I have been looking for a way to speed up some of my scripts for some time...

Oh, one more thing, if I want to install the IonCube PHP Accelerator, should I turn off gzip or change the output_handler?

Thanks icon_smile.gif
Albo
QUOTE
Originally posted by naramation
Just a question..

Will any of thses methods speed up perl scripts very much?  I have been looking for a way to speed up some of my scripts for some time...

Oh, one more thing, if I want to install the IonCube PHP Accelerator, should I turn off gzip or change the output_handler?

Thanks icon_smile.gif


If you want to speed up perl scripts, either throw some new ram sticks at your box, or optimize the code so that it doesn't hold resources for long, or check for any memory leak. There isn't much else you can do about perl scripts.

PHPA onlye speeds up php scripts by keeping a cache of pre-compiled scripts that you use. You save some CPU cycles by not compiling your scripts on every single hit.

For compression, if you have a very busy site, I would not recommend you to use mod_gzip. If your server doesn't handle a lot of traffic, you can go ahead and enable mod_gzip. However, keep in min that if you enable mod_gzip, you don't need to change the output_handler in php.ini, and vice-versa. Basically, they do the same exact thing.
Ropey
183 processes: 179 sleeping, 3 running, 1 zombie, 0 stopped
CPU states: 2.1% user, 1.7% system, 0.0% nice, 96.0% idle
Mem: 1012292K av, 904644K used, 107648K free, 1368K shrd, 22840K buff
Swap: 530104K av, 171056K used, 359048K free 294640K cached

it has started using it's swap and don't like that at all.
also 900mb of the total of 1 GB ram.

is there anyway to free up more ram so he doesn't need to use the swap file either?

here are my processes:

PID USER PRI NI SIZE RSS SHARE STAT %CPU %MEM TIME COMMAND
24178 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24282 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24283 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24284 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24285 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24286 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
24287 root 5 -10 11788 11M 2300 S < 0.0 1.1 0:00 python2.1
28527 apache 9 0 10848 10M 8896 S 0.0 1.0 0:00 httpd
28530 apache 11 0 10748 10M 9108 S 0.5 1.0 0:00 httpd
28540 apache 9 0 10744 10M 9108 S 0.2 1.0 0:00 httpd
28539 apache 9 0 10644 10M 9064 S 0.2 1.0 0:00 httpd
28549 apache 9 0 10052 9.8M 9072 S 0.0 0.9 0:00 httpd
28529 apache 9 0 10036 9.8M 9112 S 0.0 0.9 0:00 httpd
28534 apache 9 0 9808 9808 9128 S 0.0 0.9 0:00 httpd
28536 apache 9 0 9796 9796 9080 S 0.0 0.9 0:00 httpd
28550 apache 9 0 9312 9312 9000 S 0.0 0.9 0:00 httpd
28532 apache 9 0 9296 9296 8984 S 0.0 0.9 0:00 httpd
28538 apache 9 0 9296 9296 8976 S 0.0 0.9 0:00 httpd
28528 apache 9 0 9292 9292 8984 S 0.0 0.9 0:00 httpd
28531 apache 14 0 9292 9292 8984 S 0.4 0.9 0:00 httpd
28537 apache 9 0 9292 9292 8976 S 0.4 0.9 0:00 httpd
28548 apache 9 0 9292 9292 8976 S 0.0 0.9 0:00 httpd
28695 apache 9 0 9292 9292 8988 S 0.5 0.9 0:00 httpd
28696 apache 9 0 9292 9292 8988 S 0.0 0.9 0:00 httpd
28514 root 7 0 9136 9136 8856 S 0.0 0.9 0:01 httpd
24267 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
24269 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
24270 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
24271 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
28586 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
28685 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
28689 mysql 15 10 7040 7040 2212 S N 0.0 0.6 0:00 mysqld
12156 root 8 0 7884 3600 2012 S 0.0 0.3 0:06 psad
24173 nobody 5 -10 3428 3400 3016 S < 0.0 0.3 0:00 ocwhttpd
24174 nobody 5 -10 3400 3396 3016 S < 0.0 0.3 0:00 ocwhttpd
24177 nobody 5 -10 3352 3352 3016 S < 0.0 0.3 0:00 ocwhttpd
24281 nobody 5 -10 3352 3352 3016 S < 0.0 0.3 0:00 ocwhttpd
24175 nobody 5 -10 3348 3336 3004 S < 0.0 0.3 0:00 ocwhttpd
24176 nobody 5 -10 3332 3228 2912 S < 0.0 0.3 0:00 ocwhttpd
23231 named 5 -10 3076 3076 1992 S < 0.0 0.3 0:00 named
23232 named 5 -10 3076 3076 1992 S < 0.0 0.3 0:00 named
23233 named 5 -10 3076 3076 1992 S < 0.0 0.3 0:00 named
23234 named 5 -10 3076 3076 1992 S < 0.0 0.3 0:00 named
23238 named 5 -10 3076 3076 1992 S < 0.0 0.3 0:00 named
24298 nobody 5 -10 3060 3052 2928 S < 0.0 0.3 0:00 ocwhttpd
24171 root 5 -10 2964 2960 2860 S < 0.0 0.2 0:00 ocwhttpd
3099 postgres 9 0 3120 2760 2272 S 0.0 0.2 9:32 postmaster
26959 root 9 0 2600 2600 1888 S 0.0 0.2 0:00 sendmail
24172 nobody 5 -10 2688 2520 2348 S < 0.0 0.2 0:00 ocwhttpd
18751 admin45 9 0 2336 2280 2064 S 0.0 0.2 0:00 sshd


thanks,

Ropey
zerokarma
I tried adding the line:

output_handler = ob_gzhandler

to php.ini

but when I do httpd stops working, is there a specific spot I need to add it in the file?
kris1351
I have a question about output_handler = ob_gzhandler, if you are using Zend is this a null addition? We have several high use php sites that are hitting some resource highs. They have gotten busy over the last month and we would like to tune as much as we can.
Ronny
Shouldn't MaxRequestsPerChild: be set to something liek 5000 or 10,000 to prevent any memory leaks?
Daijoubu
It's not only about using GZIP
It's also about using buffering
Having bunch of echo/print and not buffering would requier many system calls
ob_start + many echos is actualy faster than adding the content to print to a variable and flush it at once

If you use ob_gzhandler
Make sure to lower the compression level down to 1 from the default 6 (-1) which use more CPU for little saving

zlib.output_compression_level = 1

As for Keep-Alive, keep it on for the shake of the end user, the overhead for making bunch of connections is not even funny. Just lower the timeout like burkul said, even something like 5secs should do the job

If your site is that big, turn it off and use another web server for the statics files and leave Keep-Alive on it (TUX, Boa, thttpd, LiteSpeed, etc...)
samasa
QUOTE
Originally posted by jaume
I am not an Apache expert but I see my server reacting when I raise maxclients over the 256. I don't know with what HARD_SERVER_LIMIT has been aoache complied.

If we assume that our apache has been compiled with the  /usr/include/apache/httpd.h ,  I see that is compiled with 2048 and not using the default:
CODE
#ifndef HARD_SERVER_LIMIT

#ifdef WIN32

#define HARD_SERVER_LIMIT 1024

#else

#define HARD_SERVER_LIMIT 2048

#endif

#endif
 

Someone know how can we find out what HARD_SERVER_LIMIT do we have compiled in? or we assume it has been compiled with 2048 ....


Can somebody tell me why appear me two lines: "#define HARD_SERVER_LIMIT 2048"

is this bad or is fine?
Here is my configuration:



#ifndef HARD_SERVER_LIMIT
#ifdef WIN32
#define HARD_SERVER_LIMIT 1024
#elif defined(NETWARE)
#define HARD_SERVER_LIMIT 2048
#else
#define HARD_SERVER_LIMIT 2048
#endif
#endif
lordo
Although the topic is quite old, thanks to everybody here for the useful information that helped me end a one month nightmare of high load average! Modifications to my.cnf and php.ini and httpd.conf are really important. KeepAlive should stay off icon_smile.gif

Thanks.
JohnnyUtah
Awsome post...
Never seen my server that fast...
Gladius
This thread is a bit outdated, hopefully aussie's still around... this is what I have in my httpd.conf on a fresh install of Ensim 4:



StartServers 8
MinSpareServers 5
MaxSpareServers 20
MaxClients 150
MaxRequestsPerChild 1000


# worker MPM
StartServers 8
MaxClients 150
# MinSpareThreads: minimum number of worker threads which are kept spare
# MaxSpareThreads: maximum number of worker threads which are kept spare
# ThreadsPerChild: constant number of worker threads in each server process
# MaxRequestsPerChild: maximum number of requests a server process serves

StartServers 8
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0

-------

So, it gets a bit more complicated... what to edit, and how many times? StartServers are in there 3 times, MaxClients twice, and so on...
Gladius
Anyone?
Host134
Anyone have anything current on this link. The site is down.

http://php.weblogs.com/tuning_apache_unix
cnat
My # of TIME_WAIT always very high, around 800-1.200, but it isn't a DOS. So how can I reduce it ?

here is my httpd.conf :

Timeout 60

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 5


StartServers 5
MinSpareServers 5
MaxSpareServers 10
MaxClients 150
MaxRequestsPerChild 1000



Thank you.
perlchild
QUOTE
Originally posted by cnat
My # of TIME_WAIT always very high, around 800-1.200, but it isn't a DOS. So how can I reduce it ?

 here is my httpd.conf :

Timeout 60

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 5


StartServers       5
MinSpareServers    5
MaxSpareServers    10
MaxClients         150
MaxRequestsPerChild 1000



 Thank you.


Can you post the sysctl values for net.ipv4.tcp_fin_timeout ?
in fact all of net.ipv4.tcp_ would enable us to help you.
cnat
Here is my sysctl.conf :

# Controls IP packet forwarding
net.ipv4.ip_forward = 0

# Controls source route verification
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.lo.rp_filter = 1
net.ipv4.conf.eth0.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

# Disables IP source routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.lo.accept_source_route = 0
net.ipv4.conf.eth0.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel
#kernel.sysrq = 0

# Disable ICMP Redirect Acceptance
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.lo.accept_redirects = 0
net.ipv4.conf.eth0.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0

net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_probes = 2
net.ipv4.tcp_keepalive_time = 90
net.ipv4.vs.timeout_timewait = 30
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_fack = 1
net.ipv4.tcp_timestamps = 1
#net.ipv4.tcp_keepalive_intvl = 10

# Enable ignoring broadcasts request
net.ipv4.icmp_echo_ignore_broadcasts = 1

# Enable bad error message Protection
net.ipv4.icmp_ignore_bogus_error_responses = 1

# Set TCP Re-Ordering value in kernel to '5'
net.ipv4.tcp_reordering = 5

# Various Settings
#net.core.netdev_max_backlog = 1024
# Increase the maximum number of skb-heads to be cached
#net.core.hot_list_length = 64
# Increase the tcp-time-wait buckets pool size
#net.ipv4.tcp_max_tw_buckets = 360000

# This will increase the amount of memory available for socket input/output queues
#net.core.rmem_default = 65535
#net.core.rmem_max = 8388608
#net.ipv4.tcp_rmem = 4096 87380 8388608
#net.core.wmem_default = 65535
#net.core.wmem_max = 8388608
#net.ipv4.tcp_wmem = 4096 65535 8388608
#net.ipv4.tcp_mem = 8388608 8388608 8388608
#net.core.optmem_max = 40960

net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_syn_retries = 2
# Enable TCP SYN Cookie Protection
net.ipv4.tcp_syncookies = 1

# Controls the System Request debugging functionality of the kernel
kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.
# Useful for debugging multi-threaded applications.
kernel.core_uses_pid = 1


My server is Pen 4 2.4, 512Mb ram.

Thank you.
dontknow
How to optimize my apache? Server: Dual Xeon 2.8Ghz with 2GB RAM. Apache 2.0.46. Big thanks. Settings now:

HostnameLookups Off
KeepAlive On
MaxKeepAliveRequests 1000
KeepAliveTimeout 2


StartServers 50
MinSpareServers 30
MaxSpareServers 64
MaxClients 150
MaxRequestsPerChild 0



StartServers 2
MaxClients 400
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0
ThreadGuardArea on
Mandi
QUOTE
Originally posted by cnat
My # of TIME_WAIT always very high, around 800-1.200, but it isn't a DOS. So how can I reduce it ?

 here is my httpd.conf :

Timeout 60

KeepAlive Off

MaxKeepAliveRequests 100

KeepAliveTimeout 5


StartServers       5
MinSpareServers    5
MaxSpareServers    10
MaxClients         150
MaxRequestsPerChild 1000



 Thank you.

Configuring KeepAlive Off will increse the number of your TIME_WAIT-s.
Go KeepAlive On for an acceptable number of TIME_WAIT-s.
ISVY
so anyone please post the best config for server. i need it. my server go high load when there are too much visitor.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.