helidon-io / helidon

Java libraries for writing microservices
https://helidon.io
Apache License 2.0
3.44k stars 562 forks source link

3.x: WebClient: setting number of worker threads is obscure and undocumented #8916

Open barchetta opened 5 days ago

barchetta commented 5 days ago

Environment Details


Problem Description

While investigating a customer issue I was trying to figure out how to increase the size of the thread pool used by WebClient. It is obscure and undocumented.

From what I can tell the answer is that you need to add the following to application.yaml:

client:
  event-loop:
    workers: 10

And then do this before you build the WebClient:

        Config config = Config.create();
        Contexts.globalContext().register(config);

I could not find this in our documentation as there is no mention of the event-loop configuration in the docs, nor is there any support for it via the WebClient (builder) API. The bit about registering config in the globalContext() is especially obscure. The only way to figure this out is to look at source code:

https://github.com/helidon-io/helidon/blob/0c11b0446d57ef5fffaf1c38c53949448228edc9/webclient/webclient/src/main/java/io/helidon/webclient/NettyClient.java#L60

The only place I have seen any indication of the ability to set the number of worker threads in here:

https://github.com/helidon-io/helidon-examples/blob/53ad7a82789dfd00f4565e8beb36acafd75ea670/examples/webclient/standalone/src/main/resources/full-webclient-config.yaml#L19

But the example does not describe this, and in fact the example doesn't pick up the number of worker threads because it does not do Contexts.globalContext().register(config).

At a minimum we should add documentation for this. I assume in Helidon 4 this issue is not applicable because of our removal of Netty and use of VirtualThreads.