SlideShare a Scribd company logo
1 of 9
Yet another Node Vs PHP+Apache
When they said Node JS , they said about performance. They said about concurrency.
They said about non-blocking I/O. I thought of giving a try to visualizing that in
comparing with other languages and see if Node is really better in some way.
I will try here to explore the 2 main features of Node that make it win in certain
scenarios.
1. Non-Blocking I/O: - In a typical application where we need to perform 3 tasks we
simple execute them this way
task1();
task2();
task3();
Now task3() will not be executed until task2() is completed and task2() may take long
time depending on its operation and so execution of task3() will be blocked. So in a
scenario where all these jobs / tasks are independent to each other and can run in
parallel, this sequential paradigm won't fit practically.
Node fits here perfectly. Node supports callbacks, that means calls are asynchronous
and non-blocking. The task2() will not block task3() or in other words "a statement in
Node will never wait for another I/O to be finished."
I created a similar scenario in Node
var http = require('http');
var resp = function doResp()
{
console.log("Second task executed..");
}
http.createServer(function (req, res) {
console.log("Task One exeuted.."); // This is task 1
setTimeout(resp,2000); //This is actually how callback is utilized
/* Below statements are task3*//
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Page content is loaded but request is yet processing task 2 in back ground...");
console.log("Task three executed..");
}).listen(9999);
The above simple node code has main 3 tasks to do as we planned.
Task one will print a message on console.
Task two is a Time consuming task takes 2 seconds and at the end it will display
message on console.
Task three writes the response to user and also displays a message on console.
This line " setTimeout(resp,2000);" is where actually callback is used. So the actual
function is being passed as parameter to setTimeout function , that means after 2000
millisecond the function doResp() will be invoked. Which is stored in a variable resp. But
the beaut is the whole statement " setTimeout(resp,2000);" gets executed immediately
and next statements start getting executed. Though in parallel sets a timer to execute
the callback function after 2 seconds, it doesn't stop next tasks.
I started the app and hit from browser, and saw on Browser screen the message "
In console I could see the below 2 messages
"Task One exeuted.."
"Task three executed.."
and after 2 seconds I did see the another message came up "Second task executed.."
I am happy with the Non-Blocking I/O (or to me asynchronous) of Node.
2. Concurrency: I am done with verifying nonblocking IO feature. Now I have to see
and test concurrency and an overall load test. As suggested by others I used siege for
load test simulation.
Wrote a simple Node which reads from a Mysql table and emmits JSON. Wrote another
PHP file which does the same thing.
Here to make the response content length similar , I purposefully avoided Chunked
transfer Encoding in PHP+Apache.
The table has around 53 records. I did test with few different parameters.
Complete code and database structure is available on Git link provided at the end.
Below are my complete test results. The upper ones are Node and Below are PHP
500 Concurrent users for 5 Minutes with 1 second delay
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t5M -
lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 296509 hits
Availability: 100.00 %
Elapsed time: 299.75 secs
Data transferred: 830.79 MB
Response time: 0.00 secs
Transaction rate: 989.19 trans/sec
Throughput: 2.77 MB/sec
Concurrency: 4.20
Successful transactions: 296509
Failed transactions: 0
Longest transaction: 0.20
Shortest transaction: 0.00
FILE: node1.log
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t5M -
lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 298656 hits
Availability: 100.00 %
Elapsed time: 299.92 secs
Data transferred: 836.80 MB
Response time: 0.00 secs
Transaction rate: 995.79 trans/sec
Throughput: 2.79 MB/sec
Concurrency: 2.27
Successful transactions: 298656
Failed transactions: 0
Longest transaction: 0.24
Shortest transaction: 0.00
FILE: nphp1.log
Summary : Not much difference. Concurrency is little higher and Longest transaction is
also slightly better but nothing real impressive.
500 Concurrent users for 10 minutes with 1 second delay
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M -
lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 594697 hits
Availability: 100.00 %
Elapsed time: 599.95 secs
Data transferred: 1666.28 MB
Response time: 0.00 secs
Transaction rate: 991.24 trans/sec
Throughput: 2.78 MB/sec
Concurrency: 3.84
Successful transactions: 594697
Failed transactions: 0
Longest transaction: 0.20
Shortest transaction: 0.00
FILE: node1.log
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M -
lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 597276 hits
Availability: 100.00 %
Elapsed time: 599.97 secs
Data transferred: 1673.50 MB
Response time: 0.00 secs
Transaction rate: 995.51 trans/sec
Throughput: 2.79 MB/sec
Concurrency: 1.94
Successful transactions: 597276
Failed transactions: 0
Longest transaction: 0.20
Shortest transaction: 0.00
FILE: nphp1.log
Summary: Node is still better at concurrency but yet nothing so impressive so far. I am
still in love with my PHP+Apache
500 Concurrent Users for 15 minutes with 1 second delay
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M -
lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 892874 hits
Availability: 100.00 %
Elapsed time: 899.25 secs
Data transferred: 2501.74 MB
Response time: 0.00 secs
Transaction rate: 992.91 trans/sec
Throughput: 2.78 MB/sec
Concurrency: 3.74
Successful transactions: 892874
Failed transactions: 0
Longest transaction: 0.25
Shortest transaction: 0.00
FILE: node1.log
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M -
lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 500 concurrent users for battle.
The server is now under siege...
[error] socket: 1011885824 address is unavailable.: Cannot assign requested address
[error] socket: -213448960 address is unavailable.: Cannot assign requested address
[error] socket: -3631360 address is unavailable.: Cannot assign requested address
Lifting the server siege... done.
Transactions: 893948 hits
Availability: 99.96 %
Elapsed time: 899.70 secs
Data transferred: 2504.75 MB
Response time: 0.00 secs
Transaction rate: 993.61 trans/sec
Throughput: 2.78 MB/sec
Concurrency: 2.25
Successful transactions: 893948
Failed transactions: 335
Longest transaction: 1.01
Shortest transaction: 0.00
FILE: nphp1.log
Summary: PHP breaks for these long running large number of concurrent
requests.Server stopped creating threads when it created enough before max outing
server's RAM. But node is standing straight here. Node looks even steady in terms of
the parameters.
1K Concurrent users for 10 minutes with 1 Second delay
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M
-lnode1.log http://localhost:9615
** SIEGE 3.0.5
** Preparing 1000 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 862079 hits
Availability: 100.00 %
Elapsed time: 599.92 secs
Data transferred: 2415.46 MB
Response time: 0.20 secs
Transaction rate: 1436.99 trans/sec
Throughput: 4.03 MB/sec
Concurrency: 281.62
Successful transactions: 862079
Failed transactions: 0
Longest transaction: 0.55
Shortest transaction: 0.00
FILE: node1.log
anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M
-lnphp1.log http://localhost/loadTest/PHP/
** SIEGE 3.0.5
** Preparing 1000 concurrent users for battle.
The server is now under siege...
Lifting the server siege... done.
Transactions: 1193412 hits
Availability: 100.00 %
Elapsed time: 599.82 secs
Data transferred: 3343.82 MB
Response time: 0.00 secs
Transaction rate: 1989.62 trans/sec
Throughput: 5.57 MB/sec
Concurrency: 5.58
Successful transactions: 1193412
Failed transactions: 0
Longest transaction: 0.54
Shortest transaction: 0.00
FILE: nphp1.log
Summary: This shows the real advantage of node in terms of concurrency. See here
with increase in number of concurrent users how the concurrency level increased for
Node(281.62) where as for PHP+Apache it is 5.58 still.
Conclusion: So I am convinced from the above test that Node is good at when high
very high concurrency is demanded. Also saw in first part that the nonblocking IO gives
Node an edge for event based application.
At the same time realized that until unless a real huge concurrency is required no need
for Node. The cost at-least at this moment will be higher for the below reason
1. Getting Node experienced people or training your developer to Pro level is
costlier
2. PHP+Apache stack will consume more swap memory (RAM) when
concurrency is more, but Node will be expensive on Processor (CPU) when
performing CPU intensive jobs. Scaling up a server is cheaper when only dealing
with memory or RAM (obviously within thresold) but if we need processor upgrade
(on physical servers) that will be real tough and expensive job.
3. If you are not owning dedicated server hosting Node on cloud is costlier
than any other options
Someone in some forum wrote " You no need to bother and think about the concurrency
of Node until you are managing sites like Google,Facebook or Amazon.
So it is upto Webmasters , depending on their load and traffic and also budget what
they want to use and implement.
GIT link for source codes and Database table
Complete discussion on Node JS forum during this whole test
*Please note:i used mysql_() functions for ease of writing instead of using pdo or
mysqli_() functions.

More Related Content

What's hot

Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with MicronautQAware GmbH
 
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...wallyqs
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with FlowdockFlowdock
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Tom Croucher
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولefazati
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problemJose Galarza
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative InfrastuctureMarc Seeger
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...Tom Croucher
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...Tom Croucher
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJSJITENDRA KUMAR PATEL
 
node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the futureJeff Miccolis
 
Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL John Anderson
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystemYukti Kaura
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.jsPrabin Silwal
 
Testing Wi-Fi with OSS Tools
Testing Wi-Fi with OSS ToolsTesting Wi-Fi with OSS Tools
Testing Wi-Fi with OSS ToolsAll Things Open
 
Solving some of the scalability problems at booking.com
Solving some of the scalability problems at booking.comSolving some of the scalability problems at booking.com
Solving some of the scalability problems at booking.comIvan Kruglov
 
Twisted: a quick introduction
Twisted: a quick introductionTwisted: a quick introduction
Twisted: a quick introductionRobert Coup
 
GopherFest 2017 - Adding Context to NATS
GopherFest 2017 -  Adding Context to NATSGopherFest 2017 -  Adding Context to NATS
GopherFest 2017 - Adding Context to NATSwallyqs
 

What's hot (20)

Microservices with Micronaut
Microservices with MicronautMicroservices with Micronaut
Microservices with Micronaut
 
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...GopherCon 2017 -  Writing Networking Clients in Go: The Design & Implementati...
GopherCon 2017 - Writing Networking Clients in Go: The Design & Implementati...
 
From LAMP to LNNP
From LAMP to LNNPFrom LAMP to LNNP
From LAMP to LNNP
 
Real-Time with Flowdock
Real-Time with FlowdockReal-Time with Flowdock
Real-Time with Flowdock
 
Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012 Streams are Awesome - (Node.js) TimesOpen Sep 2012
Streams are Awesome - (Node.js) TimesOpen Sep 2012
 
Nginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصولNginx وب سروری برای تمام فصول
Nginx وب سروری برای تمام فصول
 
Communication in Python and the C10k problem
Communication in Python and the C10k problemCommunication in Python and the C10k problem
Communication in Python and the C10k problem
 
About Node.js
About Node.jsAbout Node.js
About Node.js
 
Alternative Infrastucture
Alternative InfrastuctureAlternative Infrastucture
Alternative Infrastucture
 
A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...A language for the Internet: Why JavaScript and Node.js is right for Internet...
A language for the Internet: Why JavaScript and Node.js is right for Internet...
 
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
JavaScript is the new black - Why Node.js is going to rock your world - Web 2...
 
Introduction to node.js aka NodeJS
Introduction to node.js aka NodeJSIntroduction to node.js aka NodeJS
Introduction to node.js aka NodeJS
 
node.js, javascript and the future
node.js, javascript and the futurenode.js, javascript and the future
node.js, javascript and the future
 
Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL Automate Yo'self -- SeaGL
Automate Yo'self -- SeaGL
 
NodeJS ecosystem
NodeJS ecosystemNodeJS ecosystem
NodeJS ecosystem
 
A complete guide to Node.js
A complete guide to Node.jsA complete guide to Node.js
A complete guide to Node.js
 
Testing Wi-Fi with OSS Tools
Testing Wi-Fi with OSS ToolsTesting Wi-Fi with OSS Tools
Testing Wi-Fi with OSS Tools
 
Solving some of the scalability problems at booking.com
Solving some of the scalability problems at booking.comSolving some of the scalability problems at booking.com
Solving some of the scalability problems at booking.com
 
Twisted: a quick introduction
Twisted: a quick introductionTwisted: a quick introduction
Twisted: a quick introduction
 
GopherFest 2017 - Adding Context to NATS
GopherFest 2017 -  Adding Context to NATSGopherFest 2017 -  Adding Context to NATS
GopherFest 2017 - Adding Context to NATS
 

Similar to Yet another node vs php

Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsPerrin Harkins
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2Merixstudio
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceScyllaDB
 
Writing Networking Clients in Go - GopherCon 2017 talk
Writing Networking Clients in Go - GopherCon 2017 talkWriting Networking Clients in Go - GopherCon 2017 talk
Writing Networking Clients in Go - GopherCon 2017 talkNATS
 
Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterEugene Kirpichov
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26Max Kleiner
 
Real timeninja - Codemotion 2015 Roma
Real timeninja - Codemotion 2015 RomaReal timeninja - Codemotion 2015 Roma
Real timeninja - Codemotion 2015 RomaMeanMilan
 
Multi-core Node.pdf
Multi-core Node.pdfMulti-core Node.pdf
Multi-core Node.pdfAhmed Hassan
 
TLS - 2016 Velocity Training
TLS - 2016 Velocity TrainingTLS - 2016 Velocity Training
TLS - 2016 Velocity TrainingPatrick Meenan
 
Pipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdfPipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdfarasanlethers
 
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...Writing Serverless Application in Java with comparison of 3 approaches: AWS S...
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...Andrew Zakordonets
 
Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)Eran Harel
 
Pipe your script to slack
Pipe your script to slackPipe your script to slack
Pipe your script to slackChikashi Kato
 
Parrot Drones Hijacking
Parrot Drones HijackingParrot Drones Hijacking
Parrot Drones HijackingPriyanka Aash
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @JavaPeter Lawrey
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus44CON
 
Артем Оробец «На пути к low-latency»
Артем Оробец «На пути к low-latency»Артем Оробец «На пути к low-latency»
Артем Оробец «На пути к low-latency»DataArt
 
Production debugging web applications
Production debugging web applicationsProduction debugging web applications
Production debugging web applicationsIdo Flatow
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010Ilya Grigorik
 
maXbox Starter 42 Multiprocessing Programming
maXbox Starter 42 Multiprocessing Programming maXbox Starter 42 Multiprocessing Programming
maXbox Starter 42 Multiprocessing Programming Max Kleiner
 

Similar to Yet another node vs php (20)

Introduction to performance tuning perl web applications
Introduction to performance tuning perl web applicationsIntroduction to performance tuning perl web applications
Introduction to performance tuning perl web applications
 
Why we choose Symfony2
Why we choose Symfony2Why we choose Symfony2
Why we choose Symfony2
 
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 InstanceExtreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
Extreme HTTP Performance Tuning: 1.2M API req/s on a 4 vCPU EC2 Instance
 
Writing Networking Clients in Go - GopherCon 2017 talk
Writing Networking Clients in Go - GopherCon 2017 talkWriting Networking Clients in Go - GopherCon 2017 talk
Writing Networking Clients in Go - GopherCon 2017 talk
 
Lessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core clusterLessons learnt on a 2000-core cluster
Lessons learnt on a 2000-core cluster
 
TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26TCP Sockets Tutor maXbox starter26
TCP Sockets Tutor maXbox starter26
 
Real timeninja - Codemotion 2015 Roma
Real timeninja - Codemotion 2015 RomaReal timeninja - Codemotion 2015 Roma
Real timeninja - Codemotion 2015 Roma
 
Multi-core Node.pdf
Multi-core Node.pdfMulti-core Node.pdf
Multi-core Node.pdf
 
TLS - 2016 Velocity Training
TLS - 2016 Velocity TrainingTLS - 2016 Velocity Training
TLS - 2016 Velocity Training
 
Pipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdfPipelining understandingPipelining is running multiple stages of .pdf
Pipelining understandingPipelining is running multiple stages of .pdf
 
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...Writing Serverless Application in Java with comparison of 3 approaches: AWS S...
Writing Serverless Application in Java with comparison of 3 approaches: AWS S...
 
Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)Service discovery like a pro (presented at reversimX)
Service discovery like a pro (presented at reversimX)
 
Pipe your script to slack
Pipe your script to slackPipe your script to slack
Pipe your script to slack
 
Parrot Drones Hijacking
Parrot Drones HijackingParrot Drones Hijacking
Parrot Drones Hijacking
 
Open HFT libraries in @Java
Open HFT libraries in @JavaOpen HFT libraries in @Java
Open HFT libraries in @Java
 
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus44CON 2014 - Switches Get Stitches,  Eireann Leverett & Matt Erasmus
44CON 2014 - Switches Get Stitches, Eireann Leverett & Matt Erasmus
 
Артем Оробец «На пути к low-latency»
Артем Оробец «На пути к low-latency»Артем Оробец «На пути к low-latency»
Артем Оробец «На пути к low-latency»
 
Production debugging web applications
Production debugging web applicationsProduction debugging web applications
Production debugging web applications
 
No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010No Callbacks, No Threads - RailsConf 2010
No Callbacks, No Threads - RailsConf 2010
 
maXbox Starter 42 Multiprocessing Programming
maXbox Starter 42 Multiprocessing Programming maXbox Starter 42 Multiprocessing Programming
maXbox Starter 42 Multiprocessing Programming
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 

Yet another node vs php

  • 1. Yet another Node Vs PHP+Apache When they said Node JS , they said about performance. They said about concurrency. They said about non-blocking I/O. I thought of giving a try to visualizing that in comparing with other languages and see if Node is really better in some way. I will try here to explore the 2 main features of Node that make it win in certain scenarios. 1. Non-Blocking I/O: - In a typical application where we need to perform 3 tasks we simple execute them this way task1(); task2(); task3(); Now task3() will not be executed until task2() is completed and task2() may take long time depending on its operation and so execution of task3() will be blocked. So in a scenario where all these jobs / tasks are independent to each other and can run in parallel, this sequential paradigm won't fit practically. Node fits here perfectly. Node supports callbacks, that means calls are asynchronous and non-blocking. The task2() will not block task3() or in other words "a statement in Node will never wait for another I/O to be finished." I created a similar scenario in Node
  • 2. var http = require('http'); var resp = function doResp() { console.log("Second task executed.."); } http.createServer(function (req, res) { console.log("Task One exeuted.."); // This is task 1 setTimeout(resp,2000); //This is actually how callback is utilized /* Below statements are task3*// res.writeHead(200, {'Content-Type': 'text/plain'}); res.end("Page content is loaded but request is yet processing task 2 in back ground..."); console.log("Task three executed.."); }).listen(9999); The above simple node code has main 3 tasks to do as we planned. Task one will print a message on console. Task two is a Time consuming task takes 2 seconds and at the end it will display message on console. Task three writes the response to user and also displays a message on console. This line " setTimeout(resp,2000);" is where actually callback is used. So the actual function is being passed as parameter to setTimeout function , that means after 2000 millisecond the function doResp() will be invoked. Which is stored in a variable resp. But the beaut is the whole statement " setTimeout(resp,2000);" gets executed immediately and next statements start getting executed. Though in parallel sets a timer to execute the callback function after 2 seconds, it doesn't stop next tasks. I started the app and hit from browser, and saw on Browser screen the message " In console I could see the below 2 messages
  • 3. "Task One exeuted.." "Task three executed.." and after 2 seconds I did see the another message came up "Second task executed.." I am happy with the Non-Blocking I/O (or to me asynchronous) of Node. 2. Concurrency: I am done with verifying nonblocking IO feature. Now I have to see and test concurrency and an overall load test. As suggested by others I used siege for load test simulation. Wrote a simple Node which reads from a Mysql table and emmits JSON. Wrote another PHP file which does the same thing. Here to make the response content length similar , I purposefully avoided Chunked transfer Encoding in PHP+Apache. The table has around 53 records. I did test with few different parameters. Complete code and database structure is available on Git link provided at the end. Below are my complete test results. The upper ones are Node and Below are PHP 500 Concurrent users for 5 Minutes with 1 second delay anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t5M - lnode1.log http://localhost:9615 ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 296509 hits Availability: 100.00 % Elapsed time: 299.75 secs Data transferred: 830.79 MB Response time: 0.00 secs Transaction rate: 989.19 trans/sec
  • 4. Throughput: 2.77 MB/sec Concurrency: 4.20 Successful transactions: 296509 Failed transactions: 0 Longest transaction: 0.20 Shortest transaction: 0.00 FILE: node1.log anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t5M - lnphp1.log http://localhost/loadTest/PHP/ ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 298656 hits Availability: 100.00 % Elapsed time: 299.92 secs Data transferred: 836.80 MB Response time: 0.00 secs Transaction rate: 995.79 trans/sec Throughput: 2.79 MB/sec Concurrency: 2.27 Successful transactions: 298656 Failed transactions: 0 Longest transaction: 0.24 Shortest transaction: 0.00 FILE: nphp1.log Summary : Not much difference. Concurrency is little higher and Longest transaction is also slightly better but nothing real impressive. 500 Concurrent users for 10 minutes with 1 second delay
  • 5. anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M - lnode1.log http://localhost:9615 ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 594697 hits Availability: 100.00 % Elapsed time: 599.95 secs Data transferred: 1666.28 MB Response time: 0.00 secs Transaction rate: 991.24 trans/sec Throughput: 2.78 MB/sec Concurrency: 3.84 Successful transactions: 594697 Failed transactions: 0 Longest transaction: 0.20 Shortest transaction: 0.00 FILE: node1.log anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t10M - lnphp1.log http://localhost/loadTest/PHP/ ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 597276 hits Availability: 100.00 % Elapsed time: 599.97 secs Data transferred: 1673.50 MB Response time: 0.00 secs Transaction rate: 995.51 trans/sec Throughput: 2.79 MB/sec
  • 6. Concurrency: 1.94 Successful transactions: 597276 Failed transactions: 0 Longest transaction: 0.20 Shortest transaction: 0.00 FILE: nphp1.log Summary: Node is still better at concurrency but yet nothing so impressive so far. I am still in love with my PHP+Apache 500 Concurrent Users for 15 minutes with 1 second delay anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M - lnode1.log http://localhost:9615 ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 892874 hits Availability: 100.00 % Elapsed time: 899.25 secs Data transferred: 2501.74 MB Response time: 0.00 secs Transaction rate: 992.91 trans/sec Throughput: 2.78 MB/sec Concurrency: 3.74 Successful transactions: 892874 Failed transactions: 0 Longest transaction: 0.25 Shortest transaction: 0.00 FILE: node1.log anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c500 -d1 -t15M -
  • 7. lnphp1.log http://localhost/loadTest/PHP/ ** SIEGE 3.0.5 ** Preparing 500 concurrent users for battle. The server is now under siege... [error] socket: 1011885824 address is unavailable.: Cannot assign requested address [error] socket: -213448960 address is unavailable.: Cannot assign requested address [error] socket: -3631360 address is unavailable.: Cannot assign requested address Lifting the server siege... done. Transactions: 893948 hits Availability: 99.96 % Elapsed time: 899.70 secs Data transferred: 2504.75 MB Response time: 0.00 secs Transaction rate: 993.61 trans/sec Throughput: 2.78 MB/sec Concurrency: 2.25 Successful transactions: 893948 Failed transactions: 335 Longest transaction: 1.01 Shortest transaction: 0.00 FILE: nphp1.log Summary: PHP breaks for these long running large number of concurrent requests.Server stopped creating threads when it created enough before max outing server's RAM. But node is standing straight here. Node looks even steady in terms of the parameters. 1K Concurrent users for 10 minutes with 1 Second delay anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M -lnode1.log http://localhost:9615 ** SIEGE 3.0.5 ** Preparing 1000 concurrent users for battle.
  • 8. The server is now under siege... Lifting the server siege... done. Transactions: 862079 hits Availability: 100.00 % Elapsed time: 599.92 secs Data transferred: 2415.46 MB Response time: 0.20 secs Transaction rate: 1436.99 trans/sec Throughput: 4.03 MB/sec Concurrency: 281.62 Successful transactions: 862079 Failed transactions: 0 Longest transaction: 0.55 Shortest transaction: 0.00 FILE: node1.log anirbanb2004@Anisoft-Corporation:~/www/loadTest/siegeLog$ siege -c1000 -d1 -t10M -lnphp1.log http://localhost/loadTest/PHP/ ** SIEGE 3.0.5 ** Preparing 1000 concurrent users for battle. The server is now under siege... Lifting the server siege... done. Transactions: 1193412 hits Availability: 100.00 % Elapsed time: 599.82 secs Data transferred: 3343.82 MB Response time: 0.00 secs Transaction rate: 1989.62 trans/sec Throughput: 5.57 MB/sec Concurrency: 5.58 Successful transactions: 1193412 Failed transactions: 0
  • 9. Longest transaction: 0.54 Shortest transaction: 0.00 FILE: nphp1.log Summary: This shows the real advantage of node in terms of concurrency. See here with increase in number of concurrent users how the concurrency level increased for Node(281.62) where as for PHP+Apache it is 5.58 still. Conclusion: So I am convinced from the above test that Node is good at when high very high concurrency is demanded. Also saw in first part that the nonblocking IO gives Node an edge for event based application. At the same time realized that until unless a real huge concurrency is required no need for Node. The cost at-least at this moment will be higher for the below reason 1. Getting Node experienced people or training your developer to Pro level is costlier 2. PHP+Apache stack will consume more swap memory (RAM) when concurrency is more, but Node will be expensive on Processor (CPU) when performing CPU intensive jobs. Scaling up a server is cheaper when only dealing with memory or RAM (obviously within thresold) but if we need processor upgrade (on physical servers) that will be real tough and expensive job. 3. If you are not owning dedicated server hosting Node on cloud is costlier than any other options Someone in some forum wrote " You no need to bother and think about the concurrency of Node until you are managing sites like Google,Facebook or Amazon. So it is upto Webmasters , depending on their load and traffic and also budget what they want to use and implement. GIT link for source codes and Database table Complete discussion on Node JS forum during this whole test *Please note:i used mysql_() functions for ease of writing instead of using pdo or mysqli_() functions.