天天看點

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

微信公衆号:測試生财(定期分享獨家内容和資源)

Linux下性能壓測之系統參數調優

繼續閱讀