メモリが32GBになったのでパフォーマンスチューニング
自宅サーバーのメモリが32GB、CPUがHTで8コアになったので、それに伴ってMySQLとNginxのパフォーマンス設定を大幅に見直しました。具体的には以下に書き換えました。
MySQLのmy.cnf
[mysqld]
# buffers
key_buffer = 128M
max_allowed_packet = 16M
table_open_cache = 1024
max_connections = 2048
max_connect_errors = 20000
sort_buffer_size = 2M
read_buffer_size = 2M
myisam_sort_buffer_size = 2M
thread_cache = 512
query_cache_size = 512M
query_cache_type = 1
thread_concurrency = 16
tmp_table_size = 128M
max_heap_table_size = 128M
skip-name-resolve
character-set-server=utf8
default-storage-engine=InnoDB
# InnoDB configurations
innodb_buffer_pool_size=22G
innodb_additional_mem_pool_size=40M
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_thread_concurrency = 32
innodb_flush_log_at_trx_commit = 1
innodb_log_file_size = 256M
innodb_log_buffer_size = 32M
innodb_log_files_in_group = 2
innodb_flush_method=O_DIRECT
innodb_lock_wait_timeout = 120
innodb_io_capacity = 3000
Nginxのnginx.conf
worker_processes 8;
events {
worker_connections 8192;
use epoll;
}
http {
include mime.types;
default_type application/octet-stream;
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=czone:4m max_size=200m inactive=360m;
proxy_temp_path /usr/local/nginx/tmp;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_min_length 0;
gzip_buffers 4 8k;
gzip_types text/plain text/xml application/x-javascript text/css;
gzip_disable "msie6";
gzip_vary on;
# HttpStaticGzipModuleをオンに
gzip_static on;
include conf.d/*.conf;
server {
listen 8001;
server_name _;
access_log /var/log/nginx/fastcgi-access.log;
location / {
root /srv/www/html;
index index.php index.html index.htm;
# static files
if (-f $request_filename) {
expires 30d;
break;
}
# request to index.php
if (!-e $request_filename) {
rewrite ^(.+)$ /index.php?q=$1 last;
}
}
location ~ \.php$ {
alias /srv/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /srv/www/html/$fastcgi_script_name;
include fastcgi_params;
}
}
upstream backend {
ip_hash;
server 127.0.0.1:8001;
}
upstream yast {
ip_hash;
server 127.0.0.1:4984;
}
server {
listen 80;
server_name www.geek.sc;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location ~ .*\.(htm|html|jpg|JPG|gif|GIF|png|PNG|swf|SWF|css|CSS|js|JS|inc|INC|ico|ICO) {
root /srv/www/html;
index index.html;
ssi off;
break;
}
location / {
if ($http_cookie ~* "comment_author_|wordpress_(?!test_cookie)|wp-postpass_" ) {
set $do_not_cache 1;
}
if ($http_user_agent ~* “2.0\ 2MMP|240×320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800″) {
set $do_not_cache 1;
}
proxy_no_cache $do_not_cache;
proxy_cache_bypass $do_not_cache;
proxy_pass http://backend;
proxy_cache czone;
proxy_cache_key "$scheme://$host$request_uri";
proxy_cache_valid 200 302 60m;
proxy_cache_valid 404 20m;
}
if ( -f $request_filename ) {
break;
}
location /admin {
alias /srv/www/html/admin;
set $auth "true";
if ($remote_addr ~ "^10\.0\.0\.") {
set $auth "false";
}
if ($auth = "true") {
return 555;
}
error_page 555 = @auth;
index index.php index.html index.htm;
}
location @auth {
auth_basic "Saito Server Security";
auth_basic_user_file "/srv/www/.htpasswd";
root /srv/www/html/;
}
location /nginx_status {
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
rewrite /admin/yast https://www.geek.sc:4984/ permanent;
rewrite /dropbox https://www.dropbox.com/sh/dr0p0sramwp4ocy/WdVASFo5uV permanent;
}
server {
listen 80;
server_name www.mirai-city.org;
location / {
rewrite ^ https://www.geek.sc permanent;
}
}
この数値はあくまで暫定値です
この数字はあくまで暫定値です。しっかりパフォーマンスが出るか、よくよく計測してみますね!