Reputation: 3213
I have a very simple Vert.x application that exposes a ping endpoint:
public class LauncherVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> future) throws Exception {
DeploymentOptions options = new DeploymentOptions();
options.setConfig(config());
options.setInstances(1);
String verticleName = Example1HttpServerVerticle.class.getName();
vertx.deployVerticle(verticleName, options, ar -> {
if (ar.succeeded()) {
future.complete();
} else {
future.fail(ar.cause());
}
});
}
}
public class PingVerticle extends AbstractVerticle {
@Override
public void start(Future<Void> future) throws Exception {
Router router = Router.router(vertx);
router.get("/ping").handler(context -> {
String payload = new JsonObject().put("hey", "ho").encode();
context.response().putHeader("content-type", "application/json").end(payload);
});
}
}
As expected, by default Vert.x creates two event loop threads that I can see with VisualVM:
Of course, the application doesn't do anything, so I know go and add an http server to PingVerticle
:
String host = "0.0.0.0";
int port = 7777;
vertx.createHttpServer().requestHandler(router::accept).listen(port, host, ar -> {
if (ar.succeeded()) {
future.complete();
} else {
future.fail(ar.cause());
}
});
Now I see in VisualVM that there are two new threads, an acceptor-thread, that I can more or less understand, and another eventloop-thread:
Why is this third eventloop-thread created?
Upvotes: 2
Views: 1521
Reputation: 21
Not much documentation on vert.x architecture but there is an interesting read on Understanding Vert.x Architecture
BTW, I have four core machine and i see the same number of threads at the application startup. I noticed increase in number of eventloop threads as more load is generated, while other threads remain single per vert.x process.
In short,
Upvotes: 2
Reputation: 4245
According to vert.x javadoc:
The default number of event loop threads to be used = 2 * number of cores on the machine.
It seems, you have more than 1 core.
Upvotes: 3