Optimization scheme for Linux VPS server with Insufficient memory

Source: Internet
Author: User
Tags fpm socket system log tainted vps server memory vps server

Ever since I moved one of my websites to the Linode 1G VPS, I've always felt a little less normal. First of all dnspod monitoring on the display site can sometimes access, sometimes not. The WP Supercache plugin then restarts after a frequent failure in the execution of a pre-cached task, and the message content such as "[http://www.111cn.net] pre-caching may have lost its response." The pre-cache has been restarted. ”。 There is also a situation where Linode sometimes send disk IO to use high alert messages.

Today, the time to check the next server, found a phenomenon is the MySQL process of frequent unwarranted restart.

150424 17:41:14 [note] Event scheduler:loaded 0 Events
150424 17:41:14 [note]/usr/local/mysql/bin/mysqld:ready for connections.
Version: ' 5.5.37 ' socket: '/tmp/mysql.sock ' port:3306 Source distribution
150424 19:27:16 mysqld_safe Number of processes running now:0
150424 19:27:16 Mysqld_safe mysqld restarted
150424 19:27:24 [note] Plugin ' InnoDB ' is disabled.
150424 19:27:24 [note] Server hostname (bind-address): ' 0.0.0.0 '; port:3306
150424 19:27:24 [note]-' 0.0.0.0 ' resolves to ' 0.0.0.0 ';
150424 19:27:24 [note] Server socket created on IP: ' 0.0.0.0 '.
150424 19:27:24 [Warning] ' user ' entry ' root@li676-235 ' ignored in--skip-name-resolve mode.
150424 19:27:24 [Warning] ' proxies_priv ' entry ' @ root@li676-235 ' ignored in--skip-name-resolve mode.
150424 19:27:25 [note] Event scheduler:loaded 0 Events
150424 19:27:25 [note]/usr/local/mysql/bin/mysqld:ready for connections.
Version: ' 5.5.37 ' socket: '/tmp/mysql.sock ' port:3306 Source distribution
Through this log, MySQL prompts him to run difficult, which means that the server resources are not enough, and then start checking.


The error log message "Mysqld_safe number of processes running now:0″indicates scarcity for resources to pursue the Oper Ations.


Run free-m, found that there are more free memory, almost only half.

[root@li676-235 ~]# Free-m
Total used free shared buffers Cached
mem:990 903 87 0 114 351
-/+ buffers/cache:436 554
SWAP:255 53 202

In order to determine if the server resources are really not enough, the method is to see if the system log has oom (out of memory) killer run, and indeed found many similar logs in the log.

[root@li676-235 var]# egrep-i "Oom|kill|mysql"/var/log/messages |more
APR 13:36:16 li676-235 kernel:mysqld invoked oom-killer:gfp_mask=0x201da, order=0, oom_score_adj=0
APR 13:36:16 li676-235 kernel:mysqld cpuset=/mems_allowed=0
APR 13:36:16 li676-235 kernel:cpu:0 pid:16020 comm:mysqld not tainted 3.18.5-x86_64-linode52 #1
APR 13:36:16 li676-235 kernel: [<ffffffff8112695f>]? oom_kill_process+0x65/0x32f
APR 13:36:16 li676-235 kernel: [PID] uid tgid total_vm RSS nr_ptes swapents Oom_score_adj Name
APR 13:36:16 li676-235 kernel: [12128] 0 12128 26564 1 0 mysqld_safe
APR 13:36:16 li676-235 kernel: [12405] 501 12405 155926 2868 3676 0 mysqld
APR 13:36:16 li676-235 kernel:out of Memory:kill process 9703 (PHP-FPM) score A/sacrifice child
APR 13:36:16 li676-235 kernel:killed process 9703 (PHP-FPM) total-vm:266976kb, anon-rss:38932kb, file-rss:0kb
APR 13:36:23 li676-235 kernel:mysqld invoked oom-killer:gfp_mask=0x201da, order=0, oom_score_adj=0
APR 13:36:24 li676-235 kernel:mysqld cpuset=/mems_allowed=0
APR 13:36:24 li676-235 kernel:cpu:0 pid:12405 comm:mysqld not tainted 3.18.5-x86_64-linode52 #1
APR 13:36:24 li676-235 kernel: [<ffffffff8112695f>]? oom_kill_process+0x65/0x32f
APR 13:36:24 li676-235 kernel: [PID] uid tgid total_vm RSS nr_ptes swapents Oom_score_adj Name
APR 13:36:24 li676-235 kernel: [12128] 0 12128 26564 1 0 mysqld_safe
APR 13:36:24 li676-235 kernel: [12405] 501 12405 156056 2873 3676 0 mysqld
APR 13:36:24 li676-235 kernel:out of Memory:kill process 18168 (PHP-FPM) score or sacrifice child
APR 13:36:24 li676-235 kernel:killed process 18168 (PHP-FPM) total-vm:263724kb, anon-rss:24872kb, File-rss:0kB
Through this log, you can clearly see Oom kill in "APR 23 13:36:16" was triggered by the PHP-FPM, that is, PHP was forced to kill the system. I set the maximum number of php-fpm processes that can be opened is 20. According to 20*30 = 600M, PHP is likely to consume more resources than 600M.

"APR 23 13:36:16" The Nginx log is shown in the following figure:

With the Nginx log, you can determine that the PHP process was open a lot, resulting in insufficient system resources.

My solution is to reduce the number of pm.max_children. Of course, this value will certainly sacrifice the performance of the site, but I analyzed the log found that the normal site is not so high concurrency, so the impact should not be small.

Linux VPS server memory is not enough for the first time to adjust to this, first observation for a few days.

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.