When deploying a verticle in a Vert.x application, the documentation appears to be painstakingly unclear about what a verticle "instance" actually is, and how it relates to threads and thread pools. In fact, it's rather unclear about anything relating to the actual threading model...
From the documentation;
Vert.x works differently here. Instead of a single event loop, each Vertx instance maintains several event loops. By default we choose the number based on the number of available cores on the machine, but this can be overridden.
Also from the documentation;
The number of instances of the verticle to instantiate in the Vert.x server. Each verticle instance is strictly single threaded so to scale your application across available cores you might want to deploy more than one instance. If omitted a single instance will be deployed. We'll talk more about scaling later on in this user manual.
Let's assume I want to deploy a simple REST API that is written as a single Verticle, and I would like to have it scale efficiently across available CPU cores. What should I do?
- Do I deploy one instance of the verticle per CPU core?
- Do I deploy a single instance of the verticle, as according to at least one part of documentation a single verticle instance will alread maintain several event loops (as I assume 1 event loop = 1 thread)?
- If I deploy 4 instances of a verticle, what threads and/or thread pools will actually be created/used?
The Vert.x documentation has this paragraph:
If you wanted to utilize all of your cores, you would deploy 2 verticles per core.
When you deploy a verticle, it gets assigned an event loop thread. That means that the execution of any code written inside a verticle will always be executed on the same event loop that the verticle was deployed on. This allows you to scale nicely across the available threads.