超实用容易上手的项目压测技术推荐与简单使用----JAVA

准备工作

  1.  准备两台机器,一台部署压测系统,另外一台模拟用户发送请求。(不要使用本地去请求服务,会忽略网络消耗)
  2. 模拟用户请求的机器安装apache ab  (sudo apt-get install apache2-utils)      官网地址:http://httpd.apache.org/docs/2.0/programs/ab.html
  3. 部署系统的机器安装Arthas(阿里工具)

    https://arthas.gitee.io/install-detail.html 
    安装Arthas
    curl -O https://arthas.aliyun.com/arthas-boot.jar

apache ab简单使用

GET

ab -n 400 -c20 "http://127.0.0.1:9110/test?a=ECB8175A75&b=31BBCE"

一次发送400请求, 20并发。 GET请求放到""中

 POST

将参数key-value放到当前路径文件中

ab -n 1 -c 1 -p p.txt -T application/x-www-form-urlencoded http://172.19.49.169:9110/test/sign/1771

返回参数

https://zhuanlan.zhihu.com/p/102534511

Arthas

安装 arthas idea 这个插件使用最简单功能


使用 trace功能, com.serviceImpl getInfo -n 5 --skipJDKMethod false
追踪方法耗时

`---ts=2021-06-17 16:56:01;thread_name=http-nio-9110-exec-297;id=2c8;is_daemon=true;priority=5;TCCL=org.springframework.boot.web.embedded.tomcat.TomcatEmbeddedWebappClassLoader@e9c78c43
`---[2533.652526ms] com.DataServiceImpl:findDrawList()
+---[0.818073ms] com.ervice:findLiveRoomById() #103
+---[0.014605ms] com.live.LiveRoom:isDeleted() #107
+---[0.032514ms] com.cache.ViewTemplateCache:get() #57
+---[0.012804ms] com.google.common.collect.Maps:newHashMapWithExpectedSize() #11

这样就可以看到请求的调用链耗时,寻找耗时的瓶颈点,进而去优化代码解决问题。 

原文地址:https://www.cnblogs.com/technologykai/p/15355993.html