Apache_ Performance Tuning

Source: Internet
Author: User
Tags dedicated server

Apache transliteration, is a North American Indian tribe, called the Apache tribe, in the southwest of the United States. Legend has it that Apache is a samurai, he is heroic, and invincible, by the Indians as a courageous and victorious representatives, so posterity will use his name for the Indian tribe named, and Apache in the Indian history is also known for strong. Apache is the first WEB server in the world to use. It can run on almost all of the widely used computer platforms.
Use APAHCE to calculate memory consumption first when you are planning your Web performance capacity:
Apache_max_process_with_good_perfermance < (total_hardware_memory/apache_memory_per_process) * 2
apache_max_process = apache_max_process_with_good_perfermance * 1.5
Why would there be a apache_max_process_with_good_perfermance and a apache_max_process? The reason is that under low load the system can use more memory for the cache of the file system, thus further increasing the response speed of individual requests. Under high load, the system's individual request response speed is much slower, and more than apache_max_process, the system will start using the hard disk to do virtual memory swap space, resulting in a sharp decline in system efficiency. In addition, the same service: the memory of the machine's apache_max_process 2G is generally only set to 1G of memory 1.7 times times, because Apache itself due to excessive process results in performance degradation.
Example 1:
An Apache + mod_php server: An Apache process typically requires 4 m of memory
So on a 1G memory machine: Apache_max_process_with_good_perfermance < (1g/4m) * 2 = 500
apache_max_process = 500 * 1.5 = 750
So plan your app so that the service runs as far as 500 processes below to maintain a higher efficiency and set Apache's soft upper limit at 800.
Example 2:
An Apache + mod_resin server: An Apache process typically requires 2 m of memory
On a machine with 2G of memory:
Apache_max_process_with_good_perfermance < (2g/2m) * 2 = 2000
apache_max_process = 2000 * 1.5 = 3000
Apache's machine and operating system environment is the most performance-impacting factor, it is clear that a 368 PC with a P4 or dual-processor machine does not have the same performance. However, if hardware changes are not involved, the biggest thing we can do is to first see if Apache is running on a dedicated server, and if sharing a server with other applications is sure to affect the performance of the server.
In most cases, especially for static sites, the amount of memory is a key factor in performance, because it determines how much content Apache can cache. The more content it caches, the less chance it will be to read content on the hard disk, and access to specific files on the hard disk is a time-consuming operation. If your site is mostly static content, you'd better use the Mod_cache option, if your memory is large enough, you can use the Mod_mem_cache option.
The first option caches the information on disk, and it works well when used with the Mod_include option, which saves its final version in the cache when a page is created. Use Mod_mem_cache to store cached content in a memory heap that can be shared by all Apache processes.
Using faster disks or further using RAID can increase Apache access to disk files. Note that if you do all of these optimizations below, a hardware (rather than software) upgrade scenario is a better choice. The last one on the hardware problem is CPU capability, which has a great impact on dynamic content sites, the more dynamic content requirements higher.
The following are the performance configuration parameters that affect Apache:
Timeout 300
Specifies the number of seconds that the site responds. If the data has not been received or sent over this period of time, the connection will be disconnected. This parameter specifies the maximum wait time (in seconds) before Apache receives a request or sends the requested content, and if it exceeds that time, Apache discards the processing.
and release the connection. The default value for this parameter is 120, the recommended setting is 60, and for sites with a large amount of traffic you can set it to 30.
KeepAlive on| Off
Enabling this means allowing persistent connections to be made to make multiple requests per connection. Avoid establishing a connection with the server every time a file is requested. That is, control whether Apache allows multiple requests in a connection, which is turned on by default. However, for most forum type sites, it is usually set to off to turn off this support.
Maxkeepaliverequests 100
The number of requests per connection can be set to 0 for an unlimited number, and the default value is 100.
KeepAliveTimeout 15
The time between successive two requests per connection is considered a connection outage if more than 15 seconds have not arrived. This approach maximizes the use of limited resources, which is one of the reasons Apache performance is so superior.
Minspareservers 5
Maxspareservers 20
Apache automatically adjusts the number of idle child processes at run time based on the weight of the load.
The number of httpd processes that provide browsing services needs to vary with the number of connections, so it is necessary to keep several idle httpd processes waiting for new connection requests at any time. If the number of idle processes is less than 5 (the default), it means that there are too few idle processes and need to increase them to 5;
More than 20 (the default) means that there are too many idle processes and need to reduce them to 20.
MaxClients 150
Too many simultaneous accesses can degrade system access performance, set this parameter to limit the maximum number of simultaneous connections, the default value is 150,
It sets the request that Apache can process at the same time, which is the most influential parameter to Apache performance.
    MaxClients  and  MaxRequestPerchild;MaxClients  designation  Apache  At the same time, the maximum number of clients allowed   to connect with, if more than  MaxClients  connections, the client will get a "server Busy" error page. We see the default   case  MaxClients  set to  15, which is obviously not enough for some medium-sized sites and large sites! Maybe you need to allow  512  client connections at the same time to meet the application needs, OK, so let's change  MaxClients  to  512, save  httpd.conf  and   Exit, restart  apache, unfortunately, during the restart process you see some error prompts,apache  restart failed. Error message   You  MaxClients  maximum can only be set to  256, I believe you must be very disappointed. But don't be depressed.,apache  as a world-class  Web Server  must not be so thin! By default,maxclients  can only be set to no more than  256  integers, but if   you need to be completely customizable, you need to use  ServerLimit  Parameters to use, simply say  ServerLimit  is like a   bucket, and  MaxClients  is like water, you can change the larger bucket by replacing it ( serverlimit   set to a larger value) to accommodate   more water (maxclients), but note that the set value of,maxclients  cannot be greater than the set value of  ServerLimit ! Let's take a look at the  MaxRequestPerChild  parameter below, which specifies how many threads in a connection process can work at the same time. Perhaps   This is too professional to explain, then you just think "network Ant", "Internet Express  flashget" in the "multi-point simultaneous download" thatYes, this parameter is   is limited to a maximum of a few "points". The default setting is  0, which is: No limit. However, it is important to note that if you set this value too small   cause access problems, if there is no special need or the traffic pressure is not very large can keep the default value, if the traffic is very large then recommended settings   for  2048
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 a different server to process picture files.
# Make sure that your Web pages and CGI pages use 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,
Use the # number to comment out the unwanted modules.
# If you don't 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 "AllowOverride None", which eliminates the hardship of Apache in every directory search. htaccess file.
# 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.
# in the CGI script:
* File I/o: The fewer files you open, the better.
* Shell command: Use full path to invoke shell command.
* If your site is primarily powered by CGI, then use Mod_perl.
* In your Web page directory, do not let the number of files more than 1000, the more files spent on positioning more time.
# The fewer pictures on the WEB server, the better, ensure that each picture is run through the picture compressor.
# do stress tests on your website and suggest using Apache's own AB command to test.
# for best performance, unplug the network cable so your WEB server is safe and the load drops to 0 immediately.

Apache_ Performance Tuning

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.