TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

A response to Node.js is cancer - The Diagnosis

78 点作者 kfalter超过 13 年前

19 条评论

bigiain超过 13 年前
I think a better response to Ted's argument would have been to rewrite the fibonnaci number generator as a forked-off process with a callback that updates the requesting page on completion.<p>The thrust of Ted's argument (as I saw it, and completely agree with) is that telling people "inexperienced programmers can create high performance systems" is misleading or dangerous without pointing out that you can easily shoot yourself in the foot of you don't understand what is (and isn't) handled "magically" for you.<p>Using an algorithm that performs poorly in php or python isn't (necessarily) going to magically perform well in node.js's non blocking execution strategy. Abstracting away blocking network or io calls isn't going to help if you don't know (and notice) that your problem is the O(2^n) algorithm you're using.
michaelfeathers超过 13 年前
&#62; He contests that because a shitty Fibonacci number generator performs poorly Node.js is worthless. I contend that shitty Fibonacci generators are shitty in whatever language or framework.<p>I don't think he contends that. He was just using Fibonacci as an example to show that IO is not the only way to block a process. Although he doesn't go into it, this issue is one thing that you have to weigh when you decide to use eventing instead of threads: can you break up any potentially long running computation to maintain availability?
silentbicycle超过 13 年前
This response misses the point, which is just that it's trivial to show that you can write blocking code in node. Any program that does significant computation will still block and pause all network IO (without setting up side processes, etc.). "The stupid fibonacci benchmark" is just a cliche way to chew up the CPU.<p>My main beef with node.js is the hype, to be honest. Many of the people who are really excited about it seem completely unaware that this kind of thing is hardly new. Tcl has been based around an event-loop for ages! Erlang was made in the <i>mid-80s</i>, and has a very mature (and thoroughly integrated) event-loop-based architecture. Also, its focus is on fault-tolerance / error handling in a multi-node system. I don't know what progress Node.js has made there, so far.
评论 #3066681 未加载
评论 #3066519 未加载
vessenes超过 13 年前
He totally misunderstands node's reason for existence, and also why it can be awesome.<p>His preferred infrastructure (once I cut through the swagger) is:<p>Highly-tuned request dispatch --&#62; multiple processing threads (or processes) --&#62; back out to requesting client<p>For certain workloads, e.g. long-polling, pubsub or high-number-of-client workloads, unix dispatch overhead is actually very significant. One cannot instantiate 500 python threads on most unix boxen without severe doom.<p>For these workloads, essentially ones where you need to push text around with a minimum amount of stream processing on top of it, node is totally, totally brilliant. It is crazy fast. Magically so, even.<p>If you think of node as a lightweight turing-complete dispatch engine, you will be happy. If, on the other hand, you believe that fairies and pixie dust mean you can write blocking, bloated javascript code and that node will solve your worries, then you'll be disabused of that dream quickly.<p>On the other hand, if you started down the road with node, and realized at some point that you needed to refactor some of your slow code, you could do so easily. Doing the reverse (scaling an alternate scripting architecture) is not always so trivial.
评论 #3065558 未加载
评论 #3096274 未加载
eurleif超过 13 年前
I like node.js, but this post completely misunderstands "Node.js is Cancer". The point of that post isn't that node.js is slow; its point is that node.js does concurrency, but not parallelism; i.e., if your code is CPU-bound, it can only serve one request at a time.
评论 #3065002 未加载
评论 #3065861 未加载
评论 #3064982 未加载
josegonzalez超过 13 年前
To be honest, most of his blog posts seem to be inflammatory in nature with a cute picture at the top. I wouldn't be surprised if Ted wrote it merely to get blog views.
评论 #3066328 未加载
评论 #3065137 未加载
markokocic超过 13 年前
The article has a point, but poorly told. The problem is the following. Consider the following workload:<p>- 1 request to <a href="http://server/fiboslow" rel="nofollow">http://server/fiboslow</a><p>- 1000 requests to <a href="http://servir/fast-response" rel="nofollow">http://servir/fast-response</a><p>The point is that node will not process any of those 1000 requests until 1st one is finished, while any multithreaded/multiprocess server will do just fine, and process those 1000 requests in parallel.<p>&#60;smug note&#62; It's funny that the same people that criticized Java for its AWT EDT as poorly designed, are not praising the same thing in Node.js ;)
kenneth_reitz超过 13 年前
It should be noted that the Python code example runs in 4.038s on PyPy.<p>Standard Python: 1:07.31 :)
评论 #3068135 未加载
exogen超过 13 年前
Nice. I just wrote a followup to Ted's post myself: <a href="http://blog.brianbeck.com/post/node-js-cures-cancer" rel="nofollow">http://blog.brianbeck.com/post/node-js-cures-cancer</a><p>I couldn't believe when folks on Twitter seemed to be buying his "argument."<p>(Apologies for the self-promotion. I had literally just published mine when I saw this.)
评论 #3064967 未加载
Isofarro超过 13 年前
Not sure whether pointing out the slowness of other languages is a considered argument to make here.<p>Yes, there are other ways of blocking apart from IO. IO tends to be the main culprit, our web apps are mostly waiting for something. A database connection, a file system, another http request.<p>By making that asynchronous means we don't waste CPU time waiting. We let those external systems do their thing and when it's done, then the rest of the code runs. The important thing is that the IO isn't the bottleneck in node.js. It can do something else while the IO is doing it's thing.<p>This means that node.js is better at dealing with IO-laden processes better than the typical gamut of web frameworks.<p>CPU-bound processes are going to block unless they are performed outside of the main event loop. Dziuba is pointing that out, without offering up the obvious approach.<p>The approach to dealing with CPU intensive tasks is to delegate it to something that can be asynched out. If your platform of choice is multi-threaded, spin up a thread and run it there.<p>The node.js way, as I understand it, is to use IO to offload that intensive process somewhere else (at least until web workers is bedded in and ready to use). Since the IO is non-blocking, node.js doesn't consume much resources in waiting around for a response from the server/framework dealing with the CPU intensive activity.<p>The more I use it the more I see node.js as a pipeline connector between IO resources. Those other IO resources can either be other frameworks, or separate node.js instances that do one small job well. (So an IO process could just be a separate node.js instance that performs a CPU intensive task. In this way it doesn't affect the main request recipient in receiving more incoming requests).<p>One multi-core server can have a dozen or more instances of node running, each doing their specialised tasks and talking to each other asynchronously via IO.<p>Sure, it's not beginner level stuff. Even Dzubia himself didn't point out the better approaches to his naive solution - in node.js or any other language. node.js is as bad as every other framework when it comes to naive implementations of recursive algorithms. But offloading the calculation out of the main event loop thought non-blocking IO is a different solution that node.js offers. That's one key differentiator.<p>It would be interesting to see Dzubia demonstrate the implementation of his concocted problem in the framework / language of choice.
josephg超过 13 年前
I had the pleasure of missing Ted's original post. I read it before this one, and it was pretty misinformed. I could write a similar article arguing that assembly is useless because it takes so much code to implement a web server using it.<p>If your server runs in a single thread AND you do expensive calculations per request, you're doing it wrong. You should be caching results, and you need to either move the processing work to a backend server (written in C or something) or shard the frontend across a lot of cores (multiple processes / webworkers). In any of these configurations, nodejs will work great on the front end.<p>But, most of Ted's post was needless bile. The argument he made isn't justified by the evidence he gave. Don't bother trying to argue with him, its not worth your time.
ender7超过 13 年前
So, this may be a silly question, but what exactly are you doing that's going to use so much freakin' CPU?<p>Situations where blocking is going to be an issue:<p>1. You have roughly equivalent CPU usage per request, which means that you just have too many requests. Threaded or evented will both get bogged down here.<p>2. Most requests use a small amount of CPU, but every once in a while a request will require an ENORMOUS amounts of CPU. You want the one person with the crazy demand to feel slow, but everyone else to be unaffected. How often does this happen, exactly?<p>Most modern web apps spend the majority of their time talking to databases, which in NodeJS is a nonblocking operation. If you need to steamroll your CPU frequently, then perhaps NodeJS is not for you, but I don't think that's a common use case.
评论 #3065032 未加载
评论 #3065338 未加载
vessenes超过 13 年前
Is there a reason that these examples are using some sort of deeply nested call stack? Is it just to enforce 'slowness' in the function calls?<p><pre><code> def fibonacci(n): a,b = 0,1 for i in range(0,n): a,b, = b,a+b return b </code></pre> (cadged from zacharyfox.com) performs far, far better than the nested function calls. I imagine it would in javascript as well. In python at least, all that function calling infrastructure is relatively expensive.
评论 #3064990 未加载
评论 #3065006 未加载
mwill超过 13 年前
I strongly disagree with what Ted wrote, but I really wish he would come out and enter a dialog with the community. There's a thread on the mailing list, twitter, and blog responses floating around now, but no substantial effort by Ted to respond to or even acknowledge the replies he's received.
评论 #3065179 未加载
dicroce超过 13 年前
Asynchronous behavior is far from a panacea. Sometimes it is the right tool for the job... But for a lot of problems, all it's going to do is make your code more complicated.
tszming超过 13 年前
You made a good point: not many people are aware of the fact that the implementation of fibonacci number by Ted is just wrong.
评论 #3066683 未加载
hankejh超过 13 年前
Poor flower doesn't get it -- Node.js is a cancer, and Ruby is dead.
stottc超过 13 年前
It's remarkably easy to scatter a few process.nextTick() calls in long running functions to play nicely.
MostAwesomeDude超过 13 年前
I'm going to defer to exarkun on how Twisted does this: <a href="http://twistedmatrix.com/documents/current/web/howto/web-in-60/asynchronous.html" rel="nofollow">http://twistedmatrix.com/documents/current/web/howto/web-in-...</a> Note that his example doesn't bother to chew CPU, but you could chew CPU if you like, as long as you do it in a thread, and still best Node.