I got 2 questions that relate to Vertx threading model. The documentation mentions:
- A Vert.x instance maintains N event loop threads (where N by default is core*2) by default.
- For the levels of concurrency required in many modern applications, a blocking approach just doesn’t scale
Vertx also provides thread pool-related function to handle tasks using server resources requiring long periods for event handling (worker threads).
Ok, so we know that threads have overhead in terms of the memory they require (e.g. for their stack) and in context switching.
Vertx threads are not blocked (if correctly used) but if we got more event-loops than cores (and a thread pool for worker threads as well) isn't a context switch inevitable?
Second question - I want to understand how vert assures that a single thread is running for an event loop, considering the fact that thread switching/scheduling is done in OS level. I red in this documentation that:
An event loop context executes handlers on an event loop: handlers are executed directly on the IO threads, as a consequence:
- a handler will always be executed with the same thread
- a handler must never block the thread, otherwise it will create starvation for all the IO tasks associated with that event loop.
Can somone please clarify "handlers are executed directly on the IO threads"?