我是用Springboot开发的接口,刚开始接口相应速度在5-6s左右,优化后在2s以内。
1.Springboot配置
spring.mvc.servlet.load-on-startup=1
2.jdk优化
${jdk安装目录}\open-jdk-1.8.0_211_x64\jre\lib\security\java.security
securerandom.source=file:/dev/urandom
刚开始用的oracle得jdk1.8.0_144(windows端)/jdk1.8.0_144(Linux端),修改效果不大,
后都改用open-jdk-1.8.0_211 64位效果提升明显。
附下载链接:
http://static.azul.com/zulu/bin/下有open-jdk各种版本
Linux 64位:
https://cdn.azul.com/zulu/bin/zulu8.38.0.13-ca-jdk8.0.212-linux_x64.tar.gz
windows 64位:
https://cdn.azul.com/zulu/bin/zulu8.38.0.13-ca-jdk8.0.212-win_x64.zip
3.nginx优化
参考资料:
长连接短连接说明:
https://www.cnblogs.com/onlysun/p/4520553.html
优化资料说明:
https://blog.51cto.com/gyj110/2056555
我的实战配置:
文件 nginx.conf
===========================================================
http{
.....
tcp_nodelay on;
tcp_nopush on;
sendfile on;
keepallive_timeout 300;
keepalive_requests 10000;
include /usr/local/nginx/conf/conf.d/*.conf;
}
===========================================================
conf.d/xxx.conf
upsteam xxx-online{
server ip:port weight=1 max_fails=2 fail_timeout=30s;
server ip:port weight=1 max_fails=2 fail_timeout=30s;
keepalive 1000;
}
server {
listen port;
server_name localhost;
location / {
proxy_pass http://xx-online;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
add_header Cache-Control no-store;
#1.1支持长连接 默认是1.0 不支持长连接
proxy_http_version 1.1;
proxy_set_header Connection "";
}
}
网友评论