Deeply understand the working mode of Apahce Perfork, Worker_linux

Source: Internet
Author: User
Prefork mode uses multiple child processes, each with only one thread. Each process can maintain only one connection at a certain time. On most platforms, prefork MPM is more efficient than worker mpm, but memory usage is much higher. Prefork's wireless path design will in some cases be more advantageous than the worker: it can use Third-party modules that do not handle thread safety well, and it is easier to debug for those platforms where thread debugging is difficult.

Worker mode uses multiple child processes, each of which has multiple threads. Each thread can maintain only one connection at a certain time. In general, the worker mpm is a good choice on a high-traffic HTTP server, because worker MPM memory usage is much lower than prefork MPM. But the worker mpm also by the imperfect place, if a thread crashes, the whole process will "die" along with all its threads. Because the thread shares the memory space, a program must be recognized by the system at run time as "every thread is safe."

The prefork mode is slightly faster than the worker, however it requires slightly more CPU and memory resources than the Woker.

To view the working mode that you are using:
Apachectl-l

Two modes configuration file + Description:
Perfork mode:

Copy Code code as follows:

<ifmodule mpm_prefork_module>
Serverlimit 2000
#连接数大于256需设置此项. 20000 is serverlimit the maximum value of this parameter
Startservers 5
#初始化时建立的子进程数. Prefork defaults to 5
Minspareservers 10
#最小的空闲进程数
Maxspareservers 15
#最大的空闲进程数
MaxClients 1000
#最大并发客户端连接数上限
Maxrequestsperchild 10000
#控制服务器杀死旧进程产生新进程的频率
#将MaxRequestsPerChild设置成非零值有两个好处:
#1. It is possible to prevent (accidental) memory leaks from indefinitely running out of memory.
#2. Gives the process a finite lifespan, which helps reduce the number of active processes when the server load is reduced.
</IfModule>


Worker mode:

Copy Code code as follows:

<ifmodule mpm_worker_module>
Startservers 3
#初始化时建立的子进程数
MaxClients 2000
#最大并行处理数量. Maximum number of child processes =maxclients/threadsperchild
Serverlimit 25
#只有在你需要将MaxClients和ThreadsPerChild设置成需要超过默认值16个子进程的时候才需要使用这个指令. Do not set the value of this directive to be higher than the number of child processes required by maxclients and Threadsperchild.
Minsparethreads 50
#最少空线程数
Maxsparethreads 200
#最大空闲线程数
Threadlimit 200
#这个指令设置了每个子进程可配置的线程数ThreadsPerChild上限, the value of the directive should be consistent with the maximum value that Threadsperchild might achieve.
Threadsperchild 100
#子进程建立的服务线程数
Maxrequestsperchild 0
#设置每个子进程在其生存期内允许伺服的最大请求数量. Once the Maxrequestsperchild limit is reached, the child process will end. If Maxrequestsperchild is "0", the child process will never end.
</IfModule>


Work Mode Modification Method:
Recompile the specified work mode (default is Prefork)

Copy Code code as follows:

./configure--with-mpm=worker


Attention:
After you make changes to the working mode-related parameters, you must turn off the Apache service and restart the service.
Direct use of restart startup will be ineffective.

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.