Apache flink Flink 1.6异步IO-如何在使用REST服务调用丰富流时提高吞吐量?

Apache flink Flink 1.6异步IO-如何在使用REST服务调用丰富流时提高吞吐量?,apache-flink,Apache Flink,我目前使用的是Flink 1.6版,在AsyncIO方面遇到了一个问题,性能没有达到我的预期 我确信我在实施过程中犯了一些错误,因此任何建议都将不胜感激 发行摘要- 我正在消耗一个ID流。 对于每个id,我需要调用REST服务。 我实现了一个RichAsyncFunction,它执行异步REST调用 下面是相关的代码方法和asyncInvoke方法 // these are initialized in the open method ExecutorService executorServic

我目前使用的是Flink 1.6版,在AsyncIO方面遇到了一个问题,性能没有达到我的预期

我确信我在实施过程中犯了一些错误,因此任何建议都将不胜感激

发行摘要- 我正在消耗一个ID流。 对于每个id,我需要调用REST服务。 我实现了一个RichAsyncFunction,它执行异步REST调用

下面是相关的代码方法和asyncInvoke方法

// these are initialized in the open method
ExecutorService executorService = 
ExecutorService.newFixedThreadPool(n);
CloseableHttpAsyncClient client = ...
Gson gson = ...

public void asyncInvoke(String key, final ResultFuture<Item> resultFuture) throws Exception {

    executorService.submit(new Runnable() {

        client.execute(new HttpGet(new URI("http://myservice/" + key)), new FutureCallback<HttpResponse>() {
             @Override
                public void completed(final HttpResponse response) {
                    System.out.println("completed successfully");
                    Item item = gson.fromJson(EntityUtils.toString(response.getEntity), Item.class);
                    resultFuture.complete(Collections.singleton(item));
                }
        });
    });
//这些在open方法中初始化
ExecutorService ExecutorService=
ExecutorService.newFixedThreadPool(n);
CloseableHttpAsyncClient客户端=。。。
Gson Gson=。。。
public void asyncInvoke(字符串键,最终结果未来结果未来)引发异常{
executorService.submit(新的Runnable(){
执行(新的HttpGet(新的URI)(“http://myservice/“+key”),新未来回调(){
@凌驾
公共无效完成(最终HttpResponse响应){
System.out.println(“成功完成”);
Item Item=gson.fromJson(EntityUtils.toString(response.getEntity),Item.class);
resultFuture.complete(Collections.singleton(item));
}
});
});
}

通过上述实现,我尝试了:-

  • 提高浓缩操作的并行性
  • 增加executor服务中的线程数
  • 使用ApacheHTTPAsync客户端,我尝试了调整连接管理器设置——setDefaultMaxPerRoute和setMaxTotal
我始终获得大约100个请求/秒的吞吐量。该服务每秒可以处理5公里以上的数据。
我做错了什么,我该如何改进?

您是否检查了Flink作业()中的背压?这将有助于指出瓶颈所在。另外,您使用的是orderedWait还是unorderedWait,容量是多少?我假设您在
n
(创建线程池)中使用的是
setDefaultMaxPerRoute
setMaxTotal
以及
AsyncDataStream.unorderedWait()的容量参数。如果调用
AsyncDataStream.unorderedWait()
,而不使用容量参数,则默认值为100,考虑到当前结果,这是一个有趣的数字:)@DavidAnderson我使用的是unorderedWait,但我尚未设置容量参数。我一定会查看您共享的背压链接。@kkrugler这是一个有趣的观察结果。我没有提供容量参数。我将在调整后与大家分享结果。谢谢你的指点!