Vert.x:如何将一个 verticle 隔离到专用的事件循环?

huangapple go评论65阅读模式
英文:

Vert.x: how to isolate a verticle to dedicated event loop?

问题

在我的Java应用程序中,我正在使用vertx-web 3.9.3来创建一个Web服务器,用于托管Web应用程序和一些REST API端点。Web应用程序具有关键任务,然而REST API只是一个附加项。

因此,我将Web应用程序和REST API部署为两个垂直部件 - 分别在不同的端口上启动单独的HTTP服务器,希望在它们之间有明确的分隔,这样如果REST API出现错误,例如挂起事件循环线程,它不会影响到我关键的Web应用程序。

然而事实证明情况并非如此。在我看来,我无法控制将哪个事件循环分配给特定的垂直部件。虽然在分配事件循环时似乎采用了轮询策略,但如果存在足够多的垂直部件,其中一些垂直部件最终将开始共享同一个事件循环(我无法确定地控制)。

在Vert.x中是否有可能保持垂直部件处于隔离环境中?创建另一个Vertx实例是否可以,它是否会实现分隔?

英文:

In my java application, I am using vertx-web 3.9.3 to create a web server for hosting both a web-app and some rest api endpoints. The web-app is mission critical, the rest api, however, is just a nice to have.

I deployed the web-app and rest api therefore as two verticles - each starting a separate http server on a different port, in the hope that there is a clear separation between them so that if rest api makes a mistake, e.g. hangs the event loop thread, it won't affect my mission critical web-app.

This turns out to be not the case. It appears to me that I cannot control which event loop to be assigned to a given verticle. Although there seems to be a round robin policy when assigning event loops, if there are enough verticles, some of them will eventually start sharing the same event loop (in a way I cannot deterministically control).

Is it possible in vertx to keep a verticle in an isolated environment? Is it okay to create another Vertx instance, and will it achieve the separation?

答案1

得分: 2

你可以在同一个进程中创建多个 Vert.x 实例。

但在大多数情况下,为了部署你想要的顶点(verticle),创建足够数量的事件循环会更简单:

vertxOptions.setEventLoopPoolSize(size);

如果你绝对需要确保 REST API 部分不会对 Web 应用程序部分造成任何问题,那么我建议将它们放在单独的进程中。
在同一个 JVM 中运行时,共享事件循环是可能的干扰问题之一,还有其他问题,比如共享内存。

英文:

You can create multiple Vert.x instances in the same process.

In most cases though it is simpler to create enough event loops for the number of verticles you want to deploy:

vertxOptions.setEventLoopPoolSize(size);

If you absolutely need to guarantee the rest api part does not cause any issue to the web-app one, then I would recommend to put them in separate processes.
Sharing event loops is one possible interference problem when running in the same JVM, but there are others, like sharing memory.

huangapple
  • 本文由 发表于 2020年9月23日 02:56:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/64016085.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定