Let’s compare NodeJS with one of the most popular and widely tested PHP since I’ve been working on them for the last couple of years!
Performance wise?
Let’s begin with simple HTTP requests that can be handled per second. The good guys at Hosting Advice | 2017 Reviews, Tips, How-To's | Web Experts ran a series of tests[1]. So if you are looking for a server that can handle a lot of concurrent HTTP calls (given that the task to be performed in each HTTP request is a trivial one), basic configured NodeJS outperforms even highly optimized PHP by 17%.
When would you need such a server? One without a lot of CPU intensive work?
- Distributing load where HTTP requests are routed to various microservices to perform small tasks.
- Performing trivial tasks (such as fetching from disk) for a large number of concurrent users
That said, I’d like to clarify one important detail. The performance of a simple “hello world” serving of HTTP request in PHP is heavily tied to Apache and how PHP works. This is how PHP handles a HTTP request:
- (Apache/nginx etc) Server receives the request, dispatches it to a PHP process (through forking or by using an idle PHP process)
- The PHP code is loaded into memory, the PHP script is run. This may involve framework initialisation, configuration setup, connections setup etc (Yes, the same startup script is run for EVERY request)
- The HTTP request is processed served back to the server.
- Server delivers the response to the client.
- The PHP process is then terminated.
Compared with NodeJS :
- The HTTP request is received by the server (optional since NodeJS can run on it’s own server)
- Since NodeJS is a long running task, there’s no startup code that run on every initialisation and the the request is processed immediately.
- The server (if there is one) then receives the response and delivers it to the client.
Seeing this, it’s easy to see why PHP is actually designed, in a way, to fail the basic “hello world” HTTP request benchmark.
I/O performance
If you want to build an application that is I/O intensive, PHP will stick out as a sore thumb because PHP waits for your I/O. This means that while your PHP script establishes connection with your DB or FS or an HTTP API, that threads is blocked from further computation. This is why although PHP isn’t the bottleneck in I/O bound jobs, it’s very nature makes the whole process slow.
NodeJS on the other hand, will not wait for your I/O bound task to be over. It’ll just dispatch it to the event loop and keep working. Once the I/O bound task is over, the callback for that task takes over.
At Visit[2], one of our microservices is a Jobs Scheduler that routinely runs various tasks such as backups, engagement activities, logging etc. It involves a lot of HTTP calls per user to various servers (think DB, analytics microservice, engagement microservice etc). If, say, you have 10 HTTP/DB connection requests calls per user and have, say, over 100k users that’s 1 million Async tasks calls! And we’d want to do this every few hours.
The above case on PHP would work horrendously. Because even if each Async tasks call takes 0.1 sec, that’s = 0.1*1*10^6 = 27.7 hours! Also remember, that PHP WILL NOT DO ANYTHING while an async job is being done. It’s blocked. It Stopped. It can’t do anything else.
On Node, even with some kind of throttling and rate limiting, it’ll take less than 5 mins.
Resources
To those who say, that this is only valid for one thread, you guys are not wrong. But again understand I’m comparing one nodeJS script with one PHP script. You can run multiple scripts to in NodeJS and that’ll blow PHP out of the park too. If you say that Apache can open up new threads of PHP for every task so that total time would be much less than 27+hours, so can nginx or apache for NodeJS. Also in that case, PHP would take up much MUCH MUCH more RAM and CPU. Not to mention it will block I/O that’ll be tied up for other PHP threads.
Ease of Writing Code
I think it would boil down to what were you exposed in the past. If you have worked with asynchronous methods NodeJS would feel very different. Experience with some multi-threading would come is handy too! However PHP just seems easier and more natural because of the strictly sequential way that it works. In PHP, Line 3 gets executed after line 2 (even though line 2 has an outbound I/O task) returns. Whereas in Node, that’s not the case. PHP would seem easier to work if you don’t understand async nature of tasks.
37 Comments
IT's very informative blog and useful article thank you for sharing with us.
ReplyDeleteNode JS Training
Node JS Online Training
It's a wonderful post and very helpful, thanks for all this information.
ReplyDeleteFull Stack Online Training
Check out this article and find about companies that use node.js.
ReplyDeleteCheck out a handy list of famous companies that use node.js in production .
ReplyDeleteThank you for sharing this useful blog on Node.js. You have provided very important information on this blog. Eternal Web provides Mobile or Web Applications as well as Module Development Services. Our Developers will deliver you outstanding Node.js Development Services. Kindly contact us on.
ReplyDeleteEnjoyed reading the article above, really explains everything in detail, the article is very interesting and effective. Thank you and good luck for the upcoming articles learn Node JS training
ReplyDeleteNice blog Thank you very much for the information you shared.
ReplyDeleteweb development company in bangalore
web design company in bangalore
Thanks for the post , This is such an informative post . If you are looking for the Nodejs development company . So here is the list of Top 10 Node.js Development Companies . Thanks for the post.
ReplyDelete
ReplyDeleteNice information.Keep on sharing
Full Stack online Training
Full Stack Training
Full Stack Developer Online Training
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Full Stack Training Institute
This comment has been removed by the author.
ReplyDeleteThank you for sharing and its was very usefully to me
ReplyDeleteReactJs Training in Hyderabad
ReactJs Online Training in Hyderabad
Very good explanation sir. Thank you for sharing
ReplyDeleteNodeJs Online Training
NodeJs Training in Hyderabad
NodeJs Training in Ameerpet
Best NodeJs Training in Hyderabad
This comment has been removed by a blog administrator.
ReplyDeleteThank you for sharing very useful information.
ReplyDeleteMean stack online training
Mean stack training in hyderabad
ExpressTech Software Solutions is a nodejs Development Company, where we provide the leading Node JS web development services to our clients across the globe. Contact us: +91-9806724185 or Contact@expresstechsoftwares.com
ReplyDelete
ReplyDeleteThanks for sharing this useful information with us.
Full Stack Training in Hyderabad
Full Stack Training in Ameerpet
Best article, very useful and explanation. Your post is extremely incredible. Thank you very much for the new information.
ReplyDeleteNode Js course with placement in Hyderabad
Node Js course in Hyderabad with placement
Node Js Training Center in Hyderabad
It’s a awesome blog you shared here, Thanks for sharing
ReplyDeleteNode JS Online training
Node JS training in Hyderabad
ReplyDeleteThank you for sharing this information and Very good looking blog
Mean stack online training
Mean stack training in hyderabad
Thanks a lot for this tutorial, great tutorial for beginners
ReplyDeleteAngular JS Online training
Angular JS training in hyderabad
Excellent Information and nice work that has been providing here. Keep on update more things.
ReplyDeleteMean stack online training
Mean stack training in hyderabad
Nice and good article. It is very useful for me to learn and understand easily.
ReplyDeleteFull Stack Training in Delhi
Full Stack Training institute in Delhi
There is a high demand for this advanced JS framework among web developers. It lets them develop robust websites and applications for different verticals. And these are the reasons which push business to hire node js web development companies out of leading node js development companies available in the global market for your website requirements.
ReplyDeleteThank you for sharing this informative post. Looking forward to read more.
ReplyDeleteProfessional Website Development Services
This comment has been removed by the author.
ReplyDeleteThank you for this blog! Thanks for sharing Information on Nodejs. I really Thanks to share the blog for such an beautiful Information.
ReplyDeleteNodejs Online Training
Nice blog! I read your blog. I really like all the points you mentioned are interesting and useful. Thanks for sharing this blog.
ReplyDeleteNode Js Training Institute in Noida
Informative article, just what I was looking for. Read more about mean stack training in chennai from our website.
ReplyDeleteGreat Post, Thanks for sharing such a wonderful blog.
ReplyDeleteReact JS Online Training
React JS Online Course
React JS Online Training in chennai
This comment has been removed by the author.
ReplyDeleteI like your blog.
ReplyDeleteThanks for sharing this Information. Mean Stack Training in Gurgaon
ReplyDeleteAmazing post
ReplyDeleteThanks For sharing
VBA MACRO Training in Delhi
Python institute in Delhi NCR
AI Training course in delhi
Data Science institute in delhi
Machine learning institute in delhi
Data analytics Training in delhi
GMP
SASVBA
For more information
ReplyDeleteWow such an amazing content keep it up. I have bookmarked your page to check out more informative content here.
SASVBA Delhi provides extensive MERN STACK COURSE IN DELHI The extensive hands-on session, hosted by the MERN Stack Training Institute in Delhi, includes live projects and simulations.
FOR MORE INFO:
Wow such an amazing content keep it up. I have bookmarked your page to check out more informative content here.
ReplyDeleteSASVBA Provides Best Deep Learning Course in Delhi with Latest Development Environment and Frameworks. We keep Our Courses Up to Date with the Latest industrial trends. SASVBA Is One of the best training Deep Learning Institute in Delhi NCR Which Helps Students to Crack Interviews in Tech Giants. We train college students as well as school students.
FOR MORE IMFO:
Thanks for the Valuable information.Really useful information. Thank you so much for sharing. It will help everyone.
ReplyDeletePower BI Institute in Delhi
FOR MORE INFO
It is amazing and wonderful to visit your site. Thanks for sharing information; this is useful to us....
ReplyDeleteVBA Macro Training In Delhi
FOR MORE INFO: