Vert.x httpClient-知道如何限制并发请求的数量吗?

问题描述

我需要发送x HTTP客户端请求。我想并行发送请求,但一次不超过y。
我会解释: 客户端只能同时处理y个请求。我需要向客户发送x请求,而x> y。
我不想等到所有第一个y请求都结束,然后再发送另一批y请求。这种方法效率不高,因为我的客户每时每刻都可以处理y个请求。如果我等到所有第一个y结束发送另一个y请求,客户端将无法得到充分利用。

  1. 有什么想法可以使用vert.x实现吗?
    我正在考虑一次发送x个请求,然后每次处理程序获取回调时发送另一个请求。有道理吗?
  2. HttpClientOptions中的maxPoolSize是什么意思?它与并发请求有任何联系吗?

非常感谢!

解决方法

我建议您使用基于回调的解决方案,而不要依赖maxPoolSize

从文档中:

 * If an HttpClient receives a request but is already handling maxPoolSize requests it will attempt to put the new
 * request on it's wait queue.  If the maxWaitQueueSize is set and the new request would cause the wait queue to exceed
 * that size then the request will receive this exception.

https://github.com/eclipse-vertx/vert.x/blob/master/src/main/java/io/vertx/core/http/ConnectionPoolTooBusyException.java

,

我正在回答我的问题...经过一些测试,所描述的测试在任何反应堆模式下均无法很好地扩展。这里的解决方案是使用y的线程轮询发送x个任务。