7 ms·
Node.js cures cancer
- kenneth_reitz 15y agoIt should be noted that, with PyPy, the Python example executes in 3.924s.
- sitharus 15y agoAnd F# running under Mono executes in 0.950s and the code is shorter, where standard Python 2.6 takes 1m36s. This isn't about pure speed.
- dekomote 15y agoBut, does it webscale?
- th_yc 15y agoYes, since PyPy (and Rubinius) have JITs (like V8), that is the fairer comparison. Nevertheless this highlights just how helpful JITs can be for cpu-bound code -- makes me wish PyPy was more ubiquitous (and gets py3k support sooner rather than later).
- pilif 15y agoWhile node is doing the calculation, it won't be doing anything else (like serving the next request). If a more traditional server is doing the calculation, it will spin up another process to handle the next request. If all you do is calculating Fibonacci, you can get ~(amount of CPUs) times the performance. You could use multinode for the same effect, but this is additional work. In the end, it's a matter of the type of service you are doing. If it's a Fibonacci generator, you'd use something that's better suited than either node/JS or any other scripting language. If you are doing something that's I/O heavy (which is probably the majority of today's web applications), node or other scripting languages might be better suited because they are easier to work with for most of us. It's just tools. Not religion. I wouldn't use a hammer to remove a screw. And I definitely wouldn't write hateful articles (I'm referring to the original one) because somebody was using a screwdriver instead of a hammer to remove the screw.
- pshc 15y agoIt's a troll article, but I'd like to point out that the "UNIX way" is alive and well in node.js. I spawn new processes to do heavy lifting (e.g. thumbnailing, hashing files) all the time. I put jobs into queues in redis and handle them in other node processes. Obviously in co-operative multitasking it's wrong to block the rest of the server.
- pork 15y ago> Obviously in co-operative multitasking it's wrong to block the rest of the server. I think that obviousness is exactly what the author missed.
- tedjdziuba 15y agoI like how every rebuttal turns into "how fast can you compute a fibonacci number". I was looking for a function that burned a nontrivial amount of CPU, the choice of fibonacci was arbitrary. Let's move on from that. What I was showing was that if your request handler does a nontrivial amount of CPU work, it will hold up the event loop and kill any "scalability" you think you're getting from Node. If you Node guys were really that irritated by this, you're going to be super pissed when you learn how computers work. I ain't even mad.
- jjm 15y agoIf your using node and doing work other than serving simple pages, then your probably sending that work off. Most production serious Node-ers know not to do heavy lifting within the system. I really don't know where anyone from the Node community has ever recommended stuffing their single threaded V8 backed event processor with cpu heavy tasks. I still don't know why people are so maximist with their tools. NodeJS is a tool. It works well with your _other_ tools. There - is - no - perfect - tool, no perfect programmer, not even perfect intent.
- tedjdziuba 15y ago> Most production serious Node-ers know not to do heavy lifting within the system. So Node is reduced to the trivial work? Then why make it unnecessarily hard on yourself? > I still don't know why people are so maximist with their tools. Because moving parts = risk.
- exogen 15y agoOne Node process is reduced to doing the trivial work, like you'd have in any other system. Nothing is preventing the other processes from also being Node.
- tedjdziuba 15y agoTrue, and in fact, this is how nginx works: the process that owns the event loop is separate from the process(es) that does the work. This is a decent way of mixing an event loop and multi-core processing, but with Node, you're forced to marry the HTTP server to the application, which is a dangerously tight coupling of responsibilities. If you really want to do something silly like write your application in server-side JS because you're familiar with it, then it should be through some interface like WSGI in Python (or even CGI in days of yore), which properly separates HTTP connection handling from application serving.
- thatdrew 15y agoAs a cancer survivor, just wanted to let you know that the poor taste exhibited here is pretty sad. When you want to make your point next time, use a title that doesn't include something that kills people. Thank you.
- deleted 15y ago[deleted]
- nasmorn 15y agoLike, node is the bomb? I am sure cancer sucks more than anything I had to experience but the world is not going to change its figures of speach for you and it is not directly derogatory at all it just reminds you of your misfortune. Btw I am not criticizing you for asking the OP to change his headline I just think it is an impossible crusade.
- nasmorn 15y agoSee how I just typed crusade and pressed send without thinking.
- deleted 15y ago[deleted]
- esrauch 15y agoTo be clear, the title is intended to point out how absurd the original title was (node.js is a cancer). I strongly suspect the author agrees with you on using this kind of language when describing a language/framework, which is exactly why he did include it in the title.
- mjijackson 15y agoIt's not the main point of the article, but I just thought I'd point out that node already does have a WSGI/Rack-style library for folks who like that kind of thing. It's called Strata (http://stratajs.org http://stratajs.org). Disclaimer: I'm the author.
- exogen 15y agoThanks, I didn't know that. I've added a link to the article.
- piyush_ranjan 15y agoA good and well thought reply to a troll
- evanlong 15y agoguys guys guys. you do realize ted is trolling us all right (go look at his twitter @dozba right now. I think he is having a great time). he is a pro at this (http://teddziuba.com/2011/07/the-craigslist-reverse-programmer-troll.html http://teddziuba.com/2011/07/the-craigslist-reverse-programm...) Also if his thoughts on node.js don't annoy you enough go take a look at his archive: http://teddziuba.com/archives.html http://teddziuba.com/archives.html. He blogs/trolls/thinks about NoSQL, OS X, twisted/tornado, python, queues and more.
- jjm 15y agoThose new to NodeJS will still read this trolled post and find real gems of info here. So all is not lost.
- aaronblohowiak 15y agoExcept it contains a lot of FUD, like saying that Node has no SSL support.
- nhebb 15y ago> he is a pro at this (http://teddziuba.com/2011/07/the-craigslist-reverse-programm... http://teddziuba.com/2011/07/the-craigslist-reverse-programm...) The Craigslist Reverse Programmer Troll is clever. While it's openly a troll, it makes a good point. Worth reading.
- biot 15y agoThere are actually some great posts in there. If you've been around long enough you'll overlook the asshole facade and see that while he often presents the material in a trollish, absolute manner there's wisdom to be found.
- jpr 15y agoBtw, in a world where energy is supposedly scarce, how do people justify using languages (Python, Ruby, I'm looking at you) that are an order or two magnitudes slower than they need to?
- ricardobeat 15y agoI'm getting 0.020s tops for that fibonacci code on node (time curl http://localhost/ http://localhost/), even going up to `1.1210238130165696e+167` (800th number). OSX Lion on a C2d 2.3ghz. Python 2.7.1 took 1m25.259s (no server). Am I doing something wrong? Or is there some incredibly optimized code path for OSX? edit: even weirder, `time node fibonacci.js` without a server takes 0.090s.
- exogen 15y agoSure you're calling fibonacci(40) and not just defining the function?
- deleted 15y ago[deleted]
- ricardobeat 15y agoYes. Turns out that the recursion overhead in python is huge, it can get down to <100ms too with a non-recursive function.
- piccadilly 15y agoI have no idea whether that is true and I'm not arguing with it. Why are you writing web request handlers containing heavily recursive code, and why do you seem to think that indicates anything meaningful about Python? Please tell me you are not also using SimpleHTTPServer to try to prove points about Python's performance (like http://joshuakehn.com/2011/10/3/Diagnosis-No-Cancer.html http://joshuakehn.com/2011/10/3/Diagnosis-No-Cancer.html and http://blog.brianbeck.com/post/node-js-cures-cancer http://blog.brianbeck.com/post/node-js-cures-cancer)
- ricardobeat 15y agoI wasn't. I was just curious about the huge difference in performance. These numbers are from printing to console, no servers. def fibonacci(n): t = [0, 1] for i in xrange(n): t.append(t[-1] + t[-2]) return t[-2] print fibonacci(800)
- ryanpers 15y agodboza is pretty awesome, beck didnt really address the underlying issue. If you have any real computation, node.js is not your solution. I figured out this in event-driven IO back when I was in school 15 years ago fffffff
- rian 15y agoIMHO i think node.js sucks because it forces you to manually pass callbacks around. can't it remember my call site for me and use coroutines or call/cc or yield or something? even fork() exists on UNIX (or pthread_create()). why is passing callbacks around the answer? it's like using GOTO.
- ricardobeat 15y agoIt can actually: http://onilabs.com/stratifiedjs http://onilabs.com/stratifiedjs https://github.com/0ctave/node-sync https://github.com/0ctave/node-sync
- dbattaglia 15y agoIt's painful but I can see why they don't want to be touching the V8 engine itself (as tempting as it probably is). Short of doing that you are stuck doing things the old-fashioned way (that is, callbacks). I'm sure things will be a lot better if/when the V8 engine supports let/yield.
- deleted 15y ago[deleted]
- kqueue 15y agoThis is where gcd can help. http://en.wikipedia.org/wiki/Grand_Central_Dispatch http://en.wikipedia.org/wiki/Grand_Central_Dispatch
- billconan 15y agoThe article uses two examples to demonstrate that v8 is in fact fast. However, when using python or ruby to create a web server, the server will actually run in parallel (multiple threads), therefore, the average waiting time could be less than the node.js version.
- billconan 15y agosuppose, for example, we have two people connecting to the server at the same time. if it is the node.js server, one person waited for 5 seconds, the other one waited for 10 seconds, the average waiting time is (5+10) / 2 = 7.5 assume that the python server is less efficient, which takes 7 seconds to finish the job. but it runs in parallel. so both two people waited 7 seconds. therefore, on average, the python server is in fact, faster
- billconan 15y agoi am not a node.js expert. one thing i am wondering is that, modern computers have more than just one core. how node.js utilizes these multiple cores?
- ricardobeat 15y agoBy starting multiple processes. See cluster (https://github.com/LearnBoost/cluster https://github.com/LearnBoost/cluster), fugue (https://github.com/pgte/fugue https://github.com/pgte/fugue), multi-node (https://github.com/kriszyp/multi-node https://github.com/kriszyp/multi-node)
- aliem 15y agoThis is true for Python, Ruby, PHP. (I can't see ted's issues with node other than misunderstanding of the framework's runtime)
- schiptsov 15y agoSuch a party I missed out.. ^_^
- dewiz 15y agohow do you dare ? and why are you at the top ? really disappointed
- dewiz 15y agoI'd really like to know why people like to joke on cancer and downvote people which might be hurt by these stupid titles.
- petercooper 15y agoIt's the equivalent of tying a giant boulder to the back of a Ferrari 599 and scoffing at how Ferrari can dare to call it a "high performance" car. Stop trying to drag giant boulders around.
- no_other_alias 15y agoNot really. It's like saying "this ferrari doesn't need fuel!". Which is just bullshit.
- piccadilly 15y agoThe original Node.JS is cancer article is a silly troll. But it's totally ridiculous how in response, people keep writing these terrible, straw-man Python servers to try to prove that Python is so horribly slow. If you want to write Python web apps, there is a correct way to do it, and it isn't to use SimpleHTTPServer. Write a WSGI application, and serve it with any of a number of decent WSGI servers (just for starters, try uwsgi behind nginx; but if you really insist on directly serving requests out of a server written in an interpreted language, you could try gevent).
- deleted 15y ago[deleted]
- LeafStorm 15y agotry: my_var except NameError: pass else: if my_var is not None: # Ted needs better examples ... When would you EVER need to use this code? There is no situation in which you should ever need to use a variable in Python that may or may not be defined. While Ted's example may seem like a cheap shot, it does highlight an important problem with JavaScript: all the craziness with regards to types that aren't "real" types like undefined, arguments, and Array.
- wyuenho 15y agoI was thinking about the same thing. There's no auto-vivification in Python. Thing just blow up and you fix your code. You NEVER do this in real Python code. I'm tired of straw man examples...
- wyuenho 15y agoIs it just me or is Brian Beck misunderstood Python idioms? What's with the try/except block? There's no auto-vivification in Python. So you just don't try to catch a NameError. You just let it blow up in your test and fix your code afterwards. I'm really tired of these straw man examples.
- sannysanoff 15y agoI wonder if 1) node.js async i/o is any different from haskell i/o? 2) author knows something about strongly-typed languages, or he deliberately banned them those from server side? Imho, dziuba tried to drop a hint about strongly-typed languages, not python or ruby.
- dewiz 15y agoI just hope you will never have to experience what cancer is, otherwise you will understand how important a "cure" could be.
- pfarrell 15y agoNode has a mantra which addresses this whole thread, right back to the beginning. "Everything in node runs in parallel, except your code". Manuel Kiessling has a written a great tutorial (http://nodebeginner.org http://nodebeginner.org) that shows how node noobs enter and can escape the blocking pitfall. Node is the right tool when your requests block on I/O. I'm not convinced about CPU heavy apps, yet.
- robgleeson 15y agoI read your benchmarks on Ruby, but you didn't list the implementation or version of Ruby you used. I'd guess you used MRI 1.8.X. I decided to benchmark other versions(and implementations) of Ruby. = jruby 1.6.4 (7.3 seconds) user system total real 7.388000 0.000000 7.388000 ( 7.349000) = Rubinius 1.2.4 (Little under 6 seconds) user system total real 5.940015 0.006878 5.946893 ( 5.842485) = CRuby 1.9.2 (38 seconds) user system total real 38.250000 0.090000 38.340000 ( 38.376857) = CRuby 1.8.7 (Little under 137 seconds) user system total real 136.960000 0.240000 137.200000 (137.437748) Thanks!
- th_yc 15y agoExactly -- for a fair comparision, V8 (which has a JIT) should be compared against Rubinius (for Ruby) and PyPy (for Python), which will both be nearly as fast as V8. Of course, it is true that V8 is ubiquitous, whereas Rubinius and PyPy are not -- that is the one majore advantage of javascript.
- mschalle 15y agoI think one thing that the article hints at is still relevant: "developers" nowadays throw around terms like "scalability" and other hype phrases and think that since they know the slightest thing about some new technology, they're a real developer. Sadly, this is incredibly naive. Any script kiddie / code monkey can some application in the latest over-hyped framework and say "HEY LOOK, IT CAN HAS NOSQL, IT CAN HAS SCALABILITY, IT DOES BIGGGGDATA", and write some inefficient code for this application. The truth is that many don't even understand basic data structures and how a computer processes information at a lower level. If you don't understand what something such as algorithmic complexity is, and can't look at your code from a more scientific and critical point of view, don't call yourself a freaking developer. Pick up a book and learn what REAL computer science is, not what the latest and greatest over-hyped framework is called.
- jufo 15y agoThe nice thing about node (or any other event-based platform) is that memoizing the Fibonacci function is trivial, whereas in a multi-threaded implementation it would be tricky and error-prone.