|
|
|
|
|
by curun1r
4569 days ago
|
|
The biggest contributor to performance issues these days, from what I've seen, is synchronous code. The JVM can be blindingly fast at running your code, but when it hits a point where you make a database call or web services call that's implemented synchronously, it sits there, waiting, doing nothing. No amount of VM optimizations can increase of the speed of idling code. This is why Node apps often out-perform Java apps despite running on a VM that's significantly slower. Node is pervasively asynchronous...it's baked into the DNA of the platform and almost all libraries follow that philosophy. And as organizations move to a micro-services architecture where one external call can result in multiple internal calls between systems, the need for reactive, asynchronous programming becomes all the more glaring. That's where this critique, for me, fell down. It's spent too much time comparing the JVM to V8 and not enough time talking about how the applications being run were designed. Because CPUs are fast enough these days that any of the VMs will give you decent performance for workloads that aren't CPU-bound as long as you, the application designer, do the right thing. It's just that some environments, Node in particular, make it easier to do the right thing. This will get easier in Java with the introduction of lambdas in Java 8 and the inevitable asynchronous community frameworks and libraries, but right now it's still harder to write reactive applications in Java than it is in Node. |
|
Personally I view that as a drawback. It's all fine, until you end up with CPU-bound tasks or until you end up talking with backend servers that don't support many concurrent requests.
The JVM support for multi-threading is absolutely stellar. You've got true 1:1 kernel-level threading, with no GILs and you've got access to the best primitives available for dealing with multi-threading issues, atomic references, re-entrant read-write locks, fork-join thread-pools, non-blocking data-structures, asynchronous I/O guaranteed to work well cross-platform, all of them backed by a guaranteed memory model that also works well cross-platform, plus garbage-collectors that are the most advanced garbage collectors in mainstream usage. G1/CMS are amazing for servers and if you've got cash to spend, Azure's pauseless GC is probably as close to real-time as you can get with a GC.
And on top of these you can build whatever concurrency handling architecture you want. Including Erlang-style Actors (e.g. Quasar, Akka), STM (Clojure, Scala-STM), persistent data-structures (Clojure, Scala), asynchronous streams (Play2's Iteratees, RxJava Observables, Scalaz Machines, Scalaz Streams).
Even when speaking of Node.js's strengths, like asynchronous I/O, I still think Java is better because of the foundations (e.g. NIO, Netty, Mina). The only reason people don't work much with asynchronous workflows is because the language is so freaking painful for that. But that will change with Java 8 and people are doing wonders in Scala/Clojure.
I've personally built an entire web-service, designed to handle thousands of requests per second per frontend instance, with responses generated in under 30ms, with a completely asynchronous workflow, on top of Scala/Akka/Play2. Node.js people don't know what they are missing.