Mysql Optimization Aspects:
1.sql Statement Optimization
Creating index: Create index Idx_user_openid_ptid on Tb_pt_user (Openid,ptid);
2. Server configuration optimization, mainly optimize the cache
Configuration file location: /etc/my.cnf
[Mysqld]
Datadir=/var/lib/mysql
Socket=/var/lib/mysql/mysql.sock
User=mysql
# Disabling Symbolic-links is recommended to prevent assorted security risks
Innodb_buffer_pool_size = 1G
Innodb_additional_mem_pool_size = 64M
Innodb_thread_concurrency = 8
Innodb_flush_log_at_trx_commit = 1
Innodb_log_buffer_size = 128M
Innodb_log_file_size = 512M
Innodb_log_files_in_group = 2
innodb_max_dirty_pages_pct = 90
Innodb_lock_wait_timeout = 60
# SAFETY #
Max-allowed-packet = 16M
Max-connect-errors = 1000000
Skip-name-resolve
Sysdate-is-now = 1
# CACHES and LIMITS #
Tmp-table-size = 32M
Max-heap-table-size = 32M
Query-cache-type = 0
Query-cache-size = 0
Max-connections = 15000
Thread-cache-size = 50
Open-files-limit = 65535
Table-definition-cache = 1024
Table-open-cache = 2048
[Mysqld_safe]
Log-error=/var/log/mysqld.log
Pid-file=/var/run/mysqld/mysqld.pid
[Client]
Port = 3306
Default-character-set=utf8
Nginx Optimization
Configuration file location:/etc/nginx/nginx.conf
# For more information on configuration, see:
# * Official 中文版 documentation:http://nginx.org/en/docs/
# * Official Russian documentation:http://nginx.org/ru/docs/
User Nginx;
Worker_processes 8; #1; The server 172.16.30.201 has 8 CPUs, modified by Shao xiaoling
Worker_cpu_affinity 00000001 00000010 00000100 00001000 00010000 00100000 01000000 10000000; # The server 172.16.30.201 have 8 CPUs, modified by Shao xiaoling
Worker_rlimit_nofile 150000;
Error_log/var/log/nginx/error.log;
#error_log/var/log/nginx/error.log Notice;
#error_log/var/log/nginx/error.log Info;
Pid/var/run/nginx.pid;
Events {
Worker_connections 150000;
Multi_accept on;
Use Epoll; #epoll is one way in multiplexed IO (I/O multiplexing) , but only for linux2.6 Above the core , can greatly improve The performance of Nginx ; modified by Shao xiaoling
}
HTTP {
Include/etc/nginx/mime.types;
Default_type Application/octet-stream;
Log_format Main ' $remote _addr-$remote _user [$time _local] "$request" '
' $status $body _bytes_sent ' $http _referer '
' "$http _user_agent" "$http _x_forwarded_for";
Access_log/var/log/nginx/access.log main;
Sendfile on;
Tcp_nopush on;
Tcp_nodelay on;
#keepalive_timeout 0;
Keepalive_timeout 30;
Keepalive_requests 100000;
Reset_timedout_connection on;
Client_body_timeout 10;
Send_timeout 2;
#gzip on;
gzip on; #modified by Shao Xiaoling
#the following gzip parameters added by Shao xiaoling
Gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_comp_level 6;
Gzip_types text/html text/plain text/css text/javascript application/json application/javascript application/ X-javascript Application/xml;
Gzip_vary on;
# Load config files from the/etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
include/etc/nginx/conf.d/*.conf;
}
TCP protocol Stack optimization
1. Installation Services:
Yum-y Install Netperf Iperf
2. Modify the configuration file
File Location:/etc/sysctl.conf
KERNEL.SYSRQ = 0
Kernel.panic = 20
Kernel.softlockup_panic=1
Kernel.core_uses_pid = 1
KERNEL.MSGMNB = 65536
Kernel.msgmax = 65536
Kernel.shmmax = 25769803776
Kernel.shmall = 4294967296
Kernel.shmmni = 4096
Kernel.sem = 250 32000 100 128
Kernel.hung_task_timeout_secs = 0
Kernel.core_pattern = Core
Fs.file-max = 655350
Net.ipv4.ip_forward = 0
Net.ipv4.conf.default.rp_filter = 1
Net.ipv4.conf.default.accept_source_route = 0
Net.ipv4.tcp_syncookies = 1
Net.ipv4.tcp_fin_timeout = 3
Net.ipv4.tcp_tw_reuse = 1
Net.ipv4.tcp_tw_recycle = 1
Net.ipv4.tcp_timestamps = 0
Net.ipv4.ip_local_port_range = 2000 65000
Net.ipv4.tcp_max_syn_backlog = 3240000
Net.ipv4.tcp_max_tw_buckets = 1440000
Net.ipv4.route.gc_timeout = 100
Net.ipv4.tcp_syn_retries = 2
Net.ipv4.tcp_synack_retries = 2
Net.ipv4.tcp_sack = 1
Net.nf_conntrack_max = 2048576
Net.netfilter.nf_conntrack_max = 2048576
net.netfilter.nf_conntrack_tcp_timeout_established = 60
net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_close_wait = 30
net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 30
net.ipv4.tcp_window_scaling = 1
Net.ipv4.tcp_mem = 3097431 4129911 6194862
Net.ipv4.tcp_rmem = 4096 87380 16777216
Net.ipv4.tcp_wmem = 4096 65536 16777216
Net.ipv4.tcp_congestion_control = Cubic
Net.ipv4.tcp_max_orphans = 3276800
Net.ipv4.tcp_keepalive_time = 30
Net.ipv4.tcp_keepalive_probes = 2
NET.IPV4.TCP_KEEPALIVE_INTVL = 15
Net.ipv6.conf.all.disable_ipv6 = 1
Net.ipv6.conf.default.disable_ipv6 = 1
Net.ipv6.conf.lo.disable_ipv6 = 1
Net.bridge.bridge-nf-call-ip6tables = 0
Net.bridge.bridge-nf-call-iptables = 0
Net.bridge.bridge-nf-call-arptables = 0
Net.core.wmem_default = 8388608
Net.core.rmem_default = 8388608
Net.core.rmem_max = 16777216
Net.core.wmem_max = 16777216
Net.core.netdev_max_backlog = 262144
Net.core.somaxconn = 3240000
Vm.swappiness = 5
Vm.zone_reclaim_mode = 0
Vm.overcommit_memory = 1
Vm.panic_on_oom = 0
Vm.drop_caches = 1
Vm.dirty_ratio = 30
Vm.dirty_background_ratio = 30
Vm.dirty_writeback_centisecs = 50000
Vm.vfs_cache_pressure = 200
Vm.min_free_kbytes = 256000
3. Make the configuration file effective
Sysctl-p/etc/sysctl.conf
In MySQL ,nginx modifies the configuration file by first stop service and restart service
View MySQL service status /etc/init.d/mysqld Status
View nginx Service status /etc/init.d/nginx Status
Start MySQL service status /etc/init.d/mysqld start
Start nginx Service status /etc/init.d/nginx start
Mysql Command
{Start|stop|status|restart|condrestart|try-restart|reload|force-reload}
Nginx Command
{Start|stop|reload|configtest|status|force-reload|upgrade|restart|reopen_logs}
The profile backup is based on the plus date.
Listed as:my.cnf my.cnf.20160425 4 months backup version 1
my.cnf.20160425_02 Year 4 month backup version 2
Linux Server concurrency optimization