I am confused about standard verticle and worker verticle in Vertx. And What are the use cases of them?
Asked
Active
Viewed 2,384 times
0
-
1Welcome to stack overflow, Please go through the [tour](https://stackoverflow.com/tour), the help center and the [How to Ask](https://stackoverflow.com/questions/how-to-ask) sections to see how this site works and to help you improve your current and future questions, which can help you get better answers. Please also have a look at [How do I ask](http://meta.stackexchange.com/a/10812/162852). – Dushyant Tankariya Aug 08 '19 at 06:55
1 Answers
6
Vert.x is an event-driven and non-blocking toolkit. When a “standard” verticle gets executed, its logic runs on an event loop thread. Whilst this thread runs the logic of that verticle, it cannot serve any other request, so this thread should not execute any blocking code.
But, sometimes, you do need to execute blocking code — doing a long computation, calling an external service synchronously, etc. — in which case, you need to make sure this doesn't happen on an event loop thread.
You have two ways to execute blocking code:
- Use a worker verticle, which will execute code in its own thread pool, that can you can configure as needed;
- Or use an
executeBlocking
block, which executes in a separate thread.

Sébastien Le Callonnec
- 26,254
- 8
- 67
- 80
-
Thanks for your answer. I have one doubt here, If we are doing Asynchronous IO operation like (DB call or External API call) Then these statement does not implicitly execute in Worker Verticle/Threads or we need to specify that verticle as worker..? In nodejs eventloop will push these kind of events (Async IO operations) to worker thread pool without any manual options. – GnanaJeyam May 17 '21 at 11:40
-
Unless you use the Vert.x primitives and libraries to perform those operations asynchronously, you need to execute them explicitly either in a `executeBlocking` block, or in a worker verticle. – Sébastien Le Callonnec May 19 '21 at 12:57
-
Thanks @sebastien if I'm performing the IO operations using ASYNC API then will it work same as Nodejs.. ? By pushing the IO operations into the worker thread pool and executing it Independently. – GnanaJeyam May 20 '21 at 06:15
-
As far as I understand, executeBlocking cost much less on context switch. this article helped me: https://www.redhat.com/en/blog/troubleshooting-performance-vertx-applications-part-i-%E2%80%94-event-loop-model – Pam Stums Oct 11 '21 at 12:41