Server optimizations for php

Marlon de Boer marlon at hyves.nl
Fri Jan 23 18:46:33 MSK 2009


Jure Pečar wrote:
> On Fri, 23 Jan 2009 15:24:01 +0100
> Atif Ghaffar <atif.ghaffar at gmail.com> wrote:
> 
>> Hi. Jure,
>>
>> Thanks for the valuable advice.
>> I will look in the cool-thread servers from Sun. We are usually buying
>> from Sun but moslty the x64 server.

I tested a cool-thread t2250 with 64 threads from sun a couple of weeks
ago. My conclusion is that for our php application was that one thread
wasn't powerful enough to serve a php page fast enough. So in our case
we would end up with a lot of parallel but slower processes. Our current
x86_64 hardware could deliver the pages about 2 secs faster per php-cgi
process.

The company I work for (http://www.hyves.nl) now has over 500
webservers, serving +200M pageviews a day and 17.7M per hour max. This
is done with quadcores or 2 x quadcores with 8G mem. I'm currently
migrating them to nginx + php-fpm because we gain about 20% performance
over apache.

Some tips I would like to give you,

- use a optcacher like eaccelerator, apc or xcache, you can win about 8
times performance.
- benchmark what will be the ideal number of php-cgi processes for your
application, too much will lead to unnecessary context switches which
costs performance, waits for backend connections etc. Not enough
processes will lead to wait times between nginx and php fastcgi. For our
application I spawn about 5 php-cgi's per cpu core.
- If nginx and php-fpm run on the same host use unix sockets, these are
slightly faster than tcp sockets.
- cache complex sql queries in memcached or in shared memory (all above
optcode caches provide api's for it).
- Tune your nginx config accordantly, we also serve static content from
the same webservers. We set totally different headers like expire etc,
to save bandwidth and cpu cycles which are matched by location regexes.

Don't know if all the rules apply in your environment but see what you
can use from the above tips :-)

Marlon de Boer
System Administrator http://www.hyves.nl





More information about the nginx mailing list