How vert.x is single threaded?

696 views
Skip to first unread message

Ronald Randon

unread,
May 29, 2014, 9:16:50 AM5/29/14
to ve...@googlegroups.com
From my understanding, each vert.x instance will be assigned an event loop. Event loop handles all the request an other task for that particular instance. Event loop is a thread, I think. When there are multiple vert.x instance deployed, each instance have there own event loops right? More than one event loop means multi-threading right? That means there are multiple thread(multi-threading) exists. This is how I understood. This single-threading concept causing me so much headache. Any help will be appreciated.

Josh Kamau

unread,
May 29, 2014, 9:29:32 AM5/29/14
to ve...@googlegroups.com
Here is my humble suggestion.
 
Take some time and read the main manual (http://vertx.io/manual.html). Make sure you read all of it.
You will cover things like verticles, worker verticles, event bus, shared maps etc. 

For example: understanding worker verticles will help you understand ".. means there are multiple thread(multi-threading) exists"

Regards.
Josh.


On Thu, May 29, 2014 at 4:16 PM, Ronald Randon <ronald...@gmail.com> wrote:
From my understanding, each vert.x instance will be assigned an event loop. Event loop handles all the request an other task for that particular instance. Event loop is a thread, I think. When there are multiple vert.x instance deployed, each instance have there own event loops right? More than one event loop means multi-threading right? That means there are multiple thread(multi-threading) exists. This is how I understood. This single-threading concept causing me so much headache. Any help will be appreciated.

--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jez P

unread,
May 29, 2014, 12:11:44 PM5/29/14
to ve...@googlegroups.com
Vert.x is multithreaded but any given verticle instance will only be accessed by a single event loop thread. This means that you don't have to worry about locking of your verticle's internal state etc (if you maintain internal state). The same thread could access more than one verticle instance.

Alexander Lehmann

unread,
May 29, 2014, 1:00:10 PM5/29/14
to ve...@googlegroups.com
(I wrote a reply to your other question (tomcat vs. vert.x), but it didn't show up for some reason.)

When you run a single instance of the jvm with one or more verticles, they will use only one threads, but it is possible to start worker verticles that use their own threads. Anything that is not running in a worker thread is running in one event loop and will take care of how many requests or whatever operations are happening.

Each verticle is an instance of the verticle class so it can keep its own state, but the actual execution only happens in one at a time (which leads to kind of brain twister problem to understand what is happening when, once your comfortable with that it should be easy to implement code that correctly works with that).

Tim Fox

unread,
May 29, 2014, 1:07:57 PM5/29/14
to ve...@googlegroups.com
On 29/05/14 18:00, Alexander Lehmann wrote:
(I wrote a reply to your other question (tomcat vs. vert.x), but it didn't show up for some reason.)

When you run a single instance of the jvm with one or more verticles, they will use only one threads,

This is not correct. By default, a single Vert.x instance will instantiate N event loops, where N = 2 * number of cores on the machine.

When verticles are instantiated they are assigned an event loop in a round robin fashion.

Worker verticles do not use event loops, they run using threads from a thread pool.

but it is possible to start worker verticles that use their own threads. Anything that is not running in a worker thread is running in one event loop and will take care of how many requests or whatever operations are happening.

Each verticle is an instance of the verticle class so it can keep its own state, but the actual execution only happens in one at a time (which leads to kind of brain twister problem to understand what is happening when, once your comfortable with that it should be easy to implement code that correctly works with that).

On Thursday, May 29, 2014 3:16:50 PM UTC+2, Ronald Randon wrote:
From my understanding, each vert.x instance will be assigned an event loop. Event loop handles all the request an other task for that particular instance. Event loop is a thread, I think. When there are multiple vert.x instance deployed, each instance have there own event loops right? More than one event loop means multi-threading right? That means there are multiple thread(multi-threading) exists. This is how I understood. This single-threading concept causing me so much headache. Any help will be appreciated.
--

Alexander Lehmann

unread,
May 29, 2014, 1:31:34 PM5/29/14
to ve...@googlegroups.com
Sorry, wasn't aware of that, this makes sense in the way of distributing load of course.

I assume that any verticle will stay in a specific event loop when it is started?

Nick Scavelli

unread,
May 30, 2014, 10:13:12 AM5/30/14
to ve...@googlegroups.com


On Thursday, May 29, 2014 1:31:34 PM UTC-4, Alexander Lehmann wrote:
Sorry, wasn't aware of that, this makes sense in the way of distributing load of course.

I assume that any verticle will stay in a specific event loop when it is started?

Tim Fox

unread,
Jun 14, 2014, 6:54:26 AM6/14/14
to ve...@googlegroups.com
On 29/05/14 18:00, Alexander Lehmann wrote:
(I wrote a reply to your other question (tomcat vs. vert.x), but it didn't show up for some reason.)

When you run a single instance of the jvm with one or more verticles, they will use only one threads, but it is possible to start worker verticles that use their own threads. Anything that is not running in a worker thread is running in one event loop

Each verticle instance maintains several event loops, by default a number equal to twice the number of cores. Those threads are shared out between standard verticle instances in a round robin fashion.

and will take care of how many requests or whatever operations are happening.

Each verticle is an instance of the verticle class so it can keep its own state, but the actual execution only happens in one at a time (which leads to kind of brain twister problem to understand what is happening when, once your comfortable with that it should be easy to implement code that correctly works with that).

On Thursday, May 29, 2014 3:16:50 PM UTC+2, Ronald Randon wrote:
From my understanding, each vert.x instance will be assigned an event loop. Event loop handles all the request an other task for that particular instance. Event loop is a thread, I think. When there are multiple vert.x instance deployed, each instance have there own event loops right? More than one event loop means multi-threading right? That means there are multiple thread(multi-threading) exists. This is how I understood. This single-threading concept causing me so much headache. Any help will be appreciated.
--

Nick Scavelli

unread,
Jun 16, 2014, 12:27:52 PM6/16/14
to ve...@googlegroups.com


On Saturday, June 14, 2014 6:54:26 AM UTC-4, Tim Fox wrote:
On 29/05/14 18:00, Alexander Lehmann wrote:
(I wrote a reply to your other question (tomcat vs. vert.x), but it didn't show up for some reason.)

When you run a single instance of the jvm with one or more verticles, they will use only one threads, but it is possible to start worker verticles that use their own threads. Anything that is not running in a worker thread is running in one event loop

Each verticle instance maintains several event loops, by default a number equal to twice the number of cores. Those threads are shared out between standard verticle instances in a round robin fashion.

Just so no one is confused, he means "Each *vertx* instance maintains several event loops"  :)

Tim Fox

unread,
Jun 17, 2014, 2:56:25 AM6/17/14
to ve...@googlegroups.com
On 16/06/14 17:27, Nick Scavelli wrote:


On Saturday, June 14, 2014 6:54:26 AM UTC-4, Tim Fox wrote:
On 29/05/14 18:00, Alexander Lehmann wrote:
(I wrote a reply to your other question (tomcat vs. vert.x), but it didn't show up for some reason.)

When you run a single instance of the jvm with one or more verticles, they will use only one threads, but it is possible to start worker verticles that use their own threads. Anything that is not running in a worker thread is running in one event loop

Each verticle instance maintains several event loops, by default a number equal to twice the number of cores. Those threads are shared out between standard verticle instances in a round robin fashion.

Just so no one is confused, he means "Each *vertx* instance maintains several event loops"  :)


Yes. Thanks Nick for spotting my  mistake :)
Reply all
Reply to author
Forward
0 new messages