压测工具有很多,这里我介绍一种淘宝提供的一种压测工具,开发人员很方便的进行压测
1、引入pom
<dependency>
<groupId>com.taobao</groupId>
<artifactId>stresstester</artifactId>
<version>1.0</version>
</dependency>
找不到依赖这里提供了一个jar
配置dubbo客户端配置文件这里就不写了
2、写个main方法就可以压测了
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "classpath:conf/spring.xml" });
final PromotionCartServiceClient demoService = (PromotionCartServiceClient) context.getBean("PromotionCartServiceClient");
StressTestUtils.testAndPrint(100, 1000000, new StressTask() {
public Object doTask() throws Exception {
List<String> promoIds = new ArrayList<String>();
promoIds.add("0722d1aa9dcb4881bb6c7ad7cae76df6");
ResultDTO<Boolean> deductionPriceResource = demoService.deductionPriceResource(promoIds, UUID.randomUUID().toString(), "1443", "951023562960");
return null;
}
});
System.exit(0);
}
StressTestUtils.testAndPrint(100, 1000000, new StressTask() {…..
100是并发数
1000000是请求次数
3、压测结果
Concurrency Level: 100
Time taken for tests: 41.175274 ms
Complete Requests: 100
Failed Requests: 0
Requests per second: 3633.8547
Time per request: 27.518986 ms
Time per request: 0.27518988 ms (across all concurrent requests)
Shortest request: 10.093374 ms
Percentage of the requests served within a certain time (ms)
50% 29.744219
66% 32.11875
75% 33.670345
80% 34.80021
90% 38.767384
95% 40.011738
98% 40.90684
99% 41.175274
100% 41.175274 (longest request)