Linux下性能压测之系统参数调优

1. 前言

在做服务端压测的时候,经常会遇到一些由于Linux系统限制导致压力上不去的情况,这里从Linux系统参数上做一些调优,减少此类因素的干扰。

2. 配置

2.1 Linux系统配置

执行sudo vi /etc/sysctl.conf,添加以下内容:
 

net.ipv4.tcp_syncookies = 0
fs.file-max = 12553500
fs.nr_open = 12453500
kernel.shmall= 1048576
kernel.shmmax = 1887436
kernel.msgmax = 65536
kernel.sysrq = 0
kernel.pid_max= 65536
net.core.netdev_max_backlog = 2000000
net.core.rmem_default = 699040
net.core.rmem_max = 50331648
net.core.wmem_default = 131072
net.core.wmem_max = 33554432
net.core.somaxconn = 65535
net.ipv4.ip_nonlocal_bind = 1
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_mem = 1048576 1572864 2097152
net.ipv4.tcp_rmem = 4096 4194304 8388608
net.ipv4.tcp_wmem = 4096 4194304 8388608
net.ipv4.tcp_slow_start_after_idle = 0
net.ipv4.tcp_synack_retries = 1
net.ipv4.tcp_window_scaling = 1
vm.swappiness = 0

#TCP connection recovery
net.ipv4.tcp_max_tw_buckets = 6000000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
net.ipv4.route.max_size = 5242880
net.ipv4.ip_forward = 1
net.ipv4.tcp_timestamps = 1
#开启对于TCP时间戳的支持,若该项设置为0,则下面一项设置不起作用

#TCP connection manager
net.ipv4.tcp_max_syn_backlog = 655360
net.ipv4.tcp_syn_retries = 6
net.ipv4.tcp_retries1 = 3
net.ipv4.tcp_retries2 = 6

#TCP keepalive
net.ipv4.ip_local_port_range = 1000 65534
net.ipv4.tcp_keepalive_time = 30
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
fs.inotify.max_user_watches=524288

保存后执行:sysctl -p 生效。

2.2 文件描述符限制

2.2.1 修改fileno的配置

执行:sudo  vi /etc/security/limits.conf , 文末添加:

- nofile 1000000

2.2.2 修改supervisor服务配置文件(如果是supervisor启动的程序,则可以修改此处)

执行:vi /usr/lib/systemd/system/supervisord.service,添加如下:
 [Service]
#添加如下三行
LimitCORE=infinity
LimitNOFILE=1000000
LimitNPROC=1000000
 
修改完上述supervisord.service后,执行如下命令生效
sudo systemctl daemon-reload
sudo systemctl restart supervisord.service 

2.2.3 验证open files是否修改成功

1. 全局查看
执行:ulimit -a查看open files选项
2. 查看supervisor启动服务的open files数
#1. 先查询supervisor的pid
ps aux |grep supervisor
#2. 假如是22296,查看进程限制
cat /proc/22296/limits
#3. 看到有下面一行就ok了
Max open files 1000000 1000000 files

2.3 /etc/security/limits.conf配置 

limits.conf是Linux资源限制配置文件,为了性能测试,我们可以将其调大

* soft nofile 655350   
* hard nofile 655350
* soft nproc  655350   
* hard nproc  650000
进行了如上配置之后,在我们使用Jmeter等压测工具进行压测的时候,后端服务能享受到Linux软件层面的最大性能。

传送门:2021最新测试资料&大厂职位

博主:测试生财(一个不为996而996的测开码农)

座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。

内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。

csdn:https://blog.csdn.net/ccgshigao

博客园:https://www.cnblogs.com/qa-freeroad/

51cto:https://blog.51cto.com/14900374

微信公众号:测试生财(定期分享独家内容和资源)

posted @ 2021-03-18 08:26  公众号-测试生财  阅读(389)  评论(0编辑  收藏  举报