我试图找出异步和同步HTTP请求处理的优缺点。我正在将Dropwizard和Jersey用作我的框架。测试是比较异步和同步HTTP请求处理,这是我的代码
@Path("/")
public class RootResource {
ExecutorService executor;
public RootResource(int threadPoolSize){
executor = Executors.newFixedThreadPool(threadPoolSize);
}
@GET
@Path("/sync")
public String sayHello() throws InterruptedException {
TimeUnit.SECONDS.sleep(1L);
return "ok";
}
@GET
@Path("/async")
public void sayHelloAsync(@Suspended final AsyncResponse asyncResponse) throws Exception {
executor.submit(() -> {
try {
doSomeBusiness();
asyncResponse.resume("ok");
} catch (InterruptedException e) {
e.printStackTrace();
}
});
}
private void doSomeBusiness() throws InterruptedException {
TimeUnit.SECONDS.sleep(1L);
}
}
Run Code Online (Sandbox Code Playgroud)
该同步 API将在由码头和维护的工作线程运行的异步 API将主要运行在海关线程池。这是Jmeter的结果
我的问题是:这两种方法之间有什么区别?在哪种情况下应该使用哪种模式?
相关主题:同步HTTP处理程序和异步HTTP处理程序之间的性能差异
更新
我按照建议的延迟进行了10次测试
假设我有两个数组
val x =Array("one","two","three")
val y =Array("1","2","3")
Run Code Online (Sandbox Code Playgroud)
什么是获得像["one1","two2","three3"]这样的新阵列最优雅的方式
我有这样的查询
SELECT a.column, b.column
FROM
table_a a INNER JOIN tableb_b ON
a.id= b.id
where a.anotherid = 'some condition'
Run Code Online (Sandbox Code Playgroud)
它应该非常快,因为使用谓词a.anotherid ='某种条件',查询计划应在table_b上过滤大量数据。但是,根据Vertica的文档,
执行联接后,将评估WHERE子句。它过滤FROM子句返回的记录,从而消除任何不满足WHERE子句条件的记录。
这意味着查询将先执行联接然后进行过滤,这非常慢,这在查询计划中也显示
那么,有什么方法可以在加入连接之前推送过滤器?还是有其他方法可以优化查询?