PHP Performance in Apache: Multi-Process vs Multi-Threaded
| From: | Israel Ekpo | Date: | Tue, 14 Dec 2010 18:06:01 +0000 |
| Subject: | PHP Performance in Apache: Multi-Process vs Multi-Threaded | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-51025@lists.php.net to get a copy of this message | ||
Hi All,
I have a few questions about the performance of PHP web applications *under
load* and I would appreciate if there is anyone that would like to share
their experiences in terms of any benchmarks or observations.
*Background Information*
In multi-process environments, such as FastCGI, Apache Prefork MPM etc, PHP
needs to execute the MINIT and MSHUTDOWN functions for all loaded extensions
on every request.
In a multi-threaded environment, such as Apache Worker MPM, with Zend Thread
Safety is enabled,
PHP only needs to execute MINIT and MSHUTDOWN functions once for each
extension and not each time a new thread is created to serve a request.
It is also more expensive to create new processes than to create new
threads.
In one-on-one comparisons between scripts executed only once in ZTS mode and
scripts executed once in non-ZTS mode,
I noticed that the one in non-ZTS mode was slightly faster and this seems to
be the main reason why most people go with the non-ZTS enabled setups.
But the reason for this slight difference in speed is because of the
differences in the data structure for globals for ZTS and non-ZTS modes.
Other reasons people have cited for going with non-threaded setups include
stability which I guess we should not really be concerned about if
non-threadsafe extensions are excluded.
Since it is generally more expensive to create new processes than new
threads, I believe that under high load, php in ZTS mode (multi-threaded
environment) will perform better than an identical setup in NTS mode
(multi-process).
*Problem*
I noticed that Zend Server is using PHP in FastCGI mode (multi-process NTS)
and I am contemplating setting up apache in worker mode (threaded mode) and
compiling php in ZTS mode instead.
Has anyone performed any load tests benchmarks comparing the two setups
(Multi-Process vs Multi-Threaded)?
Are there PHP extensions that cause issues in threaded environments that I
should avoid?
Are there any internals information or any other reasons why I should choose
ZTS over NTS or vice versa?
Any useful feedback will be highly appreciated.
Thanks.
--
°O°
"Good Enough" is not good enough.
To give anything less than your best is to sacrifice the gift.
Quality First. Measure Twice. Cut Once.
http://www.israelekpo.com/