Node.js vs Vert.x — Part 2 : A Detailed Investigation

What is It All About?

Before comparing any server frameworks or programming languages, it is crucial to give a short definition for each. Popular Node.js is a server side platform created on Google Chrome’s JavaScript Engine (so-called V8 Engine). More details can be found in its official documentation. We will just add that this is a comfortable open source, cross-platform runtime environment for creating and managing networking apps. It applies JavaScript, and can be run on OS X, Microsoft Windows, and Linux.

Vert.x is a server framework which is quickly emerging. Its biggest advantage in contrast to many other frameworkcs is high performance thanks to a great range of supported protocols. It is crucial to note that Vert.x is a project affected by Node.js. They both provide an event-based programming model. Despite these two platforms stand for the asynchronous API, there is still one question arising: which one is better?

To begin with, it is important to mention similarities. The APIs are pretty much the same for both platforms, because they both offer asynchronous API. Their philosophies also look similar, and that is because Vert.x was designed as a Java version of Node.js. But a lot has changed since then.

Node.js is based on JavaScript while Vert.x is developed through the usage of Java. Despite its relation to Node.js, but Vert.x has its own original philosophy and benefits. Thus, many users prefer this server framework to similar offers.

According to DZone, the overall picture looks like this today:

But we’ll be looking at the gap that exists between Node.js and Vert.x, trying to find out why most Java-developers choose the second one.

Vert.x Unique Vision

Design philosophy of Vert.x is very interesting. You can discover it below:

Polyglot

Vert.x was created with the goal to support a few programming languages. So, it is not just limited to Java.

You can run it along with Ruby, Python, and JavaScript. So, it is a good alternative to Node.js. Just wait until Scala and Closure are added to this support list.

Favorable Concurrency Model

Do you want to be able to compose a code as a single thread app? That is a good way to achieve multi-thread programming results without synchronization, lock, or volatility.

It is nice to know that Vert.x provides an opportunity to design multiple threads. It all depends on the amount of CPU cores. By using this platform, developers can impose business logic.

Proposes Event Bus

Many cross-platforms aim to come up with a ‘single-server process DAEMON’. In contrast, our hero tries to establish a range of Vert.x-built server programs that integrate perfectly with one another. This is where an aptly called Event Bus steps in. Thus, you can implement the following functions: Point to Point and Pub/Sub. Easy communication is also guaranteed.

Module System + Public Module Repository

This cross-platform possesses a module system. We can assume this as a type of component. So, the entire project is targeted toward reusability. Users can sign up the module to a Public Module Repository. This is the way to share the module.

Some experts say that Vert.x is much more interesting than many other competitors. It makes the process of writing web apps easier and quicker.

Read Also : Part 1 — Node.js vs Vert.x

Major Differences

It is critical to admit that not everyone is in favor of Vert.x. Node.js developers benefit from the advanced support base and mature ecosystem. At the same time, Vert.x has a strong VM (JVM). These main differences lay on the surface. So, it is important to take a closer look.

1. Preferred languages

It is true that with Node.js, it is possible to prepare code using only JavaScript. At the same time, Vert.x makes comfortable use of Java, Groovy, JavaScript, and Ruby. It continues enhancing its support for Clojure, Scala and Python. So, if you want more preferred languages, Vert.x is for you.

2. Ability to use JVM

For Node.js users, this opportunity is missing. Vert.x can apply JVM which has been tuned by developers with advanced skills for ages. As for Node.js, you’ll find yourself dependent on Google’s V8. There is a corporate backing to V8 and Java.

3. Application of mature libraries

Developers can enjoy mature libraries for the JVM. However, Node.js is maturing faster. It offers a few excellent libraries such as Express, Socket.io, and Mongoose.

4. Performance

According to Vert.x Project, Vert.x definitely wins by its performance. The first scenario contrasted Node.js and Vert.x in a situation when an HTTP server was built and 200/OK response had been returned. Another scenario compared these two when a 72-byte static HTML file was returned as a response. In both cases, Vert.x showed better results.

5. Concurrency model

6. With Vert.x by your side, one can reach a multi-thread programming effect without synchronization, lock, or volatility. In the case of Node.js, the JavaScript execution engine does not support this function. So, to make this entire comparison clearer we are providing a sharp example of how the web server source code looks in both versions.

In Node.js:

StaticServlet.prototype.handleRequest = function(req, res) {
var self = this;
var path = (‘./’ + req.url.pathname).replace(‘//’,’/’).replace(/%(..)/g, function(match, hex){
return String.fromCharCode(parseInt(hex, 16));
});
console.log(path);
if (path == ‘./show’) {
res.writeHead(200, {‘content-type’: ‘text/html’});
res.write(“Hello: “);
res.end();
} else if (path == ‘./version’) {
res.writeHead(200, {‘content-type’: ‘text/html’});
res.write(“Node.js version: ” + ‘v0.10.26′);
res.end();
} else {
var parts = path.split(‘/’);
if (parts[parts.length-1].charAt(0) === ‘.’)
return self.sendForbidden_(req, res, path);
else {
fs.stat(path, function(err, stat) {
if (err)
return self.sendMissing_(req, res, path);
if (stat.isDirectory())
return self.sendDirectory_(req, res, path);
return self.sendFile_(req, res, path);
});
}
}
}

In Vert.x:

server.requestHandler(function(req) {
var file = ”;
if (req.path() == ‘/show’) {
req.response.chunked(true);
req.response.putHeader(‘content-type’,’text/html’);
req.response.write(“Hello: “);
req.response.end();
} else if (req.path() == ‘/version’) {
req.response.chunked(true);
req.response.putHeader(‘content-type’,’text/html’);
req.response.write(‘Vertx version: ‘ + ‘2.0.2-final (built 2013–10–08 10:55:59′);
req.response.end();
} else if (req.path() == ‘/’) {
file = ‘index.html’;
req.response.sendFile(‘app/’ + file);
} else if (req.path().indexOf(‘..’) == -1) {
file = req.path();
req.response.sendFile(‘app/’ + file);
}

These results may seem a bit surprising. The only obvious thing is that both servers are:
Capable of coping with great loads of requests per second (probably on the order of 500–1000)
Out of the box, meaning they run roughly the same.

However, the main hypothesis of the experts is that probably Vert.x really shines in handling multiple instances.

Conclusion

The main conclusion is that Node.js and Vert.x are still pretty much the same, but Vert.x is polyglot and reactive on JVM. Other differences are not that essential.

To conclude, here is a table which sums up the advantages of Node.js and Vert.x brilliantly.

Still, both Vert.x and Node.js development services are successfully used to deliver the most amazing web, mobile and cross-platform experiences for users all over the world. It is hard to tell which one is actually better. It all depends on the developer’s preferences and their goals. Do you have something to say on this topic? If so, we would love to hear from you in the comments below.


Originally published at www.agriya.com on September 20, 2016.