2

I am new to WebFlux and learning and understanding the concepts.

I am just playing around with the parallel calls and merging them.

I want to make parallel calls (20-25 times) to one REST endpoint and consume the responses and make a list of responses out of it.

On an average each call takes arounds 2secs. So ideally if I am making 20 calls parallelly all these should be completed in 2 sec or max 5 sec if there is any call with high response. But in my case if I am making 20 calls parallelly it's taking around 15 sec but ideally all calls were below 3 sec. Could anyone please help me on what I am doing wrong here?

I need a blocking call here because once I get all the responses for these 20 calls I have to merge them and make a list of responses out of it.

Here is my web client:

public Mono<MyObject> getxxxx(String id) {
    Mono<MyObject> orderDetails = webClient.get()
            .uri(uri+"/{id}", id)
            .exchange()
            .flatMap(clientResponse -> clientResponse.bodyToMono(MyObject.class));
    return details;
}

My helper class from where I am calling my web client like for 20 times parallelly:

public Mono<List<Myobject>> listOfOrderMonos = Flux
            .fromIterable(ids)
            .parallel()
            .runOn(Schedulers.elastic())
            .flatMap(ids-> obj.getxxxx(ids))
            .ordered((u1, u2) -> u1.getDate().compareTo(u2.getDate())).collect(Collectors.toList());

From the above method I am getting list of my objects MONO.

After I get this I am using it by .block() method.

List<MyObject> response = listOfOrderMonos.block();

Thank you

Woodchuck
  • 3,869
  • 2
  • 39
  • 70
hte_guy
  • 31
  • 5
  • Learn each tags before using. The mono tag is not for Java. – Lex Li Nov 30 '20 at 22:39
  • 1
    First of all, use parallel schedule, not elastic, also it makes not 20 parallel calls, it depends on your hardware and config, add log() operator and look at count of threads – Yauhen Balykin Dec 02 '20 at 20:34

0 Answers0