LAMP System Performance Tuning: Part 2nd: Optimizing Apache and php-Learning notes

Source: Internet
Author: User




Two configuration MPM

Apache is modular because features can be easily added and removed. At the core of Apache, the Multi-processing module (multi-processing module,mpm) provides this modular functionality-management of network connectivity, scheduling requests. MPM enables you to use threads and even to migrate Apache to another operating system.

Only one MPM can be active at a time and must be statically compiled with--with-mpm= (worker|prefork|event).

The traditional model of using one process per request is called Prefork. The newer threading model, called worker, uses multiple processes, each with multiple threads, to achieve better performance at a lower cost. The newest EVENTMPM is an experimental model that uses a separate thread pool for different tasks. To determine what is currently in use

What kind of MPM, can execute httpd-l. For example:

[Email protected] conf]# httpd-l

Compiled in Modules:

Core.c

Prefork.c

Http_core.c

Mod_so.c


Choosing which MPM to use depends on many factors. This model should not be considered until the event MPM is out of the experimental state, but rather between the use of threads and the non-use of threads.

Choose. On the surface, if all the underlying modules (including all libraries used by PHP) are thread-safe, the thread is better than the fork (forking).

Prefork is a safer option and should be tested carefully if a worker is selected. Performance benefits also depend on the libraries and hardware that came with your release. Regardless of which mpm you choose, you must properly configure it. In general, configuring MPM includes telling Apache how to control how many workers are running, which are

The thread or process. The important configuration options for Prefork MPM are shown in Listing 1. Edit the http.conf master configuration file to see:


Startservers #预先启动进程

Minspareservers #最小空闲进程

Maxspareservers #最大空闲进程

MaxClients 225 #允许连接数

Maxrequestsperchild 4000


The Prefork model creates a new process for each request. The excess process remains idle to

Processing incoming requests, which shortens the startup delay. As long as the Web server appears, pre-

50 processes, and try to keep 10 to 20 idle servers in a single

Run. The hard limit for the number of processes is specified by maxclients. Although a process can be

Many successive requests, Apache will cancel the number of connections over 4,000

This reduces the risk of memory leaks.

Configuring a threaded MPM is similar, except that you must determine how many threads are used and

Ride. The Apache documentation explains all the necessary parameters and calculations.


The Prefork model creates a new process for each request. The excess process remains idle to

Processing incoming requests, which shortens the startup delay. As long as the Web server appears, pre-

50 processes, and try to keep 10 to 20 idle servers in a single

Run. The hard limit for the number of processes is specified by maxclients. Although a process can be

Many successive requests, Apache will cancel the number of connections over 4,000

Reduce the risk of memory leaks


Configuring a threaded MPM is similar, except that you must determine how many threads are used and

Ride. The Apache documentation explains all the necessary parameters and calculations. You can choose the value you want to use after several attempts and errors. The most important value is maxclients. The goal is to allow enough workder processes or threads to run without causing the server to be over-exchanged. If the incoming request exceeds the processing power, then those requests that satisfy at least this value are serviced and other requests are blocked.



If the maxclients is too high, then all clients will experience a bad service because the Web server will attempt to swap out a process to enable another process to run. Being too low means that services may be denied unnecessarily. Viewing the number of processes running under high load and the memory consumption caused by all Apache processes can be helpful in setting this value. If the value of MaxClients exceeds 256, the Serverlimit must also be set to the same value.



Each request processed by Apache fulfills a complex set of rules that indicate the constraints or special instructions that the Web server must follow. Access to a folder may be based on

The IP address is constrained to a specific folder, and the user name and password can also be configured. These options also include working with specific files, for example, if you provide a list of directories, how to

Or output results should be compressed.

These configurations appear as containers in httpd.conf, such as <directory>, in order to specify that the configuration used refers to a location on disk, and again, such as <location>

The reference is the path in the URL. Listing 2 shows an actual directory container.



Ini

The configuration of PHP is done in php.ini. Four important settings control how much of the system resources PHP can use, as listed in table 1.

Table 1. Resource-related settings in php.ini

Set Description Suggestion Value

Max_execution_time How many CPU seconds a script can use 30

Max_input_time How long a script waits for input data (seconds) 60

Memory_limit How much memory (in bytes) a script can use before it is canceled 32M

How much data (bytes) need to be cached before output_buffering data is sent to the client 4096

The exact number depends on your application. If you want to receive large files from the user, then the max_input_time may have to be increased, can be modified in php.ini, or

It can be overridden by code. Similarly, programs that are CPU-or memory-intensive may also require a larger set-up value. The goal is to mitigate the effects of excessive procedures and therefore not build

Disable these settings globally. There is one more thing to note about Max_execution_time: It represents the CPU time of the process, not the absolute time. So a progressive

A program that runs large amounts of I/O and a small number of computations may run far more than Max_execution_time. This is also max_input_time can be greater than

The reason for Max_execution_time.

The number of log records that PHP can perform is configurable. In a production environment, disabling all log records except for the most important logs can reduce disk write operations. If you need to use

Log to troubleshoot problems, you can enable logging on demand. error_reporting = e_compile_error| e_error| E_core_error will enable sufficient

Logging that lets you discover problems while eliminating a lot of useless content from the script.

Back to top of page


This article is from the "Bug Private Cuisine" blog, please be sure to keep this source http://rex9527.blog.51cto.com/6747285/1557401

LAMP System Performance Tuning: Part 2nd: Optimizing Apache and php-Learning notes

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.