`
hongtoushizi
  • 浏览: 376708 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

Understanding Apache 2 MPM (worker vs prefork)

阅读更多

(转载):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.

分享到:
评论

相关推荐

    apache2的worker工作模式配置及MaxClients不足问题解决

    Apache 服务器是当前最流行的 Web 服务器之一,它提供了多种工作模式,包括 Prefork、Worker 和 Event 等。其中,Worker 工作模式是 Apache 2.x 版本中默认的工作模式。在 Worker 工作模式下,Apache 服务器使用多...

    Apache Prefork、Worker和Event三种MPM详解

    ### Apache Prefork、Worker 和 Event 三种 MPM 的详解 #### 一、Prefork MPM **Prefork MPM** 是 Apache 提供的一种多处理模块(MPM),它实现了非线程化的、预分叉的 Web 服务器架构,类似于 Apache 1.3 的工作...

    Apache的prefork模式和worker模式该户.docx

    Apache 提供了两种主要的 MPM:prefork 和 worker,它们各自有不同的工作原理和适用场景。 **prefork 模式** prefork 模式是一种非线程的、预派生的服务器模型,适用于那些没有线程安全库或需要避免线程兼容性问题...

    Apache中配置最大并发用户数 tcp连接设置.docx

    主要有两种 MPM 模块:prefork 和 worker。 1.1 Prefork MPM prefork 是 Unix 平台上缺省的 MPM 模块,它使用预派生子进程方式,用单独的子进程来处理不同的请求,进程之间彼此独立。在 make 编译和 make install ...

    Apache的fork模式和worker模式判断方法

    运行命令httpd -l 或者apache2 -l ,输出的结果中如果含有prefork.c,那就是prefork模式,如果结果中含有worker.c,那就是worker模式。 知道模式之后我们可以在apache的confextrahttpd-mpm.conf 进行编辑了 # # ...

    Apache的进程与线程讨论

    Worker MPM 是 Apache 中的另一种常用的 MPM,它与 prefork MPM 的最大区别在于采用了多线程的方式来处理请求。这意味着单个进程可以同时处理多个请求,提高了并发能力。在配置上,Worker MPM 有一些与 prefork 类似...

    Apache多路复用模块(MPMs)介绍

    2. **Apache Worker MPM** Worker MPM采用了多线程和多进程的混合模型。它使用较少的进程,每个进程内创建多个线程来服务请求。当请求到来时,它们会被分配给进程中的空闲线程,从而提高了并发处理能力,减少了内存...

    Apache2中文教程

    例如,使用MPM(Multi-Processing Module)如prefork或worker,调整`MaxKeepAliveRequests`和`KeepAliveTimeout`参数,以及启用GZIP压缩等。 九、故障排查 当遇到问题时,Apache2的错误日志是排查故障的重要资源。...

    linux apache2 编译成功

    ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --enable-proxy --enable-proxy-http --with-mpm=prefork ``` 执行编译和安装: ```bash make sudo make install ``` 安装完成后,Apache的可...

    Apache2的http.conf文件翻译

    ### Apache2 httpd.conf 文件详解 #### 一、概述 `httpd.conf` 是Apache Web服务器的核心配置文件,其中包含了各种指令与设置项,用于控制Apache服务器的行为与功能。通过合理配置这些指令,管理员可以实现对Apache...

    Apache2的httpd.conf翻译

    Apache支持不同的MPM,如prefork、worker和perchild,它们分别对应不同的进程和线程模型。 - `prefork MPM`:适用于单CPU系统,配置包括`StartServers`、`MinSpareServers`、`MaxSpareServers`、`MaxClients`和`...

    在 ubuntu 中安装 Apache 2 Web 服务器

    - **软件包信息**:安装过程中会显示将要安装的额外软件包列表,例如 `apache2-mpm-worker`, `apache2-utils`, `apache2.2-bin`, `apache2.2-common`, `libaprutil1-dbd-sqlite3`, `libaprutil1-ldap`, `ssl-cert` ...

    Apache2 httpd.conf 中文版

    根据给定的文件标题、描述、标签以及部分内容,本文将详细介绍Apache2的`httpd.conf`配置文件中的关键知识点。 ### Apache2 httpd.conf 文件概述 `httpd.conf`是Apache HTTP服务器的主要配置文件,它控制着服务器...

    apache2.2中文版参考手册

    2. MPM(多进程模块):Apache 2.2有多种MPM,如Prefork、Worker和Event,选择合适的MPM可以优化服务器性能。 六、安全设置 1. SSL/TLS:通过mod_ssl模块提供HTTPS支持,配置证书和密钥,保障数据传输的安全。 2....

    深入理解apahce的工作模式perfork、worker

    ### Apache工作模式深入解析:Prefork MPM与Worker MPM Apache HTTP Server 是一款广泛使用的Web服务器软件,它提供了多种多样的配置选项来满足不同场景的需求。其中,工作模式(Multi-Processing Modules, MPMs)...

    Apache2中文手册

    Apache2还支持MPM(多进程模块),如prefork和worker,它们分别基于多进程和多线程模型。mod_proxy可以实现负载均衡和反向代理,mod_rewrite则能实现复杂的URL路由规则。 总的来说,Apache2中文手册提供了全面的...

    apache2 httpd文件配置参数.txt

    #### prefork MPM - **StartServers**:启动时的初始工作子进程数量,默认值为 5。 - **MinSpareServers**:最小空闲子进程数量,默认值为 5。 - **MaxSpareServers**:最大空闲子进程数量,默认值为 10。 - **...

    Apache服务器配置与管理.ppt

    在RHAS3中,主要有三种MPM:Prefork MPM、Worker MPM和PerChild MPM。Prefork MPM采用单父进程多子进程模型,每个子进程处理一个请求,预生成子进程以提高性能。`StartServers`、`MinSpareServers`、`...

Global site tag (gtag.js) - Google Analytics