I use Vert.x v3.5.1. There is the simplest sample of code:
vertx.createHttpServer()
.requestHandler(anyRouter::accept)
.listen(8080);
In my case the event loop group size is 16 so I expect that my requests will affect 16 threads. Server is started succesfully but it works only in one thread. (I sent request using different tcp-connections so keep-alive is not a reason here.)
Class HttpServerImpl
contains httpHandlerMgr
and this manager handles a pool of event loops (named availableWorkers
). And during debug I saw that this pool contains only one worker.
Using of Verticle model doesn't resolve the issue, still not all of threads are used.
If I create server many times in loop, it helps. As a result I have many affected threads and one shared server. But it looks like workaround.
The question is how to create web server that uses all available event-loop threads?
Implementation with Verticle below
As a result this implementation uses half of available threads (8 threads). But I want it to use 16 :)
public static void main(String[] args) throws Exception {
int eventLoopSize = 16;
Vertx vertx = new VertxOptions().setEventLoopPoolSize(eventLoopSize);
for (int i=0;i<eventLoopSize; i++) {
vertx.deployVerticle(new MyServer(vertx), deploymentOptions);
}
}
public class MyServer implements Verticle {
final Vertx vertx;
public MyServer(Vertx vertx) {
this.vertx = vertx;
}
@Override
void init(Vertx vertx, Context context) {
vertx.createHttpServer()
.requestHandler(anyRouter::accept)
.listen(8080);
}
}