设为首页 收藏本站
查看: 658|回复: 0

[经验分享] Understanding Apache 2 MPM (worker vs prefork)

[复制链接]

尚未签到

发表于 2017-1-4 11:20:17 | 显示全部楼层 |阅读模式
  (转载):http://www.garron.me/en/blog/apache2-mpm-worker-prefork-php.html

Understanding Apache 2 MPM (worker vs prefork)

Written by Guillermo Garron .

Date: 2012-12-26 14:28:00 +0000


From time to time I want to learn more about stability and high availability web servers. I usually get a sandbox site where I start to play with configurations.
This time all started because I also like testing service providers, and this week I have been moving my site between Site44 and NearlyFreeSpeech to test its features for static sites.
Finally in order to test how Apache may work when serving static files (I usually use Nginx for that matter) I installed Apache 2.2 on an Ubuntu 12.10 server (Linode). After doing that I headed toblitz.io and tested my Apache 2.2 serving static files. To my surprise it served without a sweat for one minute a page with user concurrency of 250 users per second.
The next day I tried to install a Wordpress site on the same server, as soon as I tried to install php, apt told me that it was going to uninstall apache2-mpm-worker and install apache2-mpm-preforkinstead.
I instructed apt to do nothing and started to read about the differences. It turned out that Apache may work in two different ways which are:
Apache MPM Worker
In this mode, Apache works more or less like Nginx.


This Multi-Processing Module (MPM) implements a hybrid multi-process multi-threaded server. By using threads to serve requests, it is able to serve a large number of requests with fewer system resources than a process-based server. However, it retains much of the stability of a process-based server by keeping multiple processes available, each with many threads.



A single control process (the parent) is responsible for launching child processes. Each child process creates a fixed number of server threads as specified in the ThreadsPerChild directive, as well as a listener thread which listens for connections and passes them to a server thread for processing when they arrive.


There is the reason why my tests with blitz.io and Apache2 serving static files went so well, I was using a Nginx-like configured Apache.
Apache MPM Prefork


This Multi-Processing Module (MPM) implements a non-threaded, pre-forking web server that handles requests in a manner similar to Apache 1.3. It is appropriate for sites that need to avoid threading for compatibility with non-thread-safe libraries. It is also the best MPM for isolating each request, so that a problem with a single request will not affect any other.


Differences are notable, and because we usually install Apache in a LAMP stack, we install something like this

sudo apt-get install apache2 php5 mysql-server mysql-client
That way we end up with apache2-mpm-prefork package. Because I have installed my Apache2 copy as a stand alone server Ubuntu installed the apache2-mpm-worker pre-build package instead.
Why prefork
Despite MPM worker being more efficient than MPM prefork when the server is under heavy load, it is usually not installed that way because mod_php can’t work with MPM worker.
We need to know a little bit about how you can execute PHP code when working with Apache.
The most common way is with mod_php which is an Apache module capable to understand and execute PHP code inside Apache itself. This is the most common way to run PHP under Apache.
But there is another way, which is similar to what Nginx does, and that is having PHP interpreted as CGI, which means that Apache is going to forward PHP to an external interpreter and get the result back. Using this method allows you to keep Apache configured to run in worker MPM mode, and still be able to “understand” PHP.
In the next two post of these series I will show you how to configure a LAMP server using Apache with MPM worker and running eficiently a copy of Wordpress.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-323800-1-1.html 上篇帖子: Apache HttpClient 4.3-忽略证书问题 下篇帖子: apache http日志文件按天生成
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表