简体   繁体   English

Vert.x:如何将 Verticle 隔离到专用事件循环?

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

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.在我的 java 应用程序中,我使用vertx-web 3.9.3创建一个 web 服务器来托管 web 应用程序和一些 rest api 端点。 The web-app is mission critical, the rest api, however, is just a nice to have.网络应用程序是关键任务,然而,其余的 api 只是一个很好的选择。

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, eg hangs the event loop thread, it won't affect my mission critical web-app.因此,我将 web-app 和 rest api 部署为两个 verticles - 每个在不同的端口上启动一个单独的 http 服务器,希望它们之间有明确的分离,以便如果 rest api 出错,例如挂起事件循环线程,它不会影响我的关键任务网络应用程序。

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.在我看来,我无法控制将哪个事件循环分配给给定的 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?在 vertx 中是否可以将 verticle 保持在孤立的环境中? Is it okay to create another Vertx instance, and will it achieve the separation?再创建一个Vertx实例可以吗,会不会实现分离?

You can create multiple Vert.x instances in the same process.您可以在同一进程中创建多个 Vert.x 实例。

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.如果您绝对需要保证其余 api 部分不会对网络应用程序造成任何问题,那么我建议将它们放在单独的进程中。 Sharing event loops is one possible interference problem when running in the same JVM, but there are others, like sharing memory.在同一 JVM 中运行时,共享事件循环是一种可能的干扰问题,但还有其他问题,例如共享内存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM