javavert.xvertx-verticlejava-vertx-web

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. 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?


Solution

  • 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.