Recently I was talking to a software engineer and slowly we ventured into the topic of JSP. For those who don’t know what JSP is, it stands for Java Server Pages(JSP) a technology built in 1990s. Anyway, I am one of those developers who develop html pages using JSP.
He asked “why are you still using Old JSP pages? Who does it anyway?”
My response was “I want my pages to be as fast as possible, if not fastest. So I am using JSPs”
He said “There is no way JSP can be faster than Node. Otherwise why would people move to Node?”
Well, there is only one way to find out. :)
Let’s get into the test details,
Hardware
Asus Zenbook Pro Laptop with Intel i7 processor with 16GB of RAM. CPU has 8 cores.
Software
Ubuntu 16.04, Tomcat8+Java8 and NodeJS 7.5.0+PM2 module.
Code
For JSP I didn’t write any code. Downloaded the sample WAR file from https://tomcat.apache.org/tomcat-7.0-doc/appdev/sample/ and copied into the webapps folder of Tomcat.
For node, copied the index.js file from https://blog.risingstack.com/your-first-node-js-http-server/.
Setup
Since nodeJs is single threaded, I used “pm2” module to run 8 node-js processes to fully utilize all the cores.
Just to be fair to the old tomcat, I added the “NIO” configuration, so that the connectors are non-blocking.
Test
Test was performed by “Apache bench-marking” tool “ab”. The easiest tool to make a lot of requests on a http server. The goal is to make 500K requests using 100 concurrent connections. The commands are below,
Tomcat
ab -n 500000 -c 100 http://localhost:8080/sample/hello
Node
ab -n 500000 -c 100 http://localhost:3000/
Alright, lets get to the results!!
Speed
I did 5 runs of 500K requests on Tomcat and NodeJs.
8 Nodejs processes with PM2 cluster took 32 seconds to serve 500K requests.
1 NodeJs process took 28 seconds to serve 500K requests. (No pm2)
Tomcat took 20 seconds to serve 500K requests.
Verdict: NodeJs is about 50% slower than Tomcat.
Full results are available in Google Doc
8 NodeJs processes run with PM2 cluster module
Single NodeJs process without PM2 cluster module
Tomcat8 with “nio” connector and 200 threads running on JDK8
CPU Usage
This was a quick test, so I didn’t take elaborate CPU measurements. I just ran “htop” and watched the CPU usage going up and down. It is fun to watch htop. I recorded one of the runs from Node and Tomcat for your viewing pleasure, they are less than a minute, so enjoy!
Screencast of 8-nodejs processes with pm2 cluster.
Screencast of single NodeJs process
Tomcat with “nio” connector and 200 threads running on JDK8
If you watched both videos, you would have noticed that when NodeJs is tested the cores are utilized around 70%.
On the other hand, when tomcat is tested the cores are utilized around 45%.
Verdict: NodeJS consumes 50% more CPU
If you are a NodeJs developer, please don’t take this seriously and quit your job. This is purely for fun. However the results are true.
Please let me know what you think. Your comments are welcome!
Update
I have added the results for 1 nodejs process without clustering.
Thanks Ramesh for helping with NodeJs.
Thanks Vigneshkumar Chinnachamy for the suggestion, I have added the results for 1 nodejs process as well.