quarkus http调用负载测试结果1000个请求-16秒vs 65秒
测试1:quarkus http调用负载测试结果1000个请求-16秒vs 65秒,quarkus,Quarkus,测试1: @Path("/performance") public class PerformanceTestResource { @Timeout(20000) @GET @Path("/resource") @Produces(MediaType.APPLICATION_JSON) public Response performanceResource() { final String name = Thread.currentTh
@Path("/performance")
public class PerformanceTestResource {
@Timeout(20000)
@GET
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
public Response performanceResource() {
final String name = Thread.currentThread().getName();
System.out.println(name);
Single<Data> dataSingle = null;
try {
dataSingle = Single.fromCallable(() -> {
final String name2 = Thread.currentThread().getName();
System.out.println(name2);
Thread.sleep(1000);
return new Data();
}).subscribeOn(Schedulers.io());
} catch (Exception ex) {
int a = 1;
}
return Response.ok().entity(dataSingle.blockingGet()).build();
}
}
结果测试1:
@Path("/performance")
public class PerformanceTestResource {
@Timeout(20000)
@GET
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
public Response performanceResource() {
final String name = Thread.currentThread().getName();
System.out.println(name);
Single<Data> dataSingle = null;
try {
dataSingle = Single.fromCallable(() -> {
final String name2 = Thread.currentThread().getName();
System.out.println(name2);
Thread.sleep(1000);
return new Data();
}).subscribeOn(Schedulers.io());
} catch (Exception ex) {
int a = 1;
}
return Response.ok().entity(dataSingle.blockingGet()).build();
}
}
执行时间:16秒
测试2:相同但无@Timeout注释:
执行时间:65秒
问:为什么?我觉得16秒都慢。
问:如何加快通话速度:假设1000个电话通话时间为2秒。
我意识到我在资源中使用了.blockingGet()
,但仍然希望重用阻塞线程
附言。
我试图更“被动”地返回Single
或CompletionStage
,以从响应中返回-但这似乎还没有准备好(RESTEasy方面有bug)。所以我使用simple.blockingGet()`和Response
更新:反应式/RX Java 2路
@path("/performance")
public class PerformanceTestResource {
//@Timeout(20000)
@GET
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
public Single<Data> performanceResource() {
final String name = Thread.currentThread().getName();
System.out.println(name);
System.out.println("name: " + name);
return Single.fromCallable(() -> {
final String name2 = Thread.currentThread().getName();
System.out.println("name2: " + name2);
Thread.sleep(1000);
return new Data();
});
}
}`
因此,我们正在阻塞工作线程,即在REst/资源端使用的工作线程。那是高速公路然后:
如果我使用:Schedulers.io()
在sleep-1000-call的单独执行上下文中:
return Single.fromCallable(() -> { ... }).subscribeOn(Schedulers.io());
执行时间:16秒
输出如下(请参阅一个新的家伙:RxCachedThreadScheduler)
似乎无关紧要:无论我是否显式使用blockingGet()
,我都会得到相同的结果
我假设如果我不阻止它,它大约需要2-3秒
Q:I从这一点上有没有办法修复/调整这个问题
我假设使用Schedulers.io()
带来RxCachedThreadScheduler
是这一点的瓶颈,因此我最终得到了16秒的,200个io/io线程是默认限制吗?但是这些应该被重用,而不是真正被阻止。(不要认为把上限设为1000是个好主意)
Q:或者无论如何:如何使应用程序像Quarkus一样具有响应性/反应性/性能。或者我错过了什么
谢谢 好的。也许是我。
在我的脑海里;我每10毫秒传递一次CALL\u NIT\u。
10*1000=10000-+10秒,仅用于添加请求
这个,我设置为0
我有6秒的时间处理服务器1000个模拟请求
还不到2-3秒。但是6
如果我使用.getBlocking
并返回Response
或返回Single
,似乎没有什么区别
--
不过,值得一提的是,这个hello world应用程序需要1秒来处理1000个并行请求。而夸克一号是6秒
public class Sample2 {
static final AtomicInteger atomicInteger = new AtomicInteger(0);
public static void main(String[] args) {
long start = System.currentTimeMillis();
final List<Single<Response>> listOfSingles = Collections.synchronizedList(new ArrayList<>());
for (int i=0; i< 1000; i++) {
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
final Single<Response> responseSingle = longCallFunction();
listOfSingles.add(responseSingle);
}
Single<Response> last = Single.merge(listOfSingles).lastElement().toSingle();
final Response response = last.blockingGet();
long end = System.currentTimeMillis();
System.out.println("Execution time: " + (end - start) / 1000);
System.out.println(response);
}
static Single<Response> longCallFunction() {
return Single.fromCallable( () -> { // 1 sec
System.out.println(Thread.currentThread().getName());
Thread.sleep(1000);
int code = atomicInteger.incrementAndGet();
//System.out.println(code);
return new Response(code);
}).subscribeOn(Schedulers.io());
}
}
公共类样本2{
静态最终AtomicInteger AtomicInteger=新的AtomicInteger(0);
公共静态void main(字符串[]args){
长启动=System.currentTimeMillis();
final List listOfSingles=Collections.synchronizedList(新的ArrayList());
对于(int i=0;i<1000;i++){
//试一试{
//睡眠(10);
//}catch(InterruptedException e){
//e.printStackTrace();
// }
最终单响应Single=longCallFunction();
添加(responseSingle);
}
Single last=Single.merge(listOfSingles.lastElement().toSingle();
最终响应=last.blockingGet();
long end=System.currentTimeMillis();
System.out.println(“执行时间:”+(结束-开始)/1000);
System.out.println(响应);
}
静态单longCallFunction(){
返回Single.fromCallable(()->{//1秒
System.out.println(Thread.currentThread().getName());
睡眠(1000);
int code=atomicInteger.incrementAndGet();
//System.out.println(代码);
返回新的响应(代码);
}).subscribeOn(Schedulers.io());
}
}
name: vert.x-worker-thread-5
name2: RxCachedThreadScheduler-1683
vert.x-worker-thread-0
name: vert.x-worker-thread-0
vert.x-worker-thread-9
name: vert.x-worker-thread-9
name2: RxCachedThreadScheduler-1658
vert.x-worker-thread-8
public class Sample2 {
static final AtomicInteger atomicInteger = new AtomicInteger(0);
public static void main(String[] args) {
long start = System.currentTimeMillis();
final List<Single<Response>> listOfSingles = Collections.synchronizedList(new ArrayList<>());
for (int i=0; i< 1000; i++) {
// try {
// Thread.sleep(10);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
final Single<Response> responseSingle = longCallFunction();
listOfSingles.add(responseSingle);
}
Single<Response> last = Single.merge(listOfSingles).lastElement().toSingle();
final Response response = last.blockingGet();
long end = System.currentTimeMillis();
System.out.println("Execution time: " + (end - start) / 1000);
System.out.println(response);
}
static Single<Response> longCallFunction() {
return Single.fromCallable( () -> { // 1 sec
System.out.println(Thread.currentThread().getName());
Thread.sleep(1000);
int code = atomicInteger.incrementAndGet();
//System.out.println(code);
return new Response(code);
}).subscribeOn(Schedulers.io());
}
}