Don't write CPU intensive code in JS, duh

Posted by Peter J. Jones on

If you haven’t been following the flame war that ensued after Ted Dziuba wrote his now famous Node.js is Cancer article you’re missing out on some good fun. Ted’s main point is that event-based frameworks, specifically Node.js, suffer from a poor implementation that allows the main event loop to block if a handler blocks.

Tony Arcieri wrote a great follow up covering the fact that some people totally missed Ted’s point and even tried to solve the example problem that Ted used in his article to demonstrate the weakness in Node.js.

The Node.js blog didn’t directly respond to Ted’s criticism but instead decided to say “don’t do that” in a roundabout way:

Using Node does not mean that you have to write a video encoding algorithm in JavaScript (a language without even 64 bit integers) and crunch away in the main server event loop. The suggested approach is to separate the I/O bound task of receiving uploads and serving downloads from the compute bound task of video encoding. In the case of video encoding this is accomplished by forking out to ffmpeg. Node provides advanced means of asynchronously controlling subprocesses for work like this.

Disclaimer: Using JavaScript server-side seems gross to me.

About the Author

Peter J. Jones has been a professional software engineer for over 20 years and is deeply passionate about helping programmers improve the skills of their craft. He is the author of Effective Ruby: 48 Specific Ways to Write Better Ruby. Peter can be reached through our contact page or his twitter account.