Optimization of Apache working mode in depth

Source: Internet
Author: User

the Apache 2.X supports a plug-in parallel processing module called a multi-Path processing module (MPM). When compiling Apache, you have to choose only one mpm, and there are several different MPM options for Unix-like systems that can affect the speed and scalability of Apache.
Prefork MPM: This multi-path processing module (MPM) implements a non-threaded, pre-derived Web server that works like Apache 1.3. It is suitable for systems that do not have a thread-safe library and need to avoid threading compatibility issues. It is the best mpm to require each request to be independent of each other, so that if a request has a problem it will not affect the other request.
This MPM has a strong self-tuning capability and requires very little adjustment of the configuration instructions. The most important thing is to set the maxclients to a value that is large enough to handle the potential request spikes, and not too large to use more memory than the size of the physical memory.
Worker MPM: This multi-processing module (MPM) enables a network server to support mixed multithreaded multi-process. Because a thread is used to process requests, a large amount of requests can be processed, while the overhead of system resources is less than the process-based MPM. However, it also uses a multi-process, with each process having multiple threads to obtain the stability of the process-based MPM.
The number of threads that each process can have is fixed. The server increases or decreases the number of processes depending on the load. A separate control process (parent process) is responsible for the creation of child processes. Each child process can establish a threadsperchild number of service threads and a listener thread that listens to the access request and passes it to the service thread for processing and answering.
Whether it's worker mode or prefork mode, Apache always tries to keep some spare (spare) or idle child processes (the free service thread pool) to meet the incoming requests. This way, the client does not need to wait for the child process to be generated before the service is received.
Overall the prefork way is slightly higher than the worker, but it requires slightly more CPU and memory resources than the worker.

           **下面将对   Prefork MPM  、Worker MPM  这两种工作模式的配置介绍下 **
First compile that Apache service
            # tar xzvf httpd-2.4.2.tar.gz -C /opt            # tar xzvf apr-1.4.6.tar.gz -C /opt  (支持Apache上层应用跨平台,提供底层接口库)            # tar xzvf apr-util-1.4.1.tar.gz -C /opt            # cp -R apr-1.4.6/ /opt/httpd-2.4.2/srclib/apr            # cp -R apr-util-1.4.1/ /opt/httpd-2.4.2/srclib/apr-util            # yum install gcc gcc-c++ make pcre pcre-devel -y      //安装环境 (pcre : 一个Perl库,支持正则表达式)            # yum install zlib-devel -y

.

            # cd /opt/httpd-2.4.2            # ./configure             --prefix=/usr/local/httpd             --enable-deflate             --with-mpm=prefork \                           //选择为prefork工作模式            --enable-expires             --enable-so             --enable-rewrite             --enable-charset-lite             --enable-cgi

.

            # make && make install            # grep -v "#" /usr/local/httpd/bin/apachectl > /etc/init.d/httpd               # vi /etc/init.d/httpd 在文件最前面插入下面的                        #!/bin/sh                        # chkconfig:2345 85 15                        # description:Apache is a World Wide Web server.

.

            # chmod +x /etc/init.d/httpd            # chkconfig --add httpd            # chkconfig --list httpd            # chkconfig --level 35 httpd on    //开机自启动            # ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf    //生成软连接方便管理朱配置文件         # vim /etc/httpd.conf(设置主配置文件)              ServerName www.benet.com:80               Listen 192.168.100.102:80                #Listen 80       //注释该行

.

Prefork mode
    # vim /etc/httpd.conf     Include conf/extra/httpd-mpm.conf      //去# 启用httpd-mpm.conf 文件    # vim /usr/local/httpd/conf/extra/httpd-mpm.conf<IfModule mpm_prefork_module>StartServers                     10      # 启动时进程数MinSpareServers             10      # 最小空闲进程数MaxSpareServers            50      # 最大空闲进程数MaxRequestWorkers      150     # 最大并发进程数MaxConnectionsPerChild   0     # 最大连接数限制</IfModule>

.

    # /usr/local/httpd/bin/httpd -l    //查看当前工作模式

# lsof -i:80     //查看Apache 进程运行的情况


.

Worker mode
     编译安装Apache  下面编译工作模式指定为 --with-mpm=worker            其他安装步骤参考上面            # cd /opt/httpd-2.4.2            # ./configure             --prefix=/usr/local/httpd             --enable-deflate             --with-mpm=worker \                           //选择为worker工作模式            --enable-expires             --enable-so             --enable-rewrite             --enable-charset-lite             --enable-cgi

. .

# vim /usr/local/httpd/conf/extra/httpd-mpm.conf <IfModule mpm_worker_module>StartServers                      2        #启动时进程数MinSpareThreads             25      #最小空闲线程数MaxSpareThreads           75       #最大空闲线程数ThreadsPerChild              25       #每个进程可以启动的线程数量MaxRequestWorkers       150     #线程数量最大值MaxConnectionsPerChild   0      #最大连接数限制ThreadLimit                      64      #每个进程可以启动的线程数量上限值</IfModule>

Optimization of Apache working mode in depth

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.