目录
性能优化概述
1、了解每个服务
2、需要了解业务模式
3、最后我们需要考虑性能与安全
压力测试工具
[root@web01 conf.d]# yum install httpd-tools -y
#配置nginx
[root@lb01 conf.d]# cat try.conf
server {
listen 80;
server_name try.haoda.com;
location / {
root /code;
try_files $uri $uri/ @java;
index index.jsp index.html;
}
location @java {
proxy_pass http://172.16.1.8:8080;
}
}
#配置nginx使用的静态页面
[root@lb01 conf.d]# echo "nginx ab" > /code/ad.html
#配置tomcat使用的静态页面
[root@web02 ~]# wget http://mirrors.hust.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
[root@web02 ~]# tar xf apache-tomcat-9.0.16.tar.gz
[root@web02 ~]# cd /usr/share/tomcat/webapps/ROOT
[root@web02 ROOT]# echo "tomcat aaaaa" > tomcat.html
#压测工具测试nginx处理静态资源
[root@lb01 conf.d]# ab -n 10000 -c 200 http://try.haoda.com/ad.html
Server Software: nginx/1.14.2
Server Hostname: try.haoda.com
Server Port: 80
Document Path: /ad.html
Document Length: 9 bytes
Concurrency Level: 200
Time taken for tests: 1.078 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2380000 bytes
HTML transferred: 90000 bytes
Requests per second: 9272.58 [#/sec] (mean)
Time per request: 21.569 [ms] (mean)
Time per request: 0.108 [ms] (mean, across all concurrent requests)
Transfer rate: 2155.15 [Kbytes/sec] received
#压测工具测试tomcat处理静态资源
[root@lb01 conf.d]# ab -n 10000 -c 200 http://try.haoda.com/tomcat.html
Server Software: nginx/1.14.2
Server Hostname: try.haoda.com
Server Port: 80
Document Path: /tomcat.html
Document Length: 13 bytes
Concurrency Level: 200
Time taken for tests: 4.956 seconds
Complete requests: 10000
Failed requests: 0
Write errors: 0
Total transferred: 2510000 bytes
HTML transferred: 130000 bytes
Requests per second: 2017.78 [#/sec] (mean)
Time per request: 99.119 [ms] (mean)
Time per request: 0.496 [ms] (mean, across all concurrent requests)
Transfer rate: 494.59 [Kbytes/sec] received
了解影响性能指标
1、网络
(1)网络的流量
(2)网络是否丢包
(3)这些会影响http的请求与调用
2、系统
(1)硬件有没有磁盘损坏,磁盘速率
(2)系统的负载、内存、系统稳定性
3、服务
(1)连接优化。请求优化
(2)根据业务形态做对应的服务设置
4、程序
(1)接口性能
(2)处理速度
(3)程序执行效率
5、数据库
#每个服务与服务之间都或多或少有一些关联,我们需要将整个架构进行分层,找到对应系统或服务的短板,然后进行优化
系统性能优化
文件句柄,Linux一切皆文件,文件句柄可以理解为就是一个索引,文件句柄会随着我们进程的调用频繁增加,系统默认文件句柄是有限制的,不能让一个进程无限的调用,所以我们需要限制每个 进程和每个服务使用多大的文件句柄,文件句柄也是必须要调整的优化参数。
文件句柄的设置方式:
1、系统全局性修改。
2、用户局部性修改。
3、进程局部性修改。
[root@lb01 ~]# vim /etc/security/limits.conf
1、系统全局性修改。
# * 代表所有用户
* soft nofile 25535
* hard nofile 25535
2.用户局部性修改
#针对root用户,soft仅提醒,hard限制,nofile打开最大文件数
root soft nofile 65535
root hard nofile 65535
3.进程局部性修改
#针对nginx进程,nginx自带配置
worker_rlimit_nofile 30000
4.调整内