我有一个非常简单的Vert.x应用程序,它暴露了一个ping端点:
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);
});
}
}
正如所料,我可以用VisualVM看到的by default Vert.x creates two event loop threads:
当然,应用程序没有做任何事情,所以我知道去添加一个http服务器到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());
}
});
现在我在VisualVM中看到有两个新线程,一个我或多或少能理解的接受器线程,以及另一个eventloop线程:
为什么创建了第三个eventloop线程?
关于vert.x架构的文档不多,但有一篇关于Understanding Vert.x Architecture的有趣读物
顺便说一下,我有四个核心机器,我在应用程序启动时看到相同数量的线程。我注意到,当生成更多负载时,eventloop线程数量会增加,而其他线程在每个vert.x进程中保持单个。
简而言之,