Linux 512M VPS Memory optimization Steps detailed

Source: Internet
Author: User
Tags fpm vps

512M VPS Optimized Apache memory

View current memory consumption

Ps Aux|grep httpd

Basic one occupies about 50M

PS Aux|grep httpd | Wc–l

A total of 13, minus the grep httpd line of 12, indicating a footprint of about 600M
Server 512M memory exceeded,

(in contrast, nginx main process 50M, with PHP-FPM run, a fpm occupied 2M, open 10 fpm process, a total of 70M of memory is enough. )

Standard Linux Apache configuration in Apache configuration file in/etc/httpd/conf/httpd.conf

But Lampp is not in httpd.conf, but in extra/http-default.conf.
Two places respectively corresponding to two modules Prefork module and the worker module (Apache is the default enabled Prefork module), according to their own server-enabled modules to modify the corresponding parameters, you can use the command httpd-l to view the module used by Apache.
The meaning of each parameter is explained as follows:
startservers//Specifies the number of child processes established when the server is started, prefork defaults to 5. If your memory footprint is too large, this value can be reduced appropriately.
minspareservers//Specifies the minimum number of idle child processes, which defaults to 5. If the current number of idle child processes is less than minspareservers, Apache will produce a new subprocess at a maximum rate of one per second.
maxspareservers//sets the maximum number of idle child processes, defaults to 10. If there is currently an idle subprocess exceeding the maxspareservers number, the parent process kills the extra child processes. If you set the value of the directive to be smaller than Minspareservers, Apache will automatically modify it to "Minspareservers+1″."
maxclients//limits the number of client maximum access requests at the same time (number of concurrent threads per process) and defaults to 256. Any requests exceeding the maxclients limit will enter the waiting queue, and once a link is released, the request in the queue will be serviced. To increase this value, you must increase the serverlimit at the same time.
serverlimit//default maxclient maximum is 256 threads, if you want to set a larger value, add serverlimit this parameter. 20000 is the maximum value for serverlimit this parameter. Note that for this parameter to take effect: you must precede the maxclients instruction.
maxrequestsperchild//The maximum number of requests that each subprocess allows for the servo during its lifetime, defaults to 10000. After the limit of the Maxrequestsperchild is reached, the child process will end. If Maxrequestsperchild is "0″", the child process will never end. It is recommended that this value be set to a value other than 0 to prevent memory leaks and reduce the number of active processes when the server load is mitigated, which can be reduced if memory consumption is too large.
There are several more parameters in the worker module, as explained below:
threadlimit//The maximum number of threads configurable per child process. This directive sets the Threadsperchild limit for the number of threads that can be configured per child process. Any changes to this instruction during the reboot will be ignored, but the changes to the Threadsperchild will take effect. The default value is "64″."
minsparethreads//Minimum number of idle threads, the default is "75″." This MPM will monitor the number of idle threads based on the entire server. If the total number of idle threads in the server is too small, the child process will produce a new idle thread.
maxsparethreads//Set maximum number of idle threads. The default value is "250″." This MPM will monitor the number of idle threads based on the entire server. If the total number of idle threads in the server is too numerous, the child process kills the extra idle threads. The range of maxsparethreads values is limited. Apache will automatically fix the value you set as follows: The worker requires it to be greater than or equal to Minsparethreads plus threadsperchild.
Threadsperchild//The number of resident execution threads established by each child process. The default value is 25. The child processes create these threads at startup and no longer create new threads.
After you modify the save, to make the configuration effective, you need to perform the service httpd stop
Then service httpd start
Direct service httpd Restart cannot make modified configuration effective!
Feel the need to explain the Preforx module startservers, minspareservers, maxspareservers the relationship between the parameters, so that when your host memory is not enough, you can modify these values according to your actual situation!
When Apache starts, Apache initiates a startservers idle process while preparing to receive processing requests, and when multiple requests arrive, the starservers process becomes smaller, and when the idle process is reduced to minspareservers, In order to continue to have sufficient process processing requests, Apache will restart Startsservers process standby until the remaining number of idle processes arrives at maxspareservers, thus greatly reducing the likelihood of request queue waiting, resulting in improved service efficiency, This is also the reason for what is called pre-fork;

<ifmodule mpm_prefork_module>
Startservers 2
Minspareservers 2
Maxspareservers 4
MaxClients 150
Maxrequestsperchild 20
</IfModule>

This finally starts 4 processes altogether, the Apache consumes memory 200M altogether (still much better than Nginx). )

For small web sites so play, also make up, traffic is big, or to buy a big memory VPS it. Or use Nginx to be better.

Optimizing Database MySQL

Database Memory Better View
Ps Aux|grep MySQL

Direct display takes up 300M

The actual maximum consumption or card on MySQL, PHP if there is like query, 512M of memory basically can't carry. And the speed is very slow. So as much as possible to control MySQL execution time to the shortest.

Related Article

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.