Live data from Hacker News

What makes Node.js faster than Java? In a nutshell, it's all about concurrency

strongloop.com

31–40 of 59 posts

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#31
post #21

I have gotten to the point where I just can't take seriously anyone who equates "the async style" to "Node's event based system" as if Go, Erlang, Scala, Clojure, etc. don't exist. No, you do not have to choose between speed and sacrifice a sane coding style, and anyone still pushing that Node propaganda is just not worth listening to. Node is consistently beaten by multiple Go and Java frameworks across all benchmar…

I agree, they should at least compare to Go.

However, it is fair to say that when using Java, you have to choose carefully since many API's block on I/O, including those that Java programmers use by default and are most likely to be familiar with.

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#33
post #28
post #16

Earlier quoted context omitted.

Problem is the lack of third party libraries that does IO the way gevent works, if your lib does blocking IO, there is no point using gevent. NodeJS does async IO by default,so all nodejs libs do async IO. My point is , it's not so much about wether ruby or python can have the same capabilities as nodejs they can,it's about wether async libs have an ecosystem to support them or not.

"Problem is the lack of third party libraries that does IO the way gevent works, if your lib does blocking IO, there is no point using gevent." Here we probably see some of the problem. Gevent works in a way that most people don't expect, which is to hack the IO layer itself. You don't need a library to "support" gevent for it to still work within gevent. If the library's "synchronousness" is that it opens sockets an…

One can monkey-patch __builtins__, too, so `open("foo", "r").read()` will happily yield control to event loop. It's just that gevent doesn't do this.

Sounds like a great project to hack in spare time, though.

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#34
I wish the author had considered middleware components written with Netty -- they are async and highly concurent as well.

Moreover, Servlet 3.1 Specification , which is a part of Java EE7, includes JSR-340 Non-blocking I/O. In a typical application , ServletOutputStream and InputStream do read/write in a while loop while holding on to the request thread. This issue is potentially resolved in Servet 3.1 by adding event listeners – ReadListener and WriteListener interfaces. These are then registered using ServletInputStream.setReadListener and ServletOutputStream.setWriteListener. The listeners have callback methods that are invoked when the content is available to be read or can be written without blocking.

The new versions of Glassfish and Tomcat servers already support Servlet 3.1.

So Java already supports async style web applications. The programmers have to brush up their skills.

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#35
post #21

I have gotten to the point where I just can't take seriously anyone who equates "the async style" to "Node's event based system" as if Go, Erlang, Scala, Clojure, etc. don't exist. No, you do not have to choose between speed and sacrifice a sane coding style, and anyone still pushing that Node propaganda is just not worth listening to. Node is consistently beaten by multiple Go and Java frameworks across all benchmar…

I agree, they should at least compare to Go. However, it is fair to say that when using Java, you have to choose carefully since many API's block on I/O, including those that Java programmers use by default and are most likely to be familiar with.

The biggest impediment to async programming in Java-land is the lack of an async JDBC driver.

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#36
post #21

I have gotten to the point where I just can't take seriously anyone who equates "the async style" to "Node's event based system" as if Go, Erlang, Scala, Clojure, etc. don't exist. No, you do not have to choose between speed and sacrifice a sane coding style, and anyone still pushing that Node propaganda is just not worth listening to. Node is consistently beaten by multiple Go and Java frameworks across all benchmar…

What about generators and stuff like Koa[1]? Do you dismiss them too? You don't have to use events all the time, and it's trivial to wrap most Node IO as promises, thunks or whatever it is that you like, and then use generators as syntax sugar to work with them.

[1]: http://koajs.com

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#39
post #25
post #5

At first, I was ready to dismiss this article completely. However, this paragraph: "While Java or Node or something else may win a benchmark, no server has the non-blocking ecosystem of Node.js today. Over 50k modules all written in the async style, ready to use. Countless code examples strewn about the web. Lessons and tutorials all using the async style. Debuggers, monitors, loggers, cluster managers, test framewor…

This is slightly off topic, but if we're talking about language capabilities for async: Something I only figured out fairly recently but that shocked me is that Haskell, with its lazy evaluation, you can essentially get asynchronous programs for free, and still write in a synchronous style. While by default the IO monad is strict (basically makes IO stuff synchronous), there are some non-strict actions that are reall…

That's not all. This code:

    foo = do
        result 
Kinda sorta roughly desugars into something like this:

    function foo(cb) { do_first_thing(function(result) { do_second_thing(result, cb); }); }
Synchronous and asynchronous Haskell APIs can have the exact same interface.

Re: What makes Node.js faster than Java? In a nutshell, it's all about concurrency

#40
post #5

At first, I was ready to dismiss this article completely. However, this paragraph: "While Java or Node or something else may win a benchmark, no server has the non-blocking ecosystem of Node.js today. Over 50k modules all written in the async style, ready to use. Countless code examples strewn about the web. Lessons and tutorials all using the async style. Debuggers, monitors, loggers, cluster managers, test framewor…

PlayFramework (which I can't recommend enough) makes async and continuations super easy in Java. http://www.playframework.com/documentation/1.2.7/asynchronou... Play also dramatically improves Java's general... cruftiness.

Your link points to the (very old) 1.x branch docs.

http://www.playframework.com/documentation/2.2.x/JavaAsync

Post reply on HN