在 vert.x 中,在运行时创建多个 HttpServer 实例是否有意义?

In vert.x, does it make sense to create multiple HttpServer instances in a runtime?

我创建了一个名为 HttpServerVerticle 的 Verticle 并在其中让它通过 vertx.createHttpServer() 创建了一个 HttpServer 实例,然后在我的主 Verticle 中我部署了这个具有 > 1 个实例的 HTTP Verticle vertx.deployVerticle("xxx.xxx.HttpServerVerticle", deploymentOptionsOf(instances = 2)).

在运行时有多个 HttpServer 实例有意义吗?如果是,为什么我没有看到类似“8080 端口已在使用”之类的错误消息?

Vert.x 实际上会 round-robin between your HttpServer instances listening on the same port:

When several HTTP servers listen on the same port, vert.x orchestrates the request handling using a round-robin strategy...

So, when [a] verticle is instantiated multiple times as with: vertx run io.vertx.examples.http.sharing.HttpServerVerticle -instances 2, what’s happening? If both verticles would bind to the same port, you would receive a socket exception. Fortunately, vert.x is handling this case for you. When you deploy another server on the same host and port as an existing server it doesn’t actually try and create a new server listening on the same host/port. It binds only once to the socket. When receiving a request it calls the server handlers following a round robin strategy...

Consequently the servers can scale over available cores while each Vert.x verticle instance remains strictly single threaded, and you don’t have to do any special tricks like writing load-balancers in order to scale your server on your multi-core machine.

因此,如果需要跨核心扩展,创建多个 HttpServer 实例既安全又值得鼓励。