内核参数调整

ulimit 设置

ulimit -n 要调整为 650000 甚至更大。 命令行下执行 ulimit -n 650000 即可修改。如果不能修改,需要设置 /etc/security/limits.conf,加入

* soft nofile 262140
* hard nofile 262140
root soft nofile 262140
root hard nofile 262140
* soft core unlimited
* hard core unlimited
root soft core unlimited
root hard core unlimited

注意,修改 limits.conf 文件后,需要重启系统生效
对某一个进程临时修改最大文件限制用以下命令:
# CentOS7系统使用命令 prlimit --nofile=65536:65536 --pid 39977

内核设置

Linux 操作系统修改内核参数有 3 种方式:

第一种方式在操作系统重启后会自动生效,第二和第三种方法重启后失效

net.unix.max_dgram_qlen = 100

swoole 使用 unix socket dgram 来做进程间通信,如果请求量很大,需要调整此参数。系统默认为 10,可以设置为 100 或者更大。或者增加 worker 进程的数量,减少单个 worker 进程分配的请求量。

net.core.wmem_max

修改此参数增加 socket 缓存区的内存大小

net.ipv4.tcp_mem  =   379008       505344  758016net.ipv4.tcp_wmem = 4096        16384   4194304net.ipv4.tcp_rmem = 4096          87380   4194304net.core.wmem_default = 8388608net.core.rmem_default = 8388608net.core.rmem_max = 16777216net.core.wmem_max = 16777216

其他重要配置

net.ipv4.tcp_syncookies=1
net.ipv4.tcp_max_syn_backlog=81920
net.ipv4.tcp_synack_retries=3
net.ipv4.tcp_syn_retries=3
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 300
net.ipv4.ip_local_port_range = 20000 65000
net.ipv4.tcp_max_tw_buckets = 200000
net.ipv4.route.max_size = 5242880

net.ipv4.tcp_tw_reuse

是否 socket reuse,此函数的作用是 Server 重启时可以快速重新使用监听的端口。如果没有设置此参数,会导致 server 重启时发生端口未及时释放而启动失败

net.ipv4.tcp_tw_recycle

使用 socket 快速回收,短连接 Server 需要开启此参数。此参数表示开启 TCP 连接中 TIME-WAIT sockets 的快速回收,Linux 系统中默认为 0,表示关闭。打开此参数可能会造成 NAT 用户连接不稳定,请谨慎测试后再开启。

net.ipv4.tcp_tw_reuse 和  net.ipv4.tcp_tw_recycle 不能同时配置为1 ,不然会有冲突,导致 i2node 的rpc 网络端口异常。
 

参数冲突说明参考:
https://blog.csdn.net/ywq935/article/details/91384854
 

查看配置是否生效

如:修改 net.unix.max_dgram_qlen = 100 后,通过

cat /proc/sys/net/unix/max_dgram_qlen

如果修改成功,这里是新设置的值。

类似调优举例:
CASE1)、7.1.68 以及之前的版本,控制机异常,可以调节的其他模式:
如果出现单机上百个节点,日志、状态、流量等请求爆表时,控制机常规访问出现异常,按如下方式进行操作。
(1)进入Ctrlcenter/wwwroot/default/application/console/目录下有serve.ini脚本可 以设置监听调节性能。
(2)进入Ctrlcenter/wwwroot/default/application/console/目录下有i2up_sw文件,执行 i2up_sw <start> 如果没有,需要手动运行 php Serve.php。
(3)修改i2.conf文件将如下两行代码注释进行交换
proxy_pass https://https_backend/api/rpc_server?$params;   
#proxy_pass http://sw_backend/rpc_server?$params;
修改后:
#proxy_pass https://https_backend/api/rpc_server?$params;
            proxy_pass http://sw_backend/rpc_server?$params; 

(4)修改i2.conf文件并添加以下内容
  upstream sw_backend {
        server 127.0.0.1:58088;
        keepalive 8;
        keepalive_requests  2048;
    }
 
location ^~ /i2/i2/ {
…………
 #proxy_pass https://https_backend/api/rpc_server?$params;   # 注释掉默认的
 proxy_pass http://sw_backend/rpc_server?$params;   # 新增的
(5)如果需要还原将注释交换回来即可
(6)最后重启i2resty服务(nginx)

CASE2) 如遇到network error 这种情况:
一个控制台节点很多达到200+,出现类似的情况,可以 把nginx配置中 listen 58086 ssl http2; 中的http2删了, 重启i2resty服务