Nginx the new Apache, node.js the new PHP?

Yesterday I attended Cloudstock, a pre-conference event put on by Salesforce.com as part of its Dreamforce event in San Francisco.

One of the speakers was Ryan Dahl, the author of node.js. He is smart and opinionated and gave a though-provoking introduction to his project. He has a couple of core arguments. The first is that I/O is slow, and therefore all I/O calls should be non-blocking.

 

ryan-dahl.jpgThe point here is that access to the disk or the network is hundreds of times slower than access to memory. A few milliseconds may not matter much in a single-user desktop application, but if you are coding a server with many concurrent users it becomes important.

You see this problem magnified many times in web pages that allow calls to remote servers to block the loading of a page. Web developers have learned to use callbacks for things like database queries that can take a while to return. Clients like Flash and Silverlight have no other mechanism for web service calls; doing these via callbacks is built in.

 Dahl's second point is that threading does not scale well. He showed a slide comparing the performance of Apache to Nginx as the number of concurrent connections increases. It showed Apache's memory usage growing while that of Nginx hardly changed. Dahl said that Apache uses a separate thread for each connection, but Nginx uses an event model, which is why it performs better under heavy load. 

Dahl says threads consume too many resources and complicate coding because you have to worry about synchronisation. He adds that Nginx will "probably take the place of Apache" because of its better performance.

Put these two things together and you get Node.js, which is described on its home page as Evented I/O for V8 Javascript, the high-performance Javascript engine in the Google Chrome browser.

Node.js is a binding for V8 that runs on Mac, Linux, Solaris, or with a bit of effort Windows. You would typically use it for real-time server applications that need to support many concurrent users. Dahl actually coded a chat server during the session, though our attempts to connect were defeated by the firewall.

In an aside, Dahl calls HTTP "the worst protocol on earth". He adds that we are now stuck with HTTP/1.1 for ever. Node.js uses Transfer-Encoding chunked to overcome some of its limitations.

Another of his points is that we are too much tied to web servers. "There's all these weird concepts in web stacks, why not just speak HTTP to things?"

Node.js has great performance, but it is low-level and further wrappers and libaries are appearing to make it more productive to use. What might it become in future? After the talk had ended, Dahl took some further questions and admitted that he would love to see it become the next PHP.

A great session; and whether or not you agree with all Dahl's remarks they are a welcome reminder that despite all the effort that has gone into the computing platforms we use constantly, there are things that could be done much better.

Node.js is in effect public domain software, says Dahl. It is not fully done yet, but in 6 months or so the API will be stable. Well worth a look. So, for that matter, is Nginx.

2 Comments

Maxence said:

Off-topic, but you can add MongoDB the new MySQL.

Rob said:

Node.js is certainly worth a serious look and I'd welcome its uptake as "the new PHP" in the sense that it should be expected to just "be there" in Linux distributions and hosted servers. Node.js is allowing me to now design and create things with ease that previously would have been either hugely difficult or impossible - hats off to Ryan Dhal! It is truly ground-breaking innovative stuff. Every serious IT professional should be checking it out.


Leave a comment

Current Vacancies from CWJobs

(* Required field)










Preferred format