天天看点

Jprofiler监控服务器的cpu

现象:压测过程中,发现应用服务器的cpu使用率比较高>80%,我们就可以判断服务器的cpu使用率太高了。

一般cpu太高有两种情况,

1.接口的性能非常好,比如响应时间<10ms,tps很高,此时的cpu使用率高是正常的,不需要优化;

2.接口性能不好,比如响应时间>200ms,tps很低,此时需要考虑优化。

cpu消耗过高的原因:

1.使用了复杂的算法,比如加密,解密;

2,文件的压缩和解压,序列化等操作;

3.代码bug,比如死循环。

序列化

代码中的对象->json字符串的转换(大多是这个)

对象->文件的转换

我们通常使用jprofiler监控工具监控cpu。

jprofiler

1、安装

Linux下命令:rpm -ivh jprofiler_linux_11_0.rpm

默认安装到/opt/jprofiler11

2、服务端配置

tomcat中配置监控参数,在catalina.sh文件中

在JAVA_OPTS=后面,双引号中添加-agentpath:/opt/jprofiler11/bin/linux-x64/libjprofilerti.so=port=8849,nowait

配置完成后,重启tomcat才能生效

3、客户端配置

按照提示一步步配置即可

4、客户端链接服务端:

Jprofiler监控服务器的cpu
Jprofiler监控服务器的cpu
Jprofiler监控服务器的cpu
Jprofiler监控服务器的cpu
Jprofiler监控服务器的cpu

链接服务器:

Jprofiler监控服务器的cpu

服务器jprofiler的路径:

Jprofiler监控服务器的cpu

jprofiler的端口:

Jprofiler监控服务器的cpu
Jprofiler监控服务器的cpu

修改服务器配置并且重启tomcat:

Jprofiler监控服务器的cpu

服务器和win都安装后监控cpu:

Jprofiler监控服务器的cpu