r/programming • • Oct 03 '11

Node.js Cures Cancer

http://blog.brianbeck.com/post/node-js-cures-cancer
390 Upvotes

329 comments sorted by

View all comments

102

u/kamatsu Oct 03 '11

Er, this article completely missed the point. Ted was saying that CPU-intensive tasks can starve all other connections, whereas a traditional HTTP server would happily compute the fibonaccis in another thread while continuing to serve requests. This is a fundamental weakness in Node (caused by the lack of V8 thread safety). The other point he made is that JS is a terrible language, also true. Both of these points were not satisfactorily rebutted in this article.

17

u/CaptainKabob Oct 03 '11

I agree they were not rebutted. In practice though, Node is usually deployed alongside another stack that deals with intensive processing tasks, while Node provides a function like websockets/pubsub that needs very little CPU, but tons of connections, or intensive IO (e.g. that MySQL query that takes 800ms to run... yeah, I have one of those)---all of which are just squatting on threads.

An example is how Drupal (LAMP) uses NodeJS: You've got Drupal rendering big, complicated static HTML on pageloads, while NodeJS hooks directly into the database, serving AJAX and bypassing the (slow/bloated) Drupal bootstrapping process for dynamic CRUD operations.

Sure, people are building entire MVCs on top of Node, but I think they're going to be burned. But yeah, I know the "use it when you need it"-attitude is a poor offense in a flamewar.

5

u/kamatsu Oct 03 '11

I agree that if you want to use node in those cases, there won't be any performance issues, and it might even be a reasonable tool for the job - but you're still stuck with JS, which is a bizarre language choice imo.

2

u/CaptainKabob Oct 03 '11

a bizarre language choice imo

I totally agree JS sucks. But for people who came to NodeJS from doing LAMP stuff, javascript is at least a known enemy (there is always CoffeeScript). And if you're throwing a lot of AJAXY stuff with javascript on the front-end, there is some symmetry to catching it on the backend with javascript too. Though maybe code reuse is a wash since everything parses JSON and usually the frontend stuff (DOM manipulation) is very different from backend stuff (database/IO).

→ More replies (5)

10

u/papercrane Oct 03 '11

The other point he made is that JS is a terrible language, also true.

He asserted that JS is a terrible language, he never proved the point.

3

u/ramses0 Oct 03 '11

JS is pretty terrible, by many measures. From the "Google / Dash" fiasco:

""" Dash is designed with three perspectives in mind:

  • Performance -- Dash is designed with performance characteristics in mind, so that it is possible to create VMs that do not have the performance problems that all EcmaScript VMs must have.

  • Developer Usability -- Dash is designed to keep the dynamic, easy-to-get-started, no-compile nature of Javascript that has made the web platform the clear winner for hobbyist developers.

  • Ability to be Tooled -- Dash is designed to be more easily tooled (e.g. with optional types) for large-scale projects that require code-comprehension features such as refactoring and finding callsites. Dash, however, does not require tooling to be effective--small-scale developers may still be satisfied with a text editor. """

Specifically "developer tooling / == / === / typeof / closures / etc." if you say "measure js on a spectrum of 1 to terrible w.r.t. performance, ide support, etc, etc" you can have a much better conversation.

--Robert

→ More replies (1)

9

u/killerstorm Oct 03 '11

WTF is a "traditional HTTP server"?

Threading, forking and event-driven servers are all present on the market. In many cases they are hybrids.

It is not unusual for event-driven server to spawn multiple processes to improve reliability and CPU utilization. That's how nginx works.

And that's how you should run node.js.

3

u/[deleted] Oct 03 '11

Why not just use nginx?

→ More replies (32)

3

u/StoneCypher Oct 03 '11

WTF is a "traditional HTTP server"?

A server that takes a request from a unix pipe as text, and sends back another completed request, also on a pipe, also as text.

8

u/[deleted] Oct 03 '11

Ted was saying that CPU-intensive tasks can starve all other connections,

Which proves that he missed the point of node.js entirely. It certainly isn't there for rendering video.

4

u/kamatsu Oct 03 '11

Sure, but he was trying to refute the hype that inexperienced programmers can write fast, scalable applications in node with little effort. That's just totally untrue.

27

u/headzoo Oct 03 '11

Both authors missed the point. You wouldn't write a CPU-intensive synchronous function in Node.js. You would write an asynchronous function, which allows other events to fire while you're calculating a value. Here is a fibonnaci function written asynchronously.

function fibonnaci(n, done) {
	if (n === 1 || n === 2) {
		done(1);
	} else {
		process.nextTick(function() {
			fibonnaci(n - 1, function(val1) {
				process.nextTick(function() {
					fibonnaci(n - 2, function(val2) {
						done(val1 + val2);
					});
				});
			});
		});
	}
};

And using it.

fibonnaci(20, function(val) {
	console.log('Final value ' + val);
});

This function is non-blocking. Now before you scream, "OMG, that looks so much more complicated!" That's just the world of asynchronous programming, which isn't unique to Node.js.

Regardless, there's nothing stopping anyone from writing a Node.js server that forks a child process to handle each request. There are even modules available that make the task fairly trivial.

15

u/kamatsu Oct 04 '11

That's just the world of asynchronous programming, which isn't unique to Node.js.

I can write an asynchronous fibonacci function which is much, much shorter than that in Erlang or Haskell. Any language with cheap green threads is a much better approach here.

Also, manually writing CPS is just ridiculous in this day and age.

41

u/bascule Oct 03 '11

You're completely missing Ted Dzuiba's point. Fibonacci is an arbitrary example of something CPU intensive, and certainly nowhere near a practical one. Most problems aren't this granular to where you can just shove the next processing step into the event loop each time.

And where a language on, say, the JVM, will be able to do a considerable amount of inlining and optimization on that sort of problem, by round tripping everything through the event loop each time you're defeating any optimizations of the sort.

That code is a complete monstrosity.

9

u/manu3000 Oct 03 '11

Why you would want to program in CPS when there are compilers that can do this perfectly, is beyond me...

→ More replies (1)

17

u/curdie Oct 03 '11

Yeah, which gets to my frustration with the node shaped library and JS; that's the world of manual continuation passing style. Which is a problem that's been solved a couple of times.

Node with a little surgery down into V8 to add continuation support (ok, maybe a lot of surgery) could be a different animal. Or maybe node with Dash in a future version of V8, but I haven't looked at Dash yet.

Anyway, the node library is cool, but it's only easy to use if you have continuations supported in your language, one way or the other.

14

u/[deleted] Oct 03 '11

Then you might as well use Scheme or Smalltalk or Common Lisp and unfortunately I don't see the masses clamouring to learn good solid languages like those.

Fucking Javascript.

4

u/munificent Oct 04 '11

Or maybe node with Dash in a future version of V8, but I haven't looked at Dash yet.

Well, no one has yet. Not for another week.

→ More replies (3)

8

u/cosmo7 Oct 03 '11

But you wouldn't have to do this on other platforms because you're already in a server thread.

→ More replies (3)

15

u/sausagefeet Oct 03 '11

That's just the world of asynchronous programming, which isn't unique to Node.js.

No, that is the route many libraries/frameworks choose to go, asynchronous doesn't mean you need complicated code, see Erlang. There are other reasons not to write Erlang but async doesn't mean you need code this ugly.

→ More replies (1)

29

u/StoneCypher Oct 03 '11

The idea that every function has to be wrapped in steps for a language that doesn't have proper threading or yielding is obscene. Not only are you raising the total workload by an order of magnitude, but you're radically unnecessarily complicating the software, lowering the eventual quality of the product.

That's just the world of asynchronous programming

No, it isn't. That's just the world when someone attempts to use the wrong language and tries to justify it without actual data to justify their position.

Many, many asynchronous languages exist; this is essentially the only one which makes you do ridiculous backflips to get even rudimentary parallelism going, and given that that's what this language adaptation claims to be for, that's just sad.

It's just golden hammer syndrome taken to the extreme.

2

u/rvirding Oct 05 '11

This has got to be a joke. You can't seriously be suggesting that people should write code in this manner. I will admit that we got some things wrong in Erlang (but not much) but at least it allows you to write asynchronous code in a sensible manner.

→ More replies (1)
→ More replies (1)

5

u/[deleted] Oct 03 '11

[removed] — view removed comment

2

u/kamatsu Oct 03 '11

Sure, but when something like Haskell lets you use the traditional process/thread pattern with equally scalable IO and outperforms node in all benchmarks, surely we could say that Node is not the best choice to be made here.

→ More replies (32)