Based on the descriptions for both the Prefork and Worker MPM, it seems the prefork type is somewhat outdated, but I can't really find a proper comparison of the two types.

What i'd like to know:

  • What are the differences between the two versions?
  • What are the (dis-)advantages of each server type?
  • Are there any basic guidelines on which type to choose based on the conditions?
  • Are there any big performance differences between the two?
link|improve this question

feedback

3 Answers

up vote 18 down vote accepted

As the docs say, you should use the prefork MPM if you need to avoid threading for compatibility with non-thread-safe libraries. Typically, any non-trivial Apache module (mod_php -- or, more precisely, the myriad of extensions and libraries that it links to -- being the canonical example) has some sort of non-thread-safe library (or has non-thread-safe code in it), so unless you're using a pretty stock Apache install, I'd go for the prefork MPM.

link|improve this answer
I would have recommended the worker MPM, unless you're running PHP. Worker is the recommended MPM from apache, and gives better performance and lower overhead. It's only that PHP developer have never heard of thread-safety that you need to use prefork. – David Pashley Jul 24 '09 at 13:05
6  
PHP has been thread safe for a very long time. They only suggest the use of pre-forkers as they cannot control what other libraries do. Quit blaming PHP for others developers inactions. – Alister Bulman Jul 24 '09 at 13:59
PHP may be thread safe (although I doubt it) but all the libraries that it links to are definitely not. Here we run a few fairly large PHP applications and every couple of months we try to switch from prefork to worker, but we get corrupted data straight away. – Aleksandar Ivanisevic Jul 24 '09 at 14:04
2  
At least function changing ENV variable will not be thread safe, setlocal php.net/manual/en/function.setlocale.php is a common exemple of that. – radius Jul 24 '09 at 17:27
feedback

The classic solution to running unsafe extensions while serving large numbers (>100) of concurrent connections is to run PHP on fastCGI (mod_fcgid, a native apache module) and proxy dynamic requests to that from an apache instance that runs the Worker MPM.

This would enable you to scale from a few hundred up to >1000 concurrent connections with a modest amount of memory (4~8GB) when serving a mix of static and dynamic content.

Of course, you should also investigate front-end caching solutions as part of your overall deployment (memcached, varnish).

Alternatively, upgrade to apache 2.4 and its native event MPM, which handles concurrency in a much improved fashion (threads are fired off upon connection, not waiting to be polled.)

link|improve this answer
could you expand on the event mpm comment ? How does it stack up vs mpm-worker ? – Sirex May 11 at 2:23
While the worker MPM was already thread-based, and hence much faster to start and lighter to run, the event MPM no longer polls the socket - it gets notified on activity; therefore, "event". – adaptr May 11 at 13:56
so it should work better on high traffic (13k/sec) sites ? – Sirex May 20 at 20:08
feedback

This is something very particular to what you're serving. If you're doing lots of little static connections, threads would be lighter and faster. If you just have few big apps constantly spawned, prefork might have an edge due it's maturity and stability. Why not just set up what you need, test one, swap out the MPM module, try it again, see which one suits you better?

link|improve this answer
You can't arbitrarily "swap out" the MPM in apache 2.2; it is set at compile time. – adaptr Apr 2 at 13:18
feedback

Your Answer

 
or
required, but never shown

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