記一次 500併發,平均響應時間慢-調優過程~~

e_shi_yi_p_l發表於2020-12-26

1、背景:LR壓測,併發 500、持續壓測10 分鐘~
在這裡插入圖片描述
壓測結果,平均響應時間長

在這裡插入圖片描述
從報告可知,主要瓶頸在js、css、img上

2、解決 啟用nginx 快取、叢集部署、tomcat執行緒調優 linux核心調優

tomcat7 啟用nio、調大最大執行緒。等待佇列

   <Connector port="6002" enableLookups="false" maxKeepAliveRequests="1" acceptCount="550" minSpareThreads="300" maxThreads="400"  protocol="org.apache.coyote.http11.Http11NioProtocol"
               connectionTimeout="60000"
               URIEncoding="UTF-8"
               redirectPort="8443" />

初始堆記憶體設定

JAVA_OPTS="-Xms3g -Xmx3g -Xss1024K"

nginx快取配置,注意:需要單獨一個server

http模組配置:
	proxy_connect_timeout 10;
    proxy_read_timeout 180;
    proxy_send_timeout 5;
    proxy_buffer_size 16k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 96k;
    proxy_temp_file_write_size 96k;
    proxy_temp_path /opt/nginx/temp_dir1;
    proxy_cache_path /opt/nginx/cache1 levels=1:2 keys_zone=cache_one:100m inactive=1d max_size=10g;

    #gzip  on;
    gzip  on; #開啟gzip
    gzip_vary on;
    gzip_min_length 1k; #不壓縮臨界值,大於1k的才壓縮,一般不用改
    gzip_buffers 4 16k;
    gzip_comp_level 6; #壓縮級別,數字越大壓縮的越好
    gzip_types  text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png image/x-icon; #壓縮檔案型別,缺啥補啥

server 模組~
server {
        listen       8080;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
		location ~ .*\.(gif|jpg|png|css|js)?$ {     
			proxy_pass http://server.settle;
			#快取
	     	proxy_cache cache_one;
            proxy_cache_valid 200 302 24h;
            proxy_cache_valid 301 30d;
            proxy_cache_valid any 5m;
            expires 10d;
        }

         location /fsp-manage {
            proxy_pass http://server.settle;
            proxy_set_header Host 172.16.2.136:8080;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           }
      
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }

linux 核心調整,軟體的口已經放大-需要硬體的口支撐。

核心TCP引數方面

cat /etc/sysctl.conf

########################## aliyun configure ##########################
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1

vm.swappiness = 0
net.ipv4.neigh.default.gc_stale_time=120

# see details in https://help.aliyun.com/knowledge_detail/39428.html
net.ipv4.conf.all.rp_filter=0
net.ipv4.conf.default.rp_filter=0
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.all.arp_announce=2
net.ipv4.conf.lo.arp_announce=2

# see details in https://help.aliyun.com/knowledge_detail/41334.html
net.ipv4.tcp_max_tw_buckets = 5000
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_synack_retries = 2
kernel.sysrq = 1

########################## jiaxin configure ##########################
fs.file-max = 1631224
vm.overcommit_memory = 1
vm.max_map_count=655350

net.ipv4.ip_local_port_range = 1024 65530
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_keepalive_time = 1200
net.ipv4.tcp_fastopen = 3
net.ipv4.tcp_window_scaling = 1
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_sack = 1
net.ipv4.tcp_congestion_control = hybla
net.ipv4.tcp_rmem = 4096 87380 67108864
net.ipv4.tcp_wmem = 4096 87380 67108864
net.ipv4.tcp_mtu_probing = 1
net.ipv4.tcp_keepalive_time = 60
net.ipv4.tcp_keepalive_probes = 3
net.ipv4.tcp_keepalive_intvl = 20

net.core.rmem_max = 67108864
net.core.wmem_max = 67108864
net.core.netdev_max_backlog = 250000
net.core.somaxconn = 65000

儲存退出之後執行  sysctl -p  引數生效,永久生效

3、調整過程中注意觀察 nginx access.log、tomcat _localhost_accsess.log 入口日誌~~
效果如下
在這裡插入圖片描述

相關文章