文章目录
Postman : Http请求模拟工具Apache Bench (AB) : Apache附带的工具,测试网站性能JMeter : Apache组织开发的的压力测试工具代码: Semaphore, CountDownLatch等
Postman : Http请求模拟工具
前置条件是准备一个springboot的框架写一个test接口 将链接加入postman快捷方式 进行并发测试 Postman测试比较慢。。。
Apache Bench (AB) : Apache附带的工具,测试网站性能
本测试1000个;并发量为50
Concurrency Level: 50 【并发量Time taken for tests: 0.355 seconds 【总测试时间Complete requests: 1000【完成请求数Failed requests:0Total transferred: 136000 bytes【响应数据头总和HTML transferred: 4000 bytes【正文数据总和Requests per second: 2816.64#/secl (mean)【吞吐率Time per request: 17.752 ms (mean)【用户平均请求等待时间Time per request: 0.355 ms] (mean, across all concurrent - requests) 【服务器平均请求等待时间Transfer rate: 374.08 「Kbytes/secl received【单例时间从服务器获取的数据长度
JMeter : Apache组织开发的的压力测试工具
添加线程组 添加http请求 查看监听器
代码: Semaphore, CountDownLatch等
package com
.mmall
.concurrency
;
import com
.mmall
.concurrency
.annoations
.NotThreadSafe
;
import lombok
.extern
.slf4j
.Slf4j
;
import java
.util
.concurrent
.CountDownLatch
;
import java
.util
.concurrent
.ExecutorService
;
import java
.util
.concurrent
.Executors
;
import java
.util
.concurrent
.Semaphore
;
@Slf4j
@NotThreadSafe
public class ConcurrencyTest {
public static int clientTotal
=5000;
public static int threadTotal
=200;
public static int count
=0;
public static void main(String
[] args
) throws InterruptedException
{
ExecutorService executorService
= Executors
.newCachedThreadPool();
final Semaphore semaphore
= new Semaphore(threadTotal
);
final CountDownLatch countDownLatch
= new CountDownLatch(clientTotal
);
for (int i
= 0; i
< clientTotal
; i
++) {
executorService
.execute(()->{
try {
semaphore
.acquire();
add();
semaphore
.release();
} catch (InterruptedException e
) {
log
.error("exception",e
);
}
countDownLatch
.countDown();
});
}
countDownLatch
.await();
executorService
.shutdown();
log
.info("count:{}",count
);
}
private static void add(){
count
++;
}
}