Hello,
I logged into my linode yesterday and realized MySQL wasn't on. It had been killed (from reading dmesg) because it was out of memory. My Swap was also 100%. I believe it was PHP fpm taking up all of the memory. I changed the configs and am curious if I am missing anything else to help performance so this won't happen again, especially at times when more traffic hits. Even with this config, Longview shows php5-fpm using 900MB-1GB of memory and I only have a 1 GB linode.
Current ubuntu status when i just logged in shows memory usage: 55% and swap usage: 14%, 155 processes.
I am currently doing a FPM pool for each subdomain and domain hosted (there's 2 main domains hosted). Is that best or should I actually just use 1?
Any help is appreciated! Sanitized configs below.
NginxCode:
user www-data;
worker_processes 8;
pid /var/run/nginx.pid;
events {
worker_connections 768;
# multi_accept on;
}
http {
##
# Basic Settings
##
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
# server_tokens off;
# server_names_hash_bucket_size 64;
# server_name_in_redirect off;
include /etc/nginx/mime.types;
default_type application/octet-stream;
##
# Logging Settings
##
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
##
# Gzip Settings
##
gzip on;
gzip_disable "msie6";
# gzip_vary on;
# gzip_proxied any;
# gzip_comp_level 6;
# gzip_buffers 16 8k;
# gzip_http_version 1.1;
# gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;
FPM pool 1 (main site)Code:
[domain.com]
listen = /var/run/php5-fpm/domain.com.socket
listen.backlog = -1
; Unix user/group of processes
user = myaccount
group = www-data
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 25
pm.start_servers = 4
pm.process_idle_timeout = 10s
pm.min_spare_servers = 4
pm.max_spare_servers = 10
pm.status_path = /status
pm.max_requests = 500
security.limit_extensions = .php .html .run
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
PHP fpm pool 2 (admin, low usage subdomain)Code:
[admin.domain.com]
listen = /var/run/php5-fpm/admin.domain.com.socket
listen.backlog = -1
; Unix user/group of processes
user = myaccount
group = www-data
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 25
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 20
pm.max_requests = 500
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
fpm pool 3 (admin subdomain, little more usage, still for public use)Code:
[races.domain.com]
listen = /var/run/php5-fpm/races.domain.com.socket
listen.backlog = -1
; Unix user/group of processes
user = myaccount
group = www-data
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 10
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.max_requests = 200
security.limit_extensions = .php .html .run
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
fpm pool domain 2, public use. wordpressCode:
[domain2.com]
listen = /var/run/php5-fpm/domain2.com.socket
listen.backlog = -1
; Unix user/group of processes
user = myaccount
group = www-data
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 25
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
pm.process_idle_timeout = 10s
pm.max_requests = 500
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
fpm pool staging domainCode:
[test.domain.com]
listen = /var/run/php5-fpm/test.domain.com.socket
listen.backlog = -1
; Unix user/group of processes
user = myaccount
group = www-data
; Choose how the process manager will control the number of child processes.
pm = dynamic
pm.max_children = 5
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 5
pm.max_requests = 100
security.limit_extensions = .php
; Pass environment variables
env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp
MySQL my.cnfCode:
[client]
port = 3306
socket = /var/run/mysqld/mysqld.sock
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
# This was formally known as [safe_mysqld]. Both versions are currently parsed.
[mysqld_safe]
socket = /var/run/mysqld/mysqld.sock
nice = 0
[mysqld]
#
# * Basic Settings
#
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
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 127.0.0.1
#
# * Fine Tuning
#
key_buffer = 16M
max_allowed_packet = 1M
thread_stack = 64K
thread_cache_size = 8
sort_buffer = 64K
net_buffer_length = 2K
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover = BACKUP
#max_connections = 100
table_cache = 4
query_cache_limit = 1M
query_cache_size = 16M
log_error = /var/log/mysql/error.log
expire_logs_days = 10
max_binlog_size = 100M
[mysqldump]
quick
quote-names
max_allowed_packet = 16M
[mysql]
#no-auto-rehash # faster start of mysql but no tab completition
[isamchk]
key_buffer = 16M
#
# * IMPORTANT: Additional settings that can override those from this file!
# The files must end with '.cnf', otherwise they'll be ignored.
#
!includedir /etc/mysql/conf.d/