Main debugging parameters of stress test in linux, mysql, nginx, tomcat environment

1. Linux system kernel parameters

  1. Common parameters of the /etc/sysctl.conf file

    net.core.netdev_max_backlog = 32768 #允许送到队列的数据包的最大数目
    net.core.rmem_max  = 8388608        #SOCKET读缓存区大小
    net.core.wmem_max  = 8388608        #SOCKET写缓存区大小
    net.core.somaxconn   = 32768        #系统中每一个端口最大的监听队列的长度
    
    net.core.rmem_max = 16777216        #最大socket读buffer
    net.ipv4.ip_local_port_range = 1024 65000 #允许系统打开的端口范围
    net.ipv4.tcp_fin_timeout  = 30   #TIME_WAIT2进入CLOSED的等待时间
    net.ipv4.tcp_keepalive_time = 1200  #TCP发送keepalive消息的时间
    net.ipv4.tcp_timestamps = 0
    net.ipv4.tcp_synack_retries = 2
    net.ipv4.tcp_syn_retries = 2
    net.ipv4.tcp_synack_retries = 1  #内核放弃连接之前发送SYN+ACK包的数量
    net.ipv4.tcp_syn_retries =1      #内核放弃建立连接之前发送SYN包的数量 
    net.ipv4.tcp_max_tw_buckets =6000  #控制TIME_WAIT的最大数量timewait的数量,默认是180000。
    
    net.ipv4.tcp_tw_recycle = 1      #TCP连接中TIME-WAIT套接字的快速回收。默认为0,表示关闭
    
    net.ipv4.tcp_tw_reuse = 1       #允许将TIME-WAIT套接字重新用于新的TCP连接。默认为0,表示关闭。
    net.ipv4.tcp_mem = 94500000 915000000 927000000
    net.ipv4.tcp_max_orphans = 3276800
    net.ipv4.tcp_max_syn_backlog = 65536 #SYN队列的长度,默认为1024,加大队列长度为8192,可以容纳更多等待连接的网络连接数
    fs.file-max = 65535       #系统可打开的文件数
    fs.nr_open  = 65535       #fs.file-max的值不要超过fs.nr_open的值
    

    Make changes to the sysctl.conf file effective

     sysctl -p
    
  2. limits.conf file

        vi /etc/security/limits.conf
    

    add at the end

    * soft nofile 65535  
    * hard nofile 65535 
    

    Check if it works

      ulimit -a 
    

    Manual modification (restart invalid)

      ulimit -n  65535
    

Second, the main debugging parameters of Nginx

Main module parameters:

worker_processes = 8           #按照CPU核心数量的设置
worker_rlimit_nofile 65535;    #Nginx进程打开文件描述符最大数量
use epoll;                     #使用epoll事件模型
worker_connections = 102400     #每个进程的最大连接数

HTTP Module Parameters

keepalive_timeout 60;          #keepalive超时时间。
client_body_buffer_size 64K;   #客户端请求内容的缓冲区大小。
client_header_buffer_size 8k;  #客户端请求头部的缓冲区大小,可以根据系统的分页大小来设置。
large_client_header_buffers 4 128k; 
client_max_body_size 8m;       #客户端请求内容的最大值。
open_file_cache max=204800 inactive=30s;  #打开文件的缓存,max指缓存的最大数量,inactive指缓存过期时间。
open_file_cache_valid 30s;     #检查缓存的有效时间。
open_file_cache_min_uses 1;    #inactive参数的时间内文件的最少使用次数,如果超过这个值,则保持缓存的打开状态。

Three, mysql

The following configuration options may be relatively small (MySQL with 8G memory), which will actually exceed the needs of many people, and can be modified according to the running status of MySQL in the future.

[mysql]
port                           = 3306
socket                         = /var/lib/mysql/mysql.sock
[mysqld]
user                           = mysql
default_storage_engine         = InnoDB
socket                         = /var/lib/mysql/mysql.sock
pid_file                       = /var/lib/mysql/mysql.pid
skip_name_resolve
key_buffer_size                = 32M
myisam_recover                 = FORCE,BACKUP
max_allowed_packet             = 16M
max_connect_errors             = 1000000
log_bin                        = /var/lib/mysql/mysql-bin
expire_logs_days               = 7
sync_binlog                    = 0
tmp_table_size                 = 32M
max_heap_table_size            = 32M
query_cache_type               = 1
query_cache_size               = 32M
max_connections                = 500
thread_cache_size              = 50
open_files_limit               = 65535
table_definition_cache         = 1024
table_open_cache               = 2048
innodb_flush_method            = O_DIRECT
innodb_log_files_in_group      = 2
innodb_log_file_size           = 256M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table          = 1
innodb_buffer_pool_size        = 4G
log_error                      = /var/log/mysql-error.log
log_queries_not_using_indexes  = 1
slow_query_log                 = 1
slow_query_log_file            = /var/log/mysql-slow.log

Fourth, tomcat

In tomcat, server.xml configures
the 8080 port under the Connector tag to
modify the protocol="org.apache.coyote.http11.Http11NioProtocol"
and add the following parameters

connectionTimeout="20000"
processorCache="1000"
acceptCount="5000"
acceptorThreadCount="8"#根据实际cpu核数配置
maxThreads="2000"
minSpareThreads="100"
socket.appReadBufSize="1024"
socket.appWriteBufSize="1024"
socket.bufferPool="1000"

catalina.sh
tomcat startup file, adjust it according to the actual situation, -XX:NewRatio is used to configure the ratio of old generation to new generation to
increase JAVA_OPTS="-server -Xms1048m -Xmx3072m -Xss1024K -XX:PermSize=64m -XX:MaxPermSize= 128m -XX:NewRatio=4"

5. Hardware load

Check the CPU load

 top

View memory usage

 free -m

Check the situation of disk IO

iostat -kx 2

Check network traffic

sar -n DEV 2

Reference: Some optimizations about Nginx (break through 100,000 concurrent)

 

https://segmentfault.com/a/1190000002700923

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327057388&siteId=291194637