Why donesn't HttpClient connection pool work?

70 views
Skip to first unread message

Bitbone

unread,
Apr 17, 2018, 11:55:36 PM4/17/18
to vert.x
I am testing vertx httpCient. The codes are :

/*
* this vertice query mock server on every message
*/

public class QueryMockVerticle extends AbstractVerticle {
   
private static final Logger LOG = LoggerFactory.getLogger(HttpServerVerticle.class);

   
private HttpClient httpClient;

   
@Override
   
public void start() throws Exception {
       
super.start();

       
this.httpClient = vertx.createHttpClient(new HttpClientOptions()
               
.setKeepAlive(true)
               
.setTcpKeepAlive(true)
               
.setIdleTimeout(1000 * 60)
               
.setMaxPoolSize(100)
       
);

       
EventBus eventBus = vertx.eventBus();
        eventBus
.consumer("queryTarget", (msg) -> {
           
HttpClientRequest clientRequest = httpClient.get(8080, "10.95.123.131", "/test.jsp",
                    response
-> response.bodyHandler(responseBuffer ->  {
                        LOG
.info("Get nodejs response, " + this.deploymentID());

                        msg
.reply(responseBuffer.toString());
                   
})
           
);
            clientRequest
.exceptionHandler(t -> LOG.error("", t));
            clientRequest
.putHeader("Connection", "keep-alive"); // if this line is commented out, the jsp below will print 'null'
            clientRequest
.end();
       
});
   
}

   
@Override
   
public void stop() throws Exception {
       
super.stop();
       
this.httpClient.close();
   
}
}

this is the verticle to generate load:
public class LoadTestVerticle extends AbstractVerticle {
   
private long timerId;

   
@Override
   
public void start() throws Exception {
       
super.start();

       
EventBus eventBus = vertx.eventBus();

        timerId
= vertx.setPeriodic(5, time -> {
            eventBus
.send("queryTarget", "", asyncResult ->
                   
System.out.println(asyncResult.result().body())
           
);
       
});
   
}

   
@Override
   
public void stop() throws Exception {
       
super.stop();
        vertx
.cancelTimer(timerId);
   
}
}

The main class :
public class HelloWorldEmbedded {

   
public static void main(String[] args) {
       
System.out.println("cpu count: " + Runtime.getRuntime().availableProcessors());
       
VertxOptions vertxOptions = new VertxOptions();
       
System.out.println("event loop threads: " + vertxOptions.getEventLoopPoolSize());
       
Vertx vertx = Vertx.vertx(vertxOptions);

       
Verticle httpServerVerticle = new HttpServerVerticle();
        vertx
.deployVerticle(httpServerVerticle);

       
//int queryVerticleCount = vertxOptions.getEventLoopPoolSize() > 1 ? vertxOptions.getEventLoopPoolSize() - 1 : 1;
       
int queryVerticleCount = 10;
       
for (int i = 0; i < queryVerticleCount; i++) {
            vertx
.deployVerticle(new QueryMockVerticle());
       
}

        vertx
.deployVerticle(new LoadTestVerticle());

   
}

}




The jsp is :
<% System.out.println(request.getHeader("Connection")); %>OK


After vertx started up, I got too many "TIME_WAIT" TCP connections.
Every 1.0s: netstat -4 | grep TIME_WAIT | wc -l                                                                                                                                                                    

25173


So, what's wrong with my code? Why doesn't connection pool  work? Anyon can help me ?

Bitbone

unread,
Apr 18, 2018, 9:45:03 PM4/18/18
to vert.x
I replaced the vertx HttpClient with the org.asynchttpclient.AsyncClient, which works well, no more TIME_WAIT.

Thomas SEGISMONT

unread,
Apr 19, 2018, 8:17:48 AM4/19/18
to ve...@googlegroups.com
Can you create a small reproducer on GitHub, it seems some code is missing here.

Do not forget to add your expectations/observations.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/5e1076a6-c353-45a6-9d15-833166fc82fb%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Julien Viet

unread,
Apr 20, 2018, 2:05:17 PM4/20/18
to ve...@googlegroups.com
what is your Vert.x version ?

-- 
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Bitbone

unread,
Apr 23, 2018, 10:24:24 PM4/23/18
to vert.x
3.5.1

Bitbone

unread,
Apr 23, 2018, 10:24:50 PM4/23/18
to vert.x
OK, I'll try.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.

Julien Viet

unread,
Apr 24, 2018, 8:45:59 AM4/24/18
to ve...@googlegroups.com
can you try with current master ?

Reply all
Reply to author
Forward
0 new messages