How efficient NodeJS compared to PHP?

Many benchmarks have shown that PHP is as fast as Node.JS. In fact many people mistake Node's async and single threaded design is a performance booster, but this notion is misconstrued. What Node really provides is a very practical and optimized solution for web development. 

Any Java or PHP framework with a good mutex implementation will beat Node.JS and sooner or later one will catch up(most likely that it would be Java not PHP maybe never PHP).

However even if any of these languages catch up will they really replace Node.JS, I don't think so, because developers who have understood Node.JS for what it is doesn't love it for performance but because of its really efficient program design that is highly functional for web development or server development of any kind.

While some benchmarks show that Node.JS is clearly faster like the one below

Change(b)log: Benchmarking Node.js - basic performance tests against Apache + PHP

Then there are other that show PHP is still quite fast

TechEmpower Web Framework Performance Comparison

And it all depends upon scenario

Where Node would be faster than PHP

1) If requests are I/O bound - Node's async is exactly designed for this purpose

2) If requests are CPU bound but still not very complicated - Node is still quite fast and V8 engine is very optimized to perform simple CPU bound operations

Where PHP would be faster than Node

1) Complex operations - PHP will beat Node squarely because even with V8 Node still have to deal with performance limitations of Javascript

2) handle business logic and render html at the same time - You cannot use Node to vomit HTML pages, that'll defeat the purpose of using Node. You'll definitely use some templating engines, employ separation of concern and build a lot of infra around your business logic to have a good solution in Node.

But a better question to ask before performance is Productivity. C, C++ and GO are very fast that PHP, Java and Node.js but will you use them to build your sites. Python and Ruby are damn slow but a lot of high traffic sites like Twitter, Reddit, Dropbox, Instagram use them.

And this how I'll rank frameworks when it comes to productivity

1) PHP - has awesome developer base and you can literally dish-out any kind of site in not time using Wordpress, Zend, Laravel, Joomla.

2) Ruby On Rails - what Rails lacks in performance it more than makes up for it with a die-hard developer base and precious Gems. And unlike PHP you don't have to deal with different frameworks like Wordpress to be extra productive, you can literally write away anything in no-time using Rails and that is why it has such high adoption, because developers who like to crank code than copy paste love Rails.

3) Python - highly productive language and enough said. People gravitate towards Python for one simple reason PYTHON. Like Ruby, developers who like to crank code loves Python, but unlike Ruby, Python has one more reason why it has such wide spread adoption, it is multi-paradigm and slowly becoming the first language for the next generation of developers. Yes kids these day learn Python before the learn they learn C.

Also many experimental projects are done on Python and when these projects mature and becomes viable enough to be launched as a website, developers stick to the language. That is how many popular sites like Reddit, Quora which employs Analytics and learning algorithmd ended up using Python.

4) Node.JS - technically Node.js is superior for web development than Python. It has an excellent package manager and gives you access to thousands of libraries that have ready made solutions for 90% of requirements of an average website. But Python will beat it squarely when it comes to raw productivity. Also Python has mature testing frameworks than Node, it can be wielded for scripting, integration middlewares, glueing services and comes with an all round package.

5) Java - Java is still very fast and has a very mature ecosystem. And Java developers are as productive as Node developers. However when it comes to productivity Python & Rails(not Ruby) are still superior choices. You cannot compare PHP, it is in completely different league.

Wrong Choices

1) Go - with Google's marketing and the buzz around Internet of Things a lot of people are eyeing on Go. But IMHO it is a wrong choice for web development. Go from a practical perspective would be very useful in very specific cases where performance is mission critical and you need a flexible language to do it. Go supports concurrent, asynchronous/synchronous, single threaded and multi threaded programming models, and its very fast and clean.

But developing a website with Go would be like developing it with an upgraded version of C.

2) ASP - I'm going to get a lot of trolling for mentioning this, but before trolling please try Rails or Python and you'll get the picture. ASP was Microsoft's stupid answer for PHP & JSP and even after all these years PHP will squarely beat it. Neither it has the style and flair of Rails nor it is as productive and flexible as Pythonic frameworks.

3) Scala/Erlang/Clojure/Dart - all these languages have dedicated fan base but when compared with the above choices they are very bad options. For web development, Node provides a more practical concurrent model, Ruby and Javascript provides a more practical functional programming language and Python gives crazy productivity.


Getting developers onboard is a big factor for successful websites and the above languages will fall flat.

#node-js #php

4 Likes3.50 GEEK