Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Vert.x has real concurrency for single verticles?

the question might look like a troll but it is actually about how vert.x manages concurrency since a verticle itself runs in a dedicated thread.

Let's look at this simple vert.x http server written in Java:

import org.vertx.java.core.Handler;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.platform.Verticle;

public class Server extends Verticle {
    public void start() {
        vertx.createHttpServer().requestHandler(new Handler<HttpServerRequest>() {
           public void handle(HttpServerRequest req) {
                req.response().end("Hello");
           }
        }).listen(8080);
    }
}

As far as I understand the docs, this whole file represents a verticle. So the start method is called within the dedicated verticle thread, so far so good. But where is the requestHandler invoked ? If it is invoked on exactly this thread I can't see where it is better than node.js.

I'm pretty familiar with Netty, which is the network/concurrency library vert.x is based on. Every incoming connection is mapped to a dedicated thread which scales quite nicely. So.. does this mean that incoming connections represent verticles as well ? But how can then the verticle instance "Server" communicate with those clients ? In fact I would say that this concept is as limited as Node.js.

Please help me to understand the concepts right!

Regards, Chris

like image 389
Kr0e Avatar asked Jul 22 '13 12:07

Kr0e


People also ask

Is Vertx single threaded?

Vert. x is not single threaded like node. js.

What is Vert X Verticles?

A verticle is the fundamental processing unit in Vert. x. The role of a verticle is to encapsulate a technical functional unit for processing events such as exposing an HTTP API and responding to requests, providing a repository interface on top of a database, or issuing requests to a third-party system.

Is Vert X reactive?

x is an open source, reactive and polyglot software development toolkit from the developers of Eclipse. Reactive programming is a programming paradigm, associated with asynchronous streams, which respond to any changes or events.

Is Vertx multithreaded?

Worker verticle instances are never executed concurrently by Vert. x by more than one thread, but can executed by different threads at different times.


1 Answers

I've talked to someone who is quite involved in vert.x and he told me that I'm basically right about the "concurrency" issue.

BUT: He showed me a section in the docs which I totally missed where "Scaling servers" is explained in detail.

The basic concept is, that when you write a verticle you just have single core performance. But it is possible to start the vert.x platform using the -instance parameter which defines how many instances of a given verticle are run. Vert.x does a bit of magic under the hood so that 10 instances of my server do not try to open 10 server sockets but actually a single on instead. This way vert.x is horizontally scalable even for single verticles.

This is really a great concept and especially a great framework!!

like image 125
Kr0e Avatar answered Sep 21 '22 17:09

Kr0e