I am worrying about my memory usage as it is reaching more than 90% if I will not restart php-fpm.
I have the following configuration on my MySQL:
[client] port = 3306 socket = /var/run/mysqld/mysqld.sock [mysqld_safe] socket = /var/run/mysqld/mysqld.sock nice = 0 [mysqld] user = mysql pid-file = /var/run/mysqld/mysqld.pid socket = /var/run/mysqld/mysqld.sock port = 3306 basedir = /usr datadir = /var/lib/mysql tmpdir = /tmp lc-messages-dir = /usr/share/mysql skip-external-locking key_buffer = 16M max_allowed_packet = 16M thread_stack = 192K thread_cache_size = 8 myisam-recover = BACKUP max_connections = 250 table_cache = 4K wait_timeout = 1200 query_cache_limit = 1M query_cache_size = 128M join_buffer_size = 2M log_error = /var/log/mysql/error.log log_slow_queries = /var/log/mysql/mysql-slow.log long_query_time = 1 expire_logs_days = 10 max_binlog_size = 100M innodb_buffer_pool_size = 5G [mysqldump] quick quote-names max_allowed_packet = 16M [isamchk] key_buffer = 16M !includedir /etc/mysql/conf.d/
I am running nginx & php-fpm.
Two of my sites with lots of traffic are configured with this settings:
PHP-FPM pm.max_children: 64 PHP-FPM pm.start_servers: 20 PHP-FPM pm.min_spare_servers: 15 PHP-FPM pm.max_spare_servers: 64 PHP-FPM pm.max_requests: 500
The rest of my sites are configured using the following settings:
PHP-FPM pm.max_children: 64 PHP-FPM pm.start_servers: 10 PHP-FPM pm.min_spare_servers: 5 PHP-FPM pm.max_spare_servers: 15 PHP-FPM pm.max_requests: 500
When I restart mysql server and php-fpm, the initial size of memory consumed is 85%. I created a script to monitor the consumption of the memory and if it reaches 90% I automatically restarted php-fpm. I don't know if this is a good idea.
When the number of php-fpm server running increase, the memory usage also increased rapidly.
I used the following command to monitor the number of php-fpm server running:
smem -u -t -k
The example output are:
User Count Swap USS PSS RSS web8 22 0 1017.7M 1.0G 1.4G web2 20 0 1.1G 1.1G 1.3G
The output above is good when the number of server/count does not increase. But when it increase up to 64, which is the highest value of
PHP-FPM pm.max_spare_servers. There come's the problem. The memory increased rapidly.
BTW, here's the specs of my server:
Intel® Xeon® E3-1270 v2 Single Processor - Quad Core Dedicated Server CPU Speed: 4 x 3.5 Ghz w/ 8MB Smart Cache Motherboard: SuperMicro X9SCM-F Total Cores: 4 Cores + 8 Threads RAM: 32 GB DDR3 1333 ECC Hard Drive: 120GB Smart Cache: 8MB
Can anybody suggest the best settings for my server?