记一次系统压测

压测工具

使用loadruner11做为此次压测工具,
需要注意的有两点

  • 1,启用gzip压缩 其实是默认值,但我这次使用的时候不指定就没效果
web_add_header("Accept-Encoding", "gzip,deflate");

image

  • 2,勾选winiet回放 image

springboot 启用gzip压缩

在application.properties中增加以下配置

server.compression.enabled=true
server.compression.min-response-size=2048
server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain

tomcat优化

安装apr

参考

调整 catalina.sh

起始位置增加以下参数

#!/bin/sh
JVM_OPTS="-server -verbose:gc
  -XX:+PrintGCDateStamps
  -XX:+PrintGCDetails
  -XX:+UseGCLogFileRotation
  -XX:NumberOfGCLogFiles=9
  -XX:GCLogFileSize=256m
  -XX:+UseParNewGC
  -XX:+UseConcMarkSweepGC
  -XX:+CMSParallelRemarkEnabled
  -XX:CMSInitiatingOccupancyFraction=70
  -XX:+CMSClassUnloadingEnabled
  -XX:CMSMaxAbortablePrecleanTime=300
  -XX:+CMSScavengeBeforeRemark
  -XX:GCTimeRatio=19
  -XX:SurvivorRatio=3
"
JAVA_OPTS="-Xmx1g -Xms1g -Xmn256m -Xss1024K $JVM_OPTS  -Xloggc:/home/tomcat/tomcat8004/logs/gc.log "
export JAVA_HOME=/home/java/jdk1.8.0_172
export LD_LIBRARY_PATH=/home/tomcat/apr-native/lib

调整server.xml

<Executor name="tomcatThreadPool"  namePrefix="zjh-exec-"
	maxThreads="700" 
	minSpareThreads="700"
	maxSpareThreads="700"
/>

<Connector port="8004"
	protocol="org.apache.coyote.http11.Http11AprProtocol" 
	executor="tomcatThreadPool"
		 connectionTimeout="60000"
	   keepAliveTimeout="15000"
	   maxkeepAliveRequests="1"
		acceptCount="700"
		acceptorThreadCount ="4"
		enableLookups="false"
		minProcessors="100"
		maxProcessors="1000"
		URIEncoding="UTF-8" 
		compression="on"
		compressionMinSize="2048"
		noCompressionUserAgents="gozilla,traviata"
		compressableMimeType="application/json,application/xml,text/html,text/xml,text/plain"
		disableUploadTimeout="true"
		connectionUploadTimeout="0"
		useBodyEncodingForURI="true"
		userURIValidationHack="false"
	/>
	    <!-- Define an AJP 1.3 Connector on port 8009
        
    <Connector port="8019" protocol="AJP/1.3" redirectPort="8018" /> -->

调整web.xml

因为本项目没有使用session,所以将session超时设置 为1分钟

    <session-config>
        <session-timeout>1</session-timeout>
    </session-config>

mysql优化

调整my.cnf

[client]

port		= 3306

[mysqld]
port		= 3306
basedir=/home/mysql/mysql57
datadir=/home/mysql/data
skip-name-resolve
#socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
log_output=file
slow_query_log=ON
slow_query_log_file =/hwsoft/mysql/mysql57/log/mysql-slow.log
log_queries_not_using_indexes=on
long_query_time = 1
max_connections = 1024
max_connect_errors = 10000000
wait_timeout = 10
key_buffer_size=1024m
query_cache_size=512m  
query_cache_type=1 
table_open_cache=2048
open_files_limit = 65535
innodb_thread_concurrency=8
innodb_buffer_pool_size = 2048M
max_allowed_packet=600m
innodb_log_file_size = 64M
innodb_log_buffer_size = 16M

#plugin-load-add=thread_pool.so
#thread_handling=pool-of-threads
#thread_pool_size=24
#thread_pool_max_threads=100000
[mysqld_safe]
log-error=/hwsoft/mysql/mysql57/log
                         
#pid-file=/var/run/mariadb/mariadb.pid
#pid-file=/var/run/mysql/mysql5.7.pid

#
# include all files from the config directory
#
#!includedir /etc/my.cnf.d

nginx负载均衡配置

首先安装fair模块


worker_processes  4;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

worker_rlimit_nofile 65535;
events {
    worker_connections  10240;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

	log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
			      '$status $body_bytes_sent "$http_referer" '
			      '"$http_user_agent" "$http_x_forwarded_for"'
			       '$upstream_addr $upstream_response_time $request_time ';
	access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #开启或关闭gzip on off
    gzip on;

    #不使用gzip IE6
    gzip_disable "msie6";

    #gzip压缩最小文件大小,超出进行压缩(自行调节)
    gzip_min_length 100k;

    #buffer 不用修改
    gzip_buffers 4 16k;

    #压缩级别:1-10,数字越大压缩的越好,时间也越长
    gzip_comp_level 3;

    #  压缩文件类型
    gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png;

    #跟Squid等缓存服务有关,on的话会在Header里增加 "Vary: Accept-Encoding"
    gzip_vary off;

    underscores_in_headers on;
    upstream tomcat { 
    	#fair;
        server    127.0.0.1:9901 ;
        server    127.0.0.1:9902 ;  
        server    127.0.0.1:9903 ;
        server    127.0.0.1:8004 ;
    }   
    server {
       listen       8888;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
       root /home/nginx/nginx1.7/zjhdc;
         location /zjhdc{
          try_files $uri $uri/ @router;
          #try_files $uri $uri/ /index.html;
          index  index.html;
        }
	
        location = /zjhdc/ {
            proxy_pass http://localhost:8888/zjhdc;   
        } 
         location @router{
               rewrite ^.*$ /index.html last;
             }
          #转发后端接口   
         location /aaa/ {
              proxy_pass http://tomcat/aaa/;
             }
         location /bbb/ {
              proxy_pass http://tomcat/bbb/;
             }
        location /probe/ {
              proxy_pass http://tomcat/probe/;
             }
        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

    }


}

后记

TIP

调整之后,16G内存服务器,4核阿里去服务器可支撑2500并发

image