Shani Cohen
Shani Cohen

Reputation: 21

Vert.x httpClient - any idea how to limit the number of concurrent requests?

I need to send x HTTP client request. I want to send the requests in parallel, but no more than y at once.
I will explain: The client can handle only y requests simultaneously. I need to send x request to the client, while x > y.
I don't want to wait until all the first y requests will end, and then send another bulk of y requests. This approach isn't efficient, because at each moment, my client can handle y requests. If I will wait until all the first y will end to send another y requests, the client won't be fully utilized.

  1. Any Idea how can implement it with vert.x?
    I'm considering sending x requests at once and then send another request each time the handler gets the callback. Is it make sense?
  2. What is the meaning of maxPoolSize in HttpClientOptions? Is it have any connection to concurrent requests?

Many thanks!

Upvotes: 1

Views: 1569

Answers (2)

Shani Cohen
Shani Cohen

Reputation: 21

I'm answering my question... After some tests, the described test does not scale well with any reactor pattern. The solution here is to use a thread poll of y for sending x tasks.

Upvotes: 1

Alexey Soshin
Alexey Soshin

Reputation: 17741

I would suggest to go with your solution based on callbacks, and not to rely on maxPoolSize.

From the documentation:

 * 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

Upvotes: 0

Related Questions