Lamp website acceleration Optimization

Source: Internet
Author: User

The Optimization for Apache is mainly for httpd. conf,

In Apache2.0, MPM is divided into three types: worker K, worker, and event ). The worker K is inherited from Apache1.3. It adopts the process management method, so it can provide more reliable performance and better compatibility. worker is the newly added method of Apache2.0, it adopts the thread control method, which can save the system overhead and process more data than the worker K, but the compatibility is not very good at the same time, and many old programs cannot work under the worker; event is still in the test phase. It allocates different process pools for each task and should not be used currently. Httpd. conf can only be used as a starting point. Even so, if you only use the httpd. conf factory default value, it is still painful.

To verify whether the following Apache parameter adjustment works, we usually use the AB (ApacheBench) attached to Apache to perform stress testing.
The most common syntax format of AB is as follows:
AB-nXXX-cYYY-khttp: // hostname. port/path/filename
Where:
-NXXX:
Indicates that up to XXX tests can be performed. That is, XXX times of downloading the filename file.
-CYYY:
Number of concurrent client connections.
-K:
The optimization points for enabling the HTTPKeepAlive feature httpd. conf are as follows:
1. KeepAlive
The factory value of the installed Apache2.0 is Off. Change to On unless your website only has no text or images. Then all the troubles come.
I have seen a service Comparison Between Web 1.0 and Web 2.0. The impression is that AdSense is, Chitika is, and Akamai is
1.0,
BitTorrent is 2.0. In fact, Akamai's image storage service mainly solves the KeepAlive problem of servers. See this sample.html:
Helloworldimgsrc = "http://blog.penner.cn/hello.gif"/>
After the browser sends the request to Apache, Apache establishes a connection for the user and returns/sample.html. the browser parses the HTML file and finds that
Display
/Hello.gif, and then send a request to Apache again. If KeepAlive is Off, Apache needs to establish a new connection. Imagine if the page is requested
For 1000 images, Apache needs to establish 1000 connections, but the N-x connections have been intelligently disabled by Apache at the nth time of creation ). If KeepAlive is
On, Apache will process all these requests in the same connection, greatly saving the connection resources. Unfortunately, there are many attackers in the world who will use the continuous features of this connection to keep sending requests.
To consume server resources. All major companies, such as yahoow.aol, choose akamaias the image storage service, and the sample.html version of these companies is like this.
Sub:
Helloworldimgsrc = "/hello.gif"/>
(The actual image address is more complex than this) so that each user access will only send a request to Apache on the local server, and the remaining requests will be sent to akamai. Don't worry about akamai's capabilities, because it has enough anti-Load Technology, Web2.0 speakers want to replace akamai with BT.
2. MaxKeepAliveRequests
After understanding the content in 1, you can see the maximum number of requests that a connection can send. The default value is 500.
3. KeepAliveTimeout
Similarly, if the number of two requests exceeds this value, the connection is interrupted. If your KeepAlive is On and MaxKeepAliveRequests is 500,
KeepAliveTimeout is 100. You can calculate how long it takes for attackers to consume your Apache. I set KeepAliveTimeout to 5 because
Considering the Internet access speed and the size and quantity of website images, most pages can be loaded in five seconds.
4. StartServers
StartServers
Indicates the number of httpd files created directly after Apache is started. For example, your server requires an average of 100 httpd requests. If you set StartServers to 10
As a result, the remaining 90 httpd files are continuously created at the beginning of Apache startup. If your server uses up to 20 httpd servers at ordinary times, setting StartServers to 50 wastes resources.
Source. This parameter is no big deal, because Apache tends to be suitable for the number of httpd services.
5. MinSpareServers and MaxSpareServers
Retain the minimum and maximum number of alternate httpd services. That is, when so many httpd services are not required, at least MinSpareServers services are retained, but not more than MaxSpareServers services. Search for experience values based on Apache running.
6. ServerLimit, MaxClients
An important value. ServerLimit is usually equal to MaxClients. MaxClients determines the maximum number of httpd processes.
Now
The number of httpd services of MaxClients, and your website rejects normal access. However, the size of MaxClients is limited by the memory, so the default value of Apache2 is
250, with the ServerLimit parameter added as the limit, if you want to set a large MaxClients, you must expand ServerLimit at the same time, but ServerLimit is not
It should exceed MaxClients.
7. MaxRequestsPerChild
It determines the maximum number of requests that each httpd service can process. If this number is exceeded, a new httpd service is required. The latter is restricted by MaxClients, and the number of requests is completely different. My MaxRequestsPerChild is 10000.
8. HostnameLookups
Set to Off to avoid waiting for DNS queries.
In addition to the eight parameters, another plastic point of Apache is the loaded Module, which can be commented out without the LoadModule, greatly saving the memory. But the problem is that you
I don't know which Module is not required. Even if I read the functions of each Module in the Module document of Apache, I can only comment out a few modules. Below is my practical comments
Several modules:
Mime_magic_module, info_module, userdir_module, proxy_module, proxy_ftp_module, proxy_http_module, and proxy_connect_module.
PHP accelerator
PHP has nothing to worry about ). We only recommend that you disable the database permanent connection in php. ini to avoid embarrassment.
Connections "error. Close the permanent connection to mysql in php. Even if the statement mysql_pconnect in the php client fails, the existing code is no longer worried.
An error occurs because PHP automatically treats mysql_pconnect as mysql_connect and closes the database link after the execution on the page. The disadvantage is that each access
A database link is created on a page, but different from the Apache link, because Apache has N connection opportunities on each page, and the database usually only needs to be connected once on each page.
Installing a PHP acceleration tool is more meaningful than optimizing PHP itself. Previously PHP
Eaccelerator, which is popular nowadays, has many complaints ). The eAccelerator caches the PHP file at the program layer, instead of slowing down
Save php Execution and output results, so you don't have to worry about timeliness. The eAccelerator is easy to install. You only need to implement it in steps.
EAccelerator is another weapon that can significantly speed up the website following the upgrade of hardware, memory, and MySQL to 4.x mentioned above.

This article from "Good to live" blog, please be sure to keep this source http://wolfword.blog.51cto.com/4892126/1295028

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.