Vertx-web: Why there are performance issues with routing and webclient use

Created on 18 Nov 2019  Â·  9Comments  Â·  Source: vert-x3/vertx-web

Version

Context

I want to use webclient in the router's hander. First I use guice to inject webclient into the hander.

@Singleton
public class HttpClientHandler implements Handler<RoutingContext> {

    @Inject
    private WebClient webClient;


    @Override
    public void handle(RoutingContext request) {
        SocketAddress socketAddress=SocketAddress.inetSocketAddress(8080,"127.0.0.1");
        HttpRequest<Buffer> req= webClient.request(HttpMethod.GET,socketAddress,"");
        req.send(ar->{
                if(ar.succeeded()){
                    request.next();
                }else {
                    request.failed();
                }

        });
    }



}

The results after using the wrk test are:

wrk  -t8 -c400 -d20s --latency  "http://127.0.0.1:9000"

ioc

But if I initialize it in the handler, the performance will improve a lot.

public class HttpClientBaseHandler implements Handler<RoutingContext> {

    private WebClient webClient;

    @Inject
    private Vertx vertx;

    @Override
    public void handle(RoutingContext context) {
        if(webClient==null){
            WebClientOptions webClientOptions=new WebClientOptions();
            webClientOptions.setMaxPoolSize(4096);
            webClient=WebClient.create(vertx,webClientOptions);
        }
        SocketAddress socketAddress=SocketAddress.inetSocketAddress(8080,"127.0.0.1");
        HttpRequest<Buffer> request= webClient.request(HttpMethod.GET,socketAddress,"");
        request.send(ar->{
                if(ar.succeeded()){
                    context.next();
                }else {
                    System.out.println("fail");
                    context.failed();
                }
        });
    }




}

newInstance

So I want to know where the problem is.

Do you have a reproducer?

  • Link to github project/gist

Steps to reproduce

Extra

  • Anything that can be relevant
question

Most helpful comment

I'm having the same issue as described here. Is there a proper solution to this?

All 9 comments

that's likely because of the max pool size of the Web client, when you inject it in the handler ,you will get a single Web client connection pool (default size is 5) for all incoming requests and the performance will be limited by this, if you create it in request handling, you will not have this limitation anymore because the concurrency to 127.0.0.1 will be larger.

I changed the configuration before injecting, but the test results are still like this

public class WebModule extends AbstractModule {

    private Vertx vertx;

    public WebModule(Vertx vertx) {
        this.vertx = vertx;
    }

    @Override
    protected void configure() {     
        bind(WebClient.class).toInstance(providesWebClient());
    }


    private WebClient providesWebClient(){
        WebClientOptions webClientOptions=new WebClientOptions();
        webClientOptions.setMaxPoolSize(4096);
        webClientOptions.setTryUseCompression(true);
        return WebClient.create(vertx,webClientOptions);
    }
}

then provide a proper reproducer and we will investigate, thanks

I mean a GitHub project we can clone and quickly look at it (please avoid gradle if you can)

This is my test code:https://github.com/lwydyby/router-demo

I'm having the same issue as described here. Is there a proper solution to this?

We are also injecting vertx instance using guice. Will that create a issue?

@vietj I think this is closed but needs a look.

@vietj Facing similar issue of performance degradation using vertx web client. Using guice for injection . Can you reopen this and take a look once

Was this page helpful?
0 / 5 - 0 ratings