Related topics

Node.js Native breakthrough: cloudy C++ on steroids

Cancer or performance buster?

Cancer or not, Node.js is attracting plenty of interest, and just like smoking cigarettes at school Node.js is seen as the cool thing to do.

Started by Ryan Dahl in 2009, this server-side scripting environment has in less than three years attracted enough coverage to persuade Microsoft, the world's largest software company, that Node.js is worth fine tuning for Windows and its anti-Amazon Azure cloud to win developer converts.

Some say Node.js is the new Ruby on Rails; this may, or may not, be a flattering comparison given the steam seems to have escaped from that particular engine and attentions have moved elsewhere as you don't hear so much about RoR today as a few years back.

Also, the numbers for this proclamation of popularity are suspicious: these smelly, Alexa-style market statistics are based on GitHub commits and conversations on Twitter. Tim O'Reilly once made similar assertions about RoR based on sales of books by his company about the language.

The allure of Node.js is undeniable: it harnesses server strength to the flexibility of JavaScript - all on Google's V8 JS execution engine. This is exciting as JavaScript applications increase in scale and complexity.

But here's a question: Node.js is written in C/C++ and Javascript - so what happens if you strip out the JS and keep the C++, which is already known for its blazing fast performance once compiled?

That's what programmer Daniel Kang from South Korea is attempting, with a project porting Node.js to latest update of the language - C++11 - published last year. The project is called Node.js Native.

"I thought this was the time for us to go back to native languages for cloud computing," he told The Reg during a call from his home in the peninsula republic.

Kang's port doesn't just remove the JavaScript bits, it also turfs out the V8 engine that was injected by Dahl. The port would be straight C++ (Node) on C++ (application) action with the intermediary layers stripped away.

Scream if you want to go faster

According to Kang, Node.js performance is fast enough for most projects on the client and server, but he's started to see more that are straining the environment. He said: "I saw interesting projects [on GitHub] using Node.js and they required more performance on their operations."

He cites the example of one backend system under development to collect .dat image file information from Microsoft's Kinect Xbox controller to redirect that to other services.

"Because it's not a frontend service it requires some very complicated operations and instructions. In such cases we need to use C++ as the frontend language", he said. "If I put C++ on top of that, we don't have any middleware or abstraction layers. We are just talking between two interpretive systems."

Why C++ is doubleplusgood

Invented by Bjarne Stroustrup more than 30 years ago, C++ is a statically typed language that delivers fast performance partly because it can be compiled into native instructions the processor can execute directly, rather than interpreting it at runtime - as happens with dynamic languages like Javascript.

C++ is so compelling that much of the world's most popular software still uses it - OS X, Facebook, Chrome, MapReduce, Windows 7, Firefox and MySQL to name just a few.

Kang reckoned a port to native C++ is more than 80 per cent faster than "conventional" Node.js, according to a highly unofficial "hello world" benchmark here.

Like many attracted to the original Node.js, Kang likes the non-blocking architecture; this is something that supposedly can handle thousands of concurrent user connections without the application slowing down while it waits for requests to be processed. Node.js does this because it combines all user requests as a single thread but offloads I/O operations that can slow things down for things such as disk or database operations from that main thread.

Kang picked C++ for porting because it's already his main programming language, and reckons he's not "naturally a Node.js developer" because most of his JavaScript experience is on the client side on AJAX.

"I'd tried different frameworks - AppEngine, Jungle, Flask and finally Node... but when I first saw Node I thought this is a very real thing - it was the simplicity and performance that attracted me," he said.

The port was only made possible thanks to C++11, according to Kang. Completed last year, and the first major revision to the language since 1998, C++11 was designed to make it more suited to distributed computing using CPUs with multiple cores.

C++ introduced a standardized memory model that means C++ developers no longer have to build or pick their own libraries to achieve concurrency in C++ applications. A standard memory model means greater consistency in the way apps are built when running on multi-core processors that power servers found in cloud data centres.

Other changes saw features such as lambda expressions introduced to help make coding in C++ a lot easier. C++11 "completely changed the former standard" Kang reckoned.

Kang, currently moving to start a coding job in Silicon Valley, started Node.js Native just three weeks ago. While it's a very preliminary stage, and despite his move, he promised: "I'm focused on the project." Challenges remain, though. The goal is for a first release in a month or two.

Whether Node.js means cancer is coming to C++ is unclear: the internet is littered with plenty of the latest hot framework or new programming language from either individuals or small teams of devs, which either lose the backing of the participants or that forever ride the narrow end of the "long tail". What ever happens with Node.js Native, you can keep track of the project, and potentially contribute, here. ®

Sponsored: Network DDoS protection