Apache2 MPM Model Learn

Source: Internet
Author: User

First, MPM

MPM (multi-processing module (MPM) implements a hybrid multi-process multi-threaded server) is a concept introduced by Apache2, a multi-path processing module, Is the modularity of the structure. The core task is processed as a pluggable module, the MPM, which enables it to be optimized for different environments. In this case, the concept of a processing pattern is born. Processing mode under Unix/linux is now divided into prefork, Worker, Event three kinds.

Second, prefork

Prefork MPM is based on a non-threading model, and is similar to how it is handled in the Apache 1.x version. Prefork MPM is safe in all cases and is the only security option for software such as PHP that runs non-thread-safe (non-thread-safe) mode. For some applications, including programs that are popular on Apache 1.3 (such as simple static pages, CGI scripts, and so on), Prefork MPM is the best choice. On the other hand, Prefork uses separate sub-processes to handle different requests, and the processes are independent of each other, making them one of the most stable mpm. However, because each request will produce a new process, resulting in system resources (especially memory) consumption is very fast, once the concurrency is large, a large number of Apache process will occupy a large amount of memory space.

Serverlimit 3000Startservers 750Minspareservers 5Maxspareservers 100MaxClients 3000Maxrequestsperchild 10000

The first thing to look at is the meaning of the Apache parameters (the description of the official document is quoted in quotation marks):

(1) Maximum number of simultaneous response requests for Serverlimit and maxclients servers

This is your current configuration of the Apache maximum number of concurrent responses, corresponding to the number of Apache processes, two parameters are modified at the same time, maxclients must not be greater than the Serverlimit parameter. The size of the serverlimit, depending on the resources of your system, each Apache process consumes 2 m of memory by default, which can basically be calculated according to this formula: Max Memory *80%/2m=serverlimit

(2) Startservers 750 number of processes started by default at startup

This parameter defaults to 5 because Apache increases the number of processes that respond to the service by automatically starting a new process, which is also possible, and will be increased by the default of 5 to the number of processes that satisfy the service, but will appear stuck at the start of the startup. One benefit of small startup parameters is that the pressure on the back-end tomcat can be increased slowly, rather than increasing the pressure at once. This can be adjusted to the current service maximum number of concurrent connections, the current maximum number of concurrent connection, you can monitor the number of Apache process: Ps-ef | grep httpd | Wc-l to get it.  Do not adjust too much, otherwise it is unnecessary to increase the Apache through JK to establish connection with Tomcat. Note: After the Apache process has established a connection with Tomcat, it will not release this connection, it will remain connected until timeout, and will be permanently connected if there is no timeout time. The settings for timeout are described in the following JK configuration. So don't start too many Apache processes at once, just start enough processes. Other increased traffic, Apache automatically adjusts the number of processes until the maxclients parameter limits the range.

(3) Minspareservers 5 Minimum Idle Process

The minspareservers instruction sets the minimum number of idle child processes. The so-called idle child process refers to a child process that is not processing the request. If the number of currently idle sub-processes is less than minspareservers, then Apache will take the first second, two second seconds, the third second four, the number of exponential increments of the speed of the new child process.

(4) Maxspareservers 10 Max Idle Process

The maxspareservers instruction sets the maximum number of idle child processes. The so-called idle child process refers to a child process that is not processing the request. If there are currently more than maxspareservers of idle child processes, the parent process kills the extra child processes.   These two parameters can be adjusted, but the values of these two parameters cannot be set too large, or the Apache process too much, will cause the corresponding open Tomcat process will be many. On the official website there is a saying about both of these parameters: "It is usually a bad idea to set this parameter too large." "On a server with a high pressure (concurrent access 2800), maxspareservers This value is set to 200. The benefit of setting this value is that there will not be too many idle processes consuming resources while reducing Apache and Tomcat connection ports. When the idle Apache process is closed, the JK connection is freed while the number of Tomcat connections is freed, thereby reducing system resource consumption.

(5) Maxrequestsperchild 10000

The maxrequestsperchild instruction sets the maximum number of requests per child process to allow the servo during its lifetime. When the Maxrequestsperchild limit is reached, the child process will end.   If Maxrequestsperchild is "0", the child process will never end.   There are two benefits to setting Maxrequestsperchild to a value other than 0: * can prevent (accidental) memory leaks from running indefinitely, thus exhausting memory.   * Gives the process a limited lifespan, which helps reduce the number of active processes when the server load is reduced. Note for keepalive links, only the first request is counted. In fact, it changes the behavior of each child process to limit the maximum number of links. In other words, the maximum number of connections for a child process is equal to maxrequestsperchild*maxkeepaliverequests. So after you turn on keepalive, you need to set both Maxrequestsperchild and Maxrequestsperchild to make sure that each Apache process shuts down after a certain number of requests, re-opening the new subprocess, Avoid memory leaks and resource usage caused by Apache process exceptions.

(6) Keep-alive

Default: On send request, only one in maxrequestsperchild, no matter how many requests the connection sends.

(7) Maxkeepaliverequests

Default: 1001 Established keep-alive connections, the number of requests that are allowed to be sent. Once the connection is established, either the number is broken or the keepalivetimeout time is disconnected. The maxkeepaliverequests directive limits the number of requests allowed per connection when KeepAlive is enabled. If this value is set to "0", the number of requests is not limited. We recommend that you better set this value to a larger value to ensure optimal server performance. The setting of this number must consider how many requests the same user will have to access your service within a period of time.   To be considered in conjunction with the KeepAliveTimeout parameter. For example, the user needs a time interval of not more than KeepAliveTimeout, a continuous request for 10 files, then this parameter should be set to 10, if the user continuously request access during continuous time, then this value should be set more. Otherwise, re-establish the connection download. Once the user has made 10 consecutive requests, and the user is sure to complete these requests within 5 seconds of the request, or even after a long time after the request, then the keepalivetimeout time can be set very short, so as to disconnect the user as soon as possible, the resources to other users.

(8) KeepAliveTimeout

Default: 5 "The time to wait for the next request on a well-established keep-alive connection, if the number of maxkeepaliverequests is not full. "If there is a request to arrive, then Apache waits for the IO response timeout time to take effect, timeout time does not wait for response, the connection is disconnected; If no request arrives within KeepAliveTimeout time, the connection is disconnected. Specific settings can refer to the mate maxkeepaliverequests parameter. At the same time, this parameter is affected by the timeout parameter, and in a successful connection, the timeout time does not wait for a response, and the connection is also disconnected.

(9) TimeOut

Default: The timeout instruction is used to set the length of time that Apache waits for the following three events: 1.   The total time taken to accept a GET request.   2. When a post or put request is received, the time between two TCP packets is accepted.   3. Response time between two ACK packets in the TCP packet transmission. The default value of the timer before the 1.2 version is 1200, which is now set to 300, but is still sufficient for most cases. The reason for not setting the default value is that there is a problem with the code: sometimes after sending a packet, the timer is not reset.

(10) Mode of operation:

A separate control process (the parent process) is responsible for generating child processes that are used to listen for requests and respond. Apache always tries to keep some spare (spare) or idle child processes in the process of meeting incoming requests. This way, the client does not need to wait for the child process to be generated before the service is received. In Unix, the parent process typically runs as root for 80 ports, and Apache-generated child processes are typically run with a low-privileged user. The user and group directives are used to set up low-privileged users of child processes. The user who runs the child process must have read permission to the content it serves, but must have as few permissions as possible for other resources than the service content. Third, the worker four, the Event

Five, optimization recommendations

  # Upgrade Apache to the latest version, and the new version often includes performance improvements and security updates.   # setting "Hostnamelookups off" in httpd.conf avoids reverse querying for each visitor's DNS domain name.   # for busy websites, set "MaxClients 230" or higher in httpd.conf. This setting allows more httpd processes to respond to requests at the same time, and avoids the processor queuing situation.   # Use another server to process picture files.   # your Web pages and CGI pages are covered by browser buffering technology. Specific articles can refer to this site: using Mod_gzip accelerated Zope and apache  # keep your Apache slim, compile those just needed modules, before compiling, modify the Src/configuration file, before those unnecessary modules with # The number is commented out.   # If you do not need a traffic log, point the Transferlog in httpd.conf to/dev/null/  # unless you are sure to use the. htaccess file to control permissions for some directories, otherwise set "Allowoverri De None ", thus eliminating the hardship of Apache searching for. htaccess files in each directory.   # do not let unwanted background processes run.   # never write pages or log files on a network disk, such as NFS.   # do not let Apache (httpd) run in inetd mode.   # Don't let X Windows run on your WEB server, turn off X with Ctrl-alt-backspace.    # Avoid using SSI tags. #:  * file I/O in CGI scripts: the fewer files you open, the better.   * Shell command: Use full path to invoke shell command.   * If your site is primarily powered by CGI, use Mod_perl.   * in your Web page directory, do not let the number of files more than 1000, the more files spend more time on the location.   # The fewer pictures on the WEB server, the better, and ensure that each picture is run through the picture compressor. &nbsP # do stress tests on your website and suggest using Apache's own AB command to test.   # for the best performance, it's best to unplug the network cable so your WEB server is safe and the load drops to 0 immediately.

Apache2 MPM Mode Understanding

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.