Apache under three MPM modes: Prefork,worker and Event

Source: Internet
Author: User
Tags epoll

Apache under three MPM modes: Prefork,worker and Event


MPM (multi-processing module, multi-process processing module):
Prefork,worker and Event

to view the Apache mode, you can use the HTTPD-V command to view:

/usr/local/apache2/bin/httpd-vserver version:apache/2.2.29 (Unix) Server Built:aug 20:11:21server ' s Module Ma GIC number:20051115:36server loaded:apr 1.5.1, Apr-util 1.5.3Compiled using:apr 1.5.1, Apr-util 1.5.3architecture:6 4-bitserver mpm:prefork threaded:no forked:yes (variable process count)

When compiling, specify by configure parameters
--with-mpm=prefork|worker|event

Cat/usr/local/apache2/build/config.nice "./configure" ... "--with-apr=/usr/local/apr" \ "--with-apr-util=/usr/local /apr-util "\"--with-z=/usr/local "\"--with-mpm=prefork "....

Can be compiled into three kinds of support, by modifying the configuration to replace
--enable-mpms-shared=all

The modules directory will automatically compile three MPM's so files,
In httpd.conf, modify the loaded module to change the MPM mode:
LoadModule Mpm_prefork_module modules/mod_mpm_prefork.so

Prefork

"It's probably not advisable to use prefork unless you need a module that's not thread safe." The
Prefork mode, very old, very stable mode, is not recommended for use in the mode unless it is in use of a non-thread-safe module.

In order to reduce the overhead of frequent creation and destruction of processes, Apache starts by pre-fork some child processes and waits for requests to come in.

Each child process has only one thread, and within a single point in time, only one request can be processed.

Advantages: Mature and stable, compatible with all new and old modules. The
mod_php extension does not need to support thread safety and does not need to worry about thread safety.

Disadvantage: A process consumes more system resources, consuming more memory. The
is not good at handling high concurrent requests, High concurrency scenario will put the request into the queue,
Wait until there are available processes, the request will be processed.

Usage Scenario:
It is not recommended to be used in this mode unless the module is not running in thread mode.
PHP is recommended to use the fastcgi and PHP-FPM modes under non-thread-safe mode.


Worker

Threading mode with less memory footprint and better performance in high concurrency.

At startup, several child processes are forked, and each child process creates some threads, including a listener thread.

Each request comes over and is assigned to 1 threads to service.
Threads are more lightweight than processes, and threads typically share the memory space of the parent process.
In high concurrency scenarios, there are more threads available than prefork, and performance will be better.

If one thread hangs abnormally, it causes the parent process to hang with the other normal child threads.
To prevent this anomaly scenario from occurring, you need to use multiple processes to add multiple threads, and if a thread has an exception, the only part of the service that is affected is Apache, not the entire service.

Pros: Take up less memory and perform better with high concurrency.

Disadvantage: Thread-safe issues must be considered because multiple child threads are the memory addresses of the shared parent process.
Keep-alive's long connection method is designed to allow the next socket communication to be reused before the connection is created, thereby reducing the overhead of connection creation and destruction. Keeping a connection keeps a process or thread waiting, even if no data comes in. If you use Keep-alive's long connection, a thread will always be occupied and will need to wait until the timeout is released.

Usage scenarios:
Use Apache HTTPD version 2.2 or 2.4 and plan to run the SSL service.
Unless compatibility issues are resolved, it is generally recommended that the worker pattern be compared.

event


"It ' s just been moved from ' experimental ' to ' stable ' status in Apache 2.4."
Event MPM requires the support of the Linux system (Linux 2.6+) for Epoll, and is recommended for use in the httpd 2.4.x version.
Event  is similar to worker mode, which solves the problem of resource wasting of long-occupied threads under keep-alive scenarios.
Event MPM, there will be a dedicated thread to manage the keep-alive type of thread, when a real request comes over, the request is passed to the service thread, after execution, and allow it to release, enhanced the high concurrency scenario of the request processing capacity.
Event MPM will fail when it encounters some incompatible modules, it will fall back into worker mode, and a worker thread can process a request.


Usage scenarios:
Using Apache httpd 2.4, while using multi-threading, event is the best mode of operation.

Under the httpd 2.2.x document:

Warning
This MPM was experimental, so it could or may not be work as expected.

This MPM does isn't perform well on older platforms which lack good threading, but the requirement for epoll or kqueue makes This moot.

To use the this MPM in FreeBSD, FreeBSD 5.3 or higher is recommended. However, it is the possible to run this MPM on the FreeBSD 5.2.1, if you use the Libkse (see Mans libmap.conf).
For NetBSD, at least version 2.0 is recommended.
For Linux, a 2.6 kernel is recommended. It is also necessary to ensure that your version of GLIBC have been compiled with the support for Epoll.


This article from "Ops said: from rookie to veteran" blog, please be sure to keep this source http://liuqunying.blog.51cto.com/3984207/1835723

Apache under three MPM modes: Prefork,worker and Event

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.