Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » PHP Performance in Apache: Multi-Process vs Multi-Threaded [RSS Feed]

#1 Dec. 14, 2010 18:06:53

Israel E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

PHP Performance in Apache: Multi-Process vs Multi-Threaded


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/

Offline

#2 Dec. 14, 2010 19:23:25

j.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

PHP Performance in Apache: Multi-Process vs Multi-Threaded


"Israel Ekpo" <israele***@*mail.com> wrote in messagenews:aanlkti=ixwqkkovkyuluqckdvklqy2nyeyg6pjfza***@*ail.gmail.com...
> 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.

You're not correct here. A process can handle quite a lot of requests and
MINIT/MSHUTDOWN is executed only once.
So the MINIT/MSHUTDOWN overhead is negletable.

> It is also more expensive to create new processes than to create new
> threads.

Correct, but it's rarely needed to create them in both cases. So expense of
creation plays almost no role.
What plays role is switching the context when some overlapping requests are
processed. With thread it's less expensive.
But still, switching is a huge overhead when you run a server with 1K or 10K
overlapping requests.
If you talk about 10 or 40 - there is almost no difference.

> 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

that's because in ZTS case all data is in thread-safe structures and there
is quite a big overhead accessing any field of the structures.

> and this seems to
> be the main reason why most people go with the non-ZTS enabled setups.

No. Php if we talk about php with all its extensions is not threadsafe at
all. Many of the extensions allocate static data and inherently
non-thread-safe.

> 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.

correct.

> 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.

Correct. But you never know which one is truly threadsafe.
I'd only say that it's safer to use extensions that do not depend on 3rd
party libraries at all, or at least
depend on libraries written with threadsafety in mind.

> Has anyone performed any load tests benchmarks comparing the two setups
> (Multi-Process vs Multi-Threaded)?

Could you please shed some light on what load volume you're talking about?
1, 10, 100, 1K, or10K of requests per second?

with a regular web site which is handling ~4-5K visitors a day, you can
hardly get more than 10-15 requests per second.
In this case you may want to get what so ever php and apache distributed
with your OS and do not spend you time on anything else.
If you foresee 10K requests per second, it's better not to use PHP and
especially not to use Apache at all.

-j



--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit:http://www.php.net/unsub.php

Offline

  • Root
  • » PHP
  • » PHP Performance in Apache: Multi-Process vs Multi-Threaded [RSS Feed]

Board footer

Moderator control

Enjoy the 19th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support