Apache High Memory Solution

Source: Internet
Author: User

I use a 512M VPS, access is small, but memory consumption is very large, even downtime.

I use top, and then Shitf+m found that httpd occupies great memory. After the online search data set up, after a period of time and finally no more memory problems.

First find the location of the configuration file, you can use the following command:

Find/-name httpd.conf
Locate the configuration file/usr/local/apache/conf/extra/httpd-mpm.conf, modify the Settings Apache MPM prefork module

Startservers 3
Minspareservers 2
Maxspareservers 5
Serverlimit 256
MaxClients 256
Maxrequestsperchild 40

My original maxrequestsperchild was 0, and the problem should be here.

startservers sets the number of child processes that are established when the server starts
Minspareservers and maxspareservers set the minimum and maximum number of idle child processes respectively

serverlimit is the maximum value that can be used to control the maxclients. Reducing maxclients can make a big difference to the server that runs dynamic content (for example, WordPress). If your VPS encounters a significant increase in traffic and your maxclients is set too high, your server will work indefinitely to swap pages from physical memory to virtual memory, resulting in downtime. The general calculation of the appropriate MaxClients value depends on the total amount of system memory available to you, in addition to the memory used by each Apache process. For example, if you have 500MB of memory available for Apache, and each Apache process uses approximately 20MB of memory, you can set your maxclients to (512-12)/10 = 50 (this calculation seems to be incorrect in the original). Use the command top to get your VPS real-time memory usage.

maxrequestsperchild This instruction sets the number of requests that a separate subprocess will be able to process. After processing the "Maxrequestsperchild number" request, the child process will be terminated by the parent process, the memory of the child process will be freed, and if there is another access request, the parent process will re-generate the child process to process. If the Maxrequestsperchild preset is 0 (infinity) or a larger number (for example, more than 10000), you can make each subprocess handle more requests, not because the child process is constantly terminating, and the sub-processes start to reduce access efficiency, but Maxrequestsperchild is set to 0 o'clock, If the 200~300m memory is occupied, it will not reduce the amount of memory that is occupied by the load. Servers with large memory can be set to 0 or larger numbers. Servers with smaller memory may wish to be set to 50, 100, 200 to prevent memory overflow.

Locate the configuration file/usr/local/apache/conf/extra/httpd-default.conf, modify the KeepAlive settings

# timeout:the number of seconds before receives and sends time out.
#
Timeout (
#
# Keepalive:whether or not-to-allow persistent-connections (more than
# One request per Co nnection). Set to ' Off ' to deactivate.
#
KeepAlive on
#
# maxkeepaliverequests:the Maximum number of requests to allow
# during a persistent con Nection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
Maxkeepaliverequests
#
# Keepalivetimeout:number of seconds to wait for the next request from the
# Same client on the same connection.
#
KeepAliveTimeout 5

Timeout is a connection how much time after the disconnection, this parameter is set in 30-60 is the general PHP program is applicable, at least to run some to occupy a large amount of time of the PHP program, then the appropriate adjustment is also possible, but please do not too high, otherwise it will affect Apache performance, This optimization is enough for us to use 30.

Maxkeepaliverequests is a connection to the largest number of requests, for the page has more pictures and other elements, can be appropriately adjusted higher, for the General page settings in 80-120 is enough, we set to 120, Setting too high will cause httpd to fail to release memory for a long time.

KeepAliveTimeout is when a user processes a connection, if there is a request within the time of the parameter, the execution continues without the need to recreate the new connection until the maximum value of maxkeepaliverequests is reached. For Perfork mode, some people think that will be keepalive off will be better, but for most of the site will not be much more than a few picture elements, so the item opened, and set the keeptimeout in 2-5 seconds, not only effectively improve server performance, It can also speed up the page opening.

If you also need to optimize the module can be considered to modify the startup, WordPress mainly use the following modules, keep these other can be commented out

loadmodule authz_host_module modules/mod_authz_host.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule expires_module modules/mod_expires.so
LoadModule deflate_module modules/mod_deflate.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule mime_module modules/mod_mime.so
LoadModule autoindex_module modules/mod_autoindex.so
LoadModule Dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
LoadModule rewrite_module modules/ mod_rewrite.so
LoadModule negotiation_module modules/mod_negotiation.so

reprint Please specify:Apache high Memory solution-front-end development


Apache High Memory Solution

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.