0
votes

Does someone know how the following situation is handled by vert.x?

  • Consider verticle A and verticle B assigned to the same event loop
  • Verticle A receives 1 million cpu-bound events to process
  • After this Verticle B receives 1 cpu-bound event.

Will verticle B execution wait for the all queue from A to finish?

The documentation is not clear about this aspect.

Here is some excerpt from the documentation: http://vertx.io/manual.html#event-loops

When a standard verticle instance is deployed, the server chooses an event loop which will be assigned to that instance. Any subsequent work to be done for that instance will always be dispatched using that exact thread. Of course, since there are potentially many thousands of verticles running at any one time, a single event loop will be assigned to many verticles at the same time.

We call this the multi-reactor pattern. It's like the reactor pattern but there's more than one event loop.

Thanks, Mihai

2

2 Answers

3
votes

The Vert.x event loop is a NioEventLoop from Netty. Tasks to be executed by the event loop thread are queued in a MpscLinkedQueue which is a single-consumer/multi-producer queue.

This means tasks scheduled for execution are processed in the order they are submitted.

However, if there are several instances of a verticle (which all are possible consumers of the same events), round-robin scheduling is applied to distribute incoming events evenly among the consumers.

0
votes

I would not talk about "cpu events" but about events in general. If both verticles are assigned to the same event loop and events are queued in the order you said they will be executed in that way -- there is no event priority: the events are handled in the order they're in queue.

However it is very unlikely scenario and the important thing in vert.x is that each handler does not block the event loop -- ideally each verticle/handler should take very few cpu time to keep the platform whippy

HTH,
Carlo