News for hackers. Stuff that matters.
Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Friday May 04, 2012 @11:14AM (#3928738)
Finagle works fine. Thank you. Love it. But it does not take off. Why?

What all the JVM Node.js clones are missing and what Node.js sets apart are async libraries. There is no async (MySQL) JDBC driver for starters. If your IO drivers are not async, your async container is not very useful in real life.

Re:Vert.x – JVM Polyglot Alternative to Node.js by kyleburton on Friday May 04, 2012 @11:19AM (#3928764)
This. The biggest difference is in the two cultures: blocking is anathema to the Node.js community - they will literally reject libraries or code that blocks because it destroys the entire model; the JVM community does not value non-blocking code - most of the core (JDBC, Networking in general, File system operations) is all written in a blocking style - the JVM community accepts this with the implicit assumption that threads will help assuage those issues.

Python, Ruby and Perl all have the same cultural tolerance for blocking code. The Node.js community has a complete lack of tolerance for blocking code.

I work with the JVM every day (Clojure) and wish it was different wrt the common use of non-blocking code, but it's going to be a long road to get there on the JVM.

Kyle

Re:Vert.x – JVM Polyglot Alternative to Node.js by pron on Friday May 04, 2012 @11:29AM (#3928805)
Java Executors combined with Guava's ListenableFutures easily turn any blocking operation to an asynchronous one.

Netty's entire model is asynchronous, and Java 7 now has AsynchronousChannels for IO which, I assume, Netty will make use of.

All in all, the JVM has a much more solid and performant foundation than anything Node can provide. The whole difference will come down to a programming style preference. I am not entirely sure why Vert.x adopted the Node style rather than the proven servlet container, as I'm sure both styles provide comparable performance. I guess each may shine under different loads/usage patterns (my guess is that Vert.x/Node can squeeze more performance from a single thread, but servlets are more scalable).

Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Friday May 04, 2012 @11:33AM (#3928825)
There is no async MySDQL JDBC driver. If you encapsulate it in an async layer, you need to keep a thread for the connection.
Re:Vert.x – JVM Polyglot Alternative to Node.js by pron on Friday May 04, 2012 @11:49AM (#3928918)
Is that supposed to be bad? The programming style will be the same. If threads are done right, and the JVM can manage their affinity well (especially on NUMA architectures), it's best to use them and pass a relatively small amount of data between them, then they can provide much better performance than accessing the same large piece of RAM from many threads (that's what happens if you simply replicate a single event-loop thread with asynchronous IO).
Re:Vert.x – JVM Polyglot Alternative to Node.js by tensor on Friday May 04, 2012 @11:57AM (#3928961)
Maybe I am missing something, but how can you possibly have an async SQL driver without threads like this? This sounds like a case of your Node.js database driver hiding the exact same behaviour described here within C code.
Re:Vert.x – JVM Polyglot Alternative to Node.js by purplefox on Friday May 04, 2012 @01:36PM (#3929445)
If the wire protocol for the driver is published, then you can write a 100% async driver for it. I.e. no threads blocking, ever. In fact, I already did this for redis and vert.x (I will dig out the code for this some time).

If you are dealing with something where you don't know what the wire protocol is and you just have a blocking client library to play with (e.g. JDBC - JDBC is, by definition blocking - see the JDBC API), then you can't do much but to wrap the blocking api in an async facade and limit the number of threads that block at any one time. This is exactly what we do in vert.x. We accept the fact that many libraries in the Java world are blocking (e.g. JDBC) so we allow you to use them by running them on as a worker. This is one area where we differ from node.js. Node.js makes you run everything on an event loop. This is just silly for some things, e.g. long running computations (remember the Fibonacci number affair?), or calling blocking apis. With vert.x you run "event-loopy" things on the event loop but you can run "non event-loopy" things on a worker. It's a hybrid.

Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Saturday May 05, 2012 @01:23AM (#3931430)
A limited number of threads will not scale as real async wake-on-data connections will scale. If demand is higher than your thread pool, for the use case that you're web response builds on async backend requests, your site will be down.
Re:Vert.x – JVM Polyglot Alternative to Node.js by d503 on Friday May 04, 2012 @01:23PM (#3929395)
PostgresSQL's libpq supports nonblocking asynchronous operation, and node-postgres takes advantage of that.

http://www.postgresql.org/docs/9.1/static/libpq-async.html

https://github.com/brianc/node-postgres/blob/master/src/bind...

(notice the Connect method on line 325 of binding.cc)

At some level a client-server database driver isn't all that different from any other network client; you send a request over a socket and wait for a result. There's no reason you have to block while waiting.

Moreover some databases (like Postgres) let you receive asynchronous notifications signaled by transactions on other connections; that's how trigger-based replication systems like Bucardo do their thing.

http://www.postgresql.org/docs/9.1/static/sql-notify.html

Re:Vert.x – JVM Polyglot Alternative to Node.js by kodablah on Friday May 04, 2012 @01:26PM (#3929411)
Because it would be based on asynchronous socket responses. So you wouldn't iterate like you currently do w/ a ResultSet but rather have a simple "RowHandler" or sorts. However you still run into the trouble you do w/ node if you decide to do a lot of blocking work in there instead of just sending the row to some ExecutorService thread to get worked on.
Re:Vert.x – JVM Polyglot Alternative to Node.js by batista on Friday May 04, 2012 @12:01PM (#3928981)
Yes, but the lib can do it for you, and you won't have to know a thing.
Re:Vert.x – JVM Polyglot Alternative to Node.js by Locke1689 on Friday May 04, 2012 @11:26AM (#3928789)
What are you talking about? libevent invented everything Node.js uses and Python's Twisted had and has everything Node.js could dream of.

Node.js is just a reinvention of old technologies in Javascript.

Edit: Removed flame about Javascript because I don't want to have this debate again.

Re:Vert.x – JVM Polyglot Alternative to Node.js by kyleburton on Friday May 04, 2012 @11:43AM (#3928883)
I am talking about the cultures surrounding these languages and frameworks. Node's community rejects blocking libraries. Java's does not. I've used the non-blocking frameworks in Perl (POE and my own), C (select, and some of the poll variants), Ruby (event machine) and they are fine if you can avoid blocking libraries -- in these communities it is generally acceptable to write blocking libraries. I don't see it as a technical hurdle, I see it as a cultural one.
Re:Vert.x – JVM Polyglot Alternative to Node.js by Locke1689 on Friday May 04, 2012 @12:56PM (#3929286)
You need to start backing up your claims with actual data. What networking libraries are blocking in Node.js that are not blocking in Twisted? Moreover, what can't you do with a Twisted Deferred that you can do in Node.js?

There are two main things that block in computing:

* I/O

* CPU

You better believe that Node blocks on CPU, so what I/O does Node not block on that Twisted does?

Re:Vert.x – JVM Polyglot Alternative to Node.js by batista on Friday May 04, 2012 @12:07PM (#3929010)
I am talking about the cultures surrounding these languages and frameworks. Node's community rejects blocking libraries. Java's does not.

So what?

You get tons of Java libs to use, a majority of blocking ones and lots of non blocking on one hand, or you restrict yourself to the fewer non-blocking libs of varying quality available for Node.

With Java you can also turn blocking libs to non blocking with a wrapper and threads, whereas with Node.js if it's blocking you're screwing, because the js engine is single-threaded.

Re:Vert.x – JVM Polyglot Alternative to Node.js by ricardobeat on Friday May 04, 2012 @05:34PM (#3930445)
Node is nearing 10k published libraries. Is there a comprehensive site listing Java libraries?

It's trivial to offload blocking operations to other processes in node too, it's just not the preferred option.

Re:Vert.x – JVM Polyglot Alternative to Node.js by moe on Friday May 04, 2012 @06:35PM (#3930635)
Node is nearing 10k published libraries.

And ruby has 38237 gems. 99,9% of which are garbage.

Library-count is a terrible metric.

Re:Vert.x – JVM Polyglot Alternative to Node.js by juiceandjuice on Friday May 04, 2012 @06:36PM (#3930639)
Have you ever programmed in Java? That's a strange question to ask if you have.

http://mvnrepository.com/

Whatever libraries node has is a drop in the bucket compared to java.

Re:Vert.x – JVM Polyglot Alternative to Node.js by ricardobeat on Saturday May 05, 2012 @09:55PM (#3933888)
I haven't, thats why I asked. Node is just 2 years old. You'll get 90% of garbage on any open package manager.
Re:Vert.x – JVM Polyglot Alternative to Node.js by soc88 on Friday May 04, 2012 @12:08PM (#3929022)
You make it sound like "rejecting blocking libraries" was some noble principle. Due to the severe limitations of JavaScript, there is no other choice.
Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Friday May 04, 2012 @11:29AM (#3928807)
We run a major site on Java, had some thread trouble years ago in the very beginning, works very well now when tuned. Threads work.

BUT: I assume people will move to backend services with REST and combining REST backend results to a page. This increases IO a lot and will kill your latency and default thread models when you do sync code. You'd need to use async IO, composeable futures to manage latency and thread count. And if you do async backend REST, why not do async JDBC etc. But there are no libraries.

Re:Vert.x – JVM Polyglot Alternative to Node.js by batista on Friday May 04, 2012 @11:59AM (#3928977)
>This. The biggest difference is in the two cultures: blocking is anathema to the Node.js community - they will literally reject libraries or code that blocks because it destroys the entire model

Really? So they reject any kind of library that does anything except call a callback? Because everything else, from calculating 2+2 to creating a template blocks. And it doesn't matter when it happens, when it happens it blocks.

Re:Vert.x – JVM Polyglot Alternative to Node.js by spullara on Friday May 04, 2012 @12:36PM (#3929180)
Twitter is sponsoring a Summer of Code developer to create an async library for MySQL: http://engineering.twitter.com/2012/05/summer-of-code-at-twi...
Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Saturday May 05, 2012 @01:26AM (#3931433)
This can't be voted high enough.
Re:Vert.x – JVM Polyglot Alternative to Node.js by sehugg on Friday May 04, 2012 @12:12PM (#3929042)
Your async container still can be useful, since you can have worker threads executing blocking operations. This works fine as long as your JDBC queries are fast enough to feed the event loop without creating tons of threads.

What async containers like Netty (and by proxy, Vert.x) solve is high-latency cases like long polling and file upload/download. Netty for one does have support for zero-copy file transfers: http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example...

In my experience, these are a small percentage of cases so the majority of the app can use blocking I/O -- even long-polling code, as long as you are using the async framework for the client connection.

Re:Vert.x – JVM Polyglot Alternative to Node.js by andrewvc on Friday May 04, 2012 @11:28AM (#3928803)
So, I googled 'finagle java' and all the results were terrible. There was no concise description with a short example. Nothing led me to believe 'node.js' clone in anything I saw in the first few results. In fact, the first result was this: http://engineering.twitter.com/2011/08/finagle-protocol-agno...

"Protocol-agnostic RPC System" does not sound like a node clone at all.

Re:Vert.x – JVM Polyglot Alternative to Node.js by Uchikoma on Friday May 04, 2012 @11:32AM (#3928819)
(as a side note, what do you think REST PUT calls over HTTP on Node are?)

Finagle is about composing async IO calls, e.g. here

http://twitter.github.com/scala_school/finagle.html

This works much better in Scala, as Java is not very good at composing Futures. It needs a lot of boiler plate code as it lacks noise free closures.

Re:Vert.x – JVM Polyglot Alternative to Node.js by tlrobinson on Friday May 04, 2012 @02:35PM (#3929707)
There was no MySQL driver for Node when it was first created. You have to start somewhere.
Re:Vert.x – JVM Polyglot Alternative to Node.js by batista on Friday May 04, 2012 @11:57AM (#3928963)
>What all the JVM Node.js clones are missing and what Node.js sets apart are async libraries. There is no async (MySQL) JDBC driver for starters.

Would you call Node.js's MySQL drivers "production quality"?

Re:Vert.x – JVM Polyglot Alternative to Node.js by ricardobeat on Friday May 04, 2012 @02:18PM (#3929623)
Being non-existent and being production quality or not are very different things. BTW there are hundreds of node apps in production.
Re:Vert.x – JVM Polyglot Alternative to Node.js by batista on Friday May 04, 2012 @02:39PM (#3929724)
>Being non-existent and being production quality or not are very different things.

As far production is concerned, they might as well be the same thing.

>BTW there are hundreds of node apps in production.

Do they use some of Node's MySQL drivers though? For they (or their lack thereof) was the topic of this subthread.

Re:Vert.x – JVM Polyglot Alternative to Node.js by ricardobeat on Friday May 04, 2012 @03:41PM (#3929996)
The topic was the non-existence of drivers in other platforms, you brought quality up. Node itself isn't 1.0 yet. I don't see how not having anything is better than having something in development.

transloadit.com, from the module mantainers, has been using it for an year+. I don't have any magic insight into what modules sites use, but judging from the activity in their repo it's quite popular (~1000 watchers, 100+ forks): https://github.com/felixge/node-mysql

Re:Vert.x – JVM Polyglot Alternative to Node.js by scubaguy on Friday May 04, 2012 @12:17PM (#3929068)
Finagle looks like it is a bit lower level framework compared to vert.x. While Finagle aims to be a framework that supports services using multiple protocols, vert.x appears to be much more tailored for HTTP web services.
Re:Vert.x – JVM Polyglot Alternative to Node.js by gcampbell on Friday May 04, 2012 @12:49PM (#3929253)
finagle-http (https://github.com/twitter/finagle/tree/master/finagle-http) provides pretty much everything you need to build an HTTP web service.
Re:Vert.x – JVM Polyglot Alternative to Node.js by scubaguy on Friday May 04, 2012 @07:43PM (#3930819)
But take a look at the Finagle example from Heroku and compare it to the example from vert.x. There's a lot of boilerplate in the Finagle version because Finagle is a general purpose async service framework, which was my entire point.