An example of how Node.js is faster than PHP

I wanted to see what all the Node.js hype was about so I decided to run some head to head load tests using Ghost (Node.js) and WordPress (php). The results were incredible with Ghost soundly trouncing WordPress. It was like watching a starship racing an airplane (well, what I imagine that would be like anyway).

The Setup

To provide a little background, Ghost is just a blogging platform and nothing more while WordPress is a full up CMS. I wanted to make this comparison as fair as possible so I limited my load testing scripts to executing against only the blog pages. I also wanted to test the “out of the box” experience so I did not make configuration changes to either platform (besides hooking them both up to MySQL). I spun up a single 64-bit RHEL m1.large (reference server sizing image below for specs) instance on Amazon EC2 to host both blogging platforms.

I wanted to test the most common configurations so I used NginX to front end Ghost and used Apache to front end WordPress. Both platforms shared the same local MySQL backend database instance (Ghost comes with SQLite by default but I wanted to make sure I provided a level playing field on the back end).

I had both Ghost (listening on port 80) and WordPress (listening on port 8080) running at the same time but only applied load to one blogging platform at any given time.

That brings me to the load generation portion of this little experiment. I spun up another EC2 instance (64-bit ubuntu, size m1.medium – reference server sizing image above for specs) in the same availability zone in an attempt to minimize network impact on test results. I asked my colleague @dustinwhittle to recommend a load test configuration and he referred me to his blog post about load test tools and recommended I used a combination of Siege and Sproxy.

After I had the blogging platforms installed and tested as working I added an 8 part blog series in plain text (no images) to each site and removed any pre-existing blogs. In WordPress I left the standard URL pattern in place and did NOT implement permalinks so that I would not slow things down by using that feature. I also did not turn on any caching technology for WordPress as I was trying to measure the out of the box experience. Basically I didn’t attempt any sort of tuning at all on either platform.

I ran Sproxy against both Ghost and WordPress and ended up with my list of URLs. I modified each of these files to include the exact same list of blog posts so that the load tests would be as similar as possible. You can see the contents of each file below.

So now I was ready to fire up Siege and start hitting each blog with load. Siege is a nice tool that allows you to manipulate some key parameters. The ones I played with the most were the number of concurrent connections (-c) and the delay (-d in seconds) between batches of requests. Here is the command for your reference… siege -v -c 100 -i -t 10M -f urls.txt -d 1

The Results

In a word, staggering! I ran siege for 10 minutes with 100 concurrent connections and a 1 second delay between batches of web requests. The results are shown below…

Siege load test results for Ghost with Nginx under heavy load.

Siege load test results for WordPress and Apache under heavy load.

As you can see from the output shown above, Ghost with Nginx outperformed WordPress with Apache by about 678% when looking at total transactional throughput over a 10 minute test. Impressively, the longest transaction response time for Ghost was 2.62 seconds compared the an abysmal 33.41 seconds for WordPress. I repeated these test runs multiple times and got very similar results so I am not going to show the rest of the test results since they are redundant. My goal here was not to run an exhaustive analysis of performance at varying loads but instead to create a substantial load and to see how each platform handled it.

Some other interesting data points to note. During the load test, Ghost ran with only 1 process and Nginx had a total of 2 processes. WordPress and Apache on the other hand spawned a total of ~110 httpd processes which makes sense since Siege was throwing 100 concurrent connections at it. The interesting part is in the CPU data during the load tests. I have plotted Average, Min, and Max CPU utilization on the charts below. You can clearly see that Ghost CPU consumption was about 40% while WordPress consumption was about 70%.

Now don’t think that I have forgot about normal loading patterns. How do things look with a moderate load as compared to the super high load that I placed on these platforms with the 100 concurrent connections test? To find out I dropped the number of concurrent connections to 10 and set the delay between batches of connections to 5 seconds. The results are shown below and are still incredibly impressive for Ghost. WordPress was outperformed in every way possible. Ghost had higher throughput and most importantly the slowest transaction response time was .18 seconds compared to 2.72 seconds for WordPress. From a CPU perspective Ghost only consumed ~4% on average during this test while WordPress consumed ~30% on average.

Siege load test results for Ghost with Nginx under light load.

Siege load test results for WordPress with Apache under light load.

Update on 10/18/2013 – It’s not fair!!! Apples and Oranges!!!

There have been some who say I’m comparing apples to oranges. To this I say, you’re damn right! In this post I set out to compare the common combinations of Nginx + Ghost and Apache + WordPress. I set out to compare these in their most basic forms, no tuning, no caching, just what you get out of the box. But I understand the outcry and I decided to level the playing field. Some people thought that Apache was a bottleneck so I decided to use Apache as the front end web server for Ghost and to re-run my load tests. I ran multiple tests again but they were all very consistent so I am only going to show the output from one of them (shown below).

The results shown above are interesting. Apache + Ghost was actually slightly FASTER than running Ghost with Nginx. Ghost is still super fast regardless of using Apache or Nginx as the web server.

The Conclusion

Ghost is way faster and can handle way more load than WordPress while also consuming much less CPU resource (Ghost also has considerably less functionality than WordPress but that’s not relevant for the purpose of this test). It would be interesting to run Ghost in a 2 process Node.js cluster and see what difference it makes in throughput and CPU utilization. Hmmmm, that sounds like a really good subject for another blog post…

Another interesting topic that I didn’t cover here is monitoring for both of these platforms. In my mind it’s not enough to just observe the behavior of these platforms from the outside. I want to see what’s going on from the inside. In a future blog post I am going to monitor Ghost with Nodetime and will monitor WordPress with AppDynamics. I can’t wait to see how they both look from the inside!

Appendix

Here are the links to the information I used to build out my blogging and testing platforms (I used the relevant portions of each article since my configuration was different than what was in each article alone):

About Author

Jim Hirschauer is a Technology Evangelist for AppDynamics. He has an extensive background working in highly available, business critical, large enterprise IT operations environments. Jim has been interested in application performance testing and monitoring since he was a Systems Administrator working in a retail bank. His passion for performance analysis led him down a path where he would design, implement and manage the cloud computing monitoring architecture for a top 10 investment bank. During his tenure at the investment bank, Jim created new processes and procedures that increased overall code release quality and dramatically improved end user experience.

As a request could I ask that once I release nGhost (nanoGhost), could you run a similar test?

I have a feeling, given that currenlty nGhost is 45kb in size and content is cached as html the numbers will put a smile on any performace engineer

Jim Hirschauer

nGhost sounds interesting (and tiny). Let me know when you release it and I’ll take a look.

Anonymous

Like most of these X vs. Y benchmark comparisons, you’re comparing apples to oranges, and the only conclusion you can come to is that Ghost + Nginx (the way you have them configured) is faster than WordPress + Apache (the way you have them configured) serving the 8 pages that you setup (node vs. php doesn’t apply here).

NodeJS may very well be faster than PHP, but one cannot jump to that conclusion from this test, there are far too many confounding variables.

Jim Hirschauer

vipercc, I agree with the fact that I’m comparing apples to oranges. These are 2 very different technologies and platforms. The purpose was not to benchmark Node.js or PHP but instead, as I clearly stated in the blog post, to test the common configuration of each platform (i.e. Ghost + Nginx and WordPress + Apache). In this case, the Node.js based platform soundly trounced the PHP based platform.

And just to take it a step further I configured Apache to be the front end web server for Ghost and guess what happened? Ghost ran every bit as fast and the total CPU consumption on the server was basically the same as with Nginx as the web server.

Should also state that WordPress is far more mature than Ghost, and I don’t mean by WordPress is suppose to more optimised or anything. By that I mean WordPress has a lot more to it, and unfortunately its just horrible software that is not optimised in anyway shape or form. It’d make more sense to compare Ghost to another newer PHP based blogging platform like Wardrobe which is more on par with Ghost IMO.

Hi George, I re-ran my tests using Apache as the front end for Ghost instead of Nginx and found that Apache + Ghost runs just as fast as Nginx + Ghost. I’ll update the post with this information today.

http://vbtechsupport.com/ GEORGE LIU

Cheers Jim, would be interesting to see a part 2 for concurrency scaling of apache + ghost vs nginx + ghost. I see you retested at 100 user concurrency

Thanks to your blog post’s introduction to Ghost, I just started playing with Ghost on Centminmod.com Nginx stack and looks interesting indeed. Eventually, I might as well do my own siege tests to compare Ghost + web server pairing for Nginx, Apache 2.4.6 event worker and Openlitespeed and share my findings.

It’s great to see people taking the time to do this, I could never publish this sort of thing I’d be seen as baised Nonetheless it’s a great set of results to help us explain why we abandoned PHP-land.

Comparing apples to oranges is always tricky, but the whole point is to see what the out-of-the-box experience is – which is perfect. I’d love to see what would happen though if you did run a similar test but with WordPress on nginx – perhaps you could provide some great performance ideas for those in the WP community.

The exciting thing is that we haven’t really started optimising Ghost yet – and there are many plans.

http://kylebumpus.com/ Kyle Bumpus

WordPress on Nginx wouldn’t buy you much because you’d still have all that blocking code. Javascript just lends itself to writing async by its nature, but an engineer who knew what they were doing could accomplish the same thing in PHP or Ruby if they enjoyed self-torture.

Anonymous

And now a test that uses an Opcode cacher for PHP.

Not saying that Ghost is not faster (it likely is. WordPress has picked up quite some bloat), but the results you are showing look a lot like an uncached PHP, which is not a configuration you would see out in the wild.

Also, it would be fairer to setup PHP-FPM and Nginx for WordPress as well

Jim Hirschauer

I specifically state in the blog post that I am testing out of the box configurations of each tool. There is definitely no caching on the PHP side. I did not tune any product (Nginx, Apache, Ghost, or WordPress) in any way. But, that is exactly the point. With no tuning of any sort Ghost was lightning fast.

I agree with your point about fairness, but I was testing common configurations not trying to benchmark. I did however run some tests where I used Apache to front end Ghost instead of Nginx. I am updating the post today to include that information so that people can see that the slowness on the WordPress side had nothing to do with Apache.

Anonymous

That’s my point though. Nobody would run PHP without some form of opcode caching. I know Apache has nothing to do with the slowness

Jim Hirschauer

Do you have a favorite opcode cache? I’d like to see the difference in performance when I add one to the mix. It would make an interesting follow up blog post.

I didn’t mean to imply that you thought Apache was the bottleneck. Others have mentioned it so that is why I brought it up. Thanks for your feedback so far!

Anonymous

Nor am I implying you are “fixing” the benchmark. I’ll concede that Node.JS has better out of the box performance characteristics, much like Nginx.

I’m merely pointing out that you’ll be hard pressed to find a hosting account that does not support an opcode cache as it literally makes a 2-5x difference.

That said, since it’s an out of the box experience, I’d pick one that is supplied by your distro. Rhel 6 comes with php 5.3.3 and you should probably stick with APC.

(yum install php-pecl-apc)

Be sure to restart Apache
Would love to see the difference and I’m willing to bet Ghost will still be somewhat faster. Just not 10x

http://vagabondians.com/ Glenn Dixon

“No PHP code requires op code caching. ”

That’s from the CEO of my hosting company, HawkHost.com – said they’d rather take the CPU hit than deal with the headache. In other words, seems like this ‘out-of-the-box’ test is spot-on…

Anonymous

It doesn’t “require” caching no, but the pages will load slower. Basically you are parsing and interpreting the code every time you hit a page. Go ahead, test it. Even without significant load, the pageloads will take almost twice as long and much more CPU.

Fortunately PHP 5.5 includes Zend Opcode cache by default so the only reason it’s not on “out of the box” is because it generally takes 2 years for a PHP version to make it to the default repo’s

As for the headache, I’m guessing he is referring to cache corruptions. This is a problem with PHP-FPM, but fortunately my more old fashioned setup will just make a cache per PHP process. I’d rather take the memory hit than have slow pageloads

http://vagabondians.com/ Glenn Dixon

He said he was testing the “most common configurations” – would you agree that it is ‘most common’ for opcode cache to be left out of the typical shared hosting setup at this time?

Again, no one is questioning whether opcode cache is better, just whether or not the typical blogger will have access to it “out of the box”

MT2D

lol )) of course he’d rather sell you more cpu power

http://vbtechsupport.com/ GEORGE LIU

These days it’s one of 3 opcode cachers

1. APC Cache
2. Xcache
3. Zend OpCache

Jim Hirschauer

Thanks for the feedback Hannah. I was really quite surprised to see how well Ghost handled the load. I’ll be interested to see how things go as more features are developed. I think one of the great benefits and drawbacks of WordPress is the massive amount of functionality available.

Hannah Wolfe

To date we have done nothing at all around optimisation, we did a basic load test to check we hadn’t done something stupid, but no performance testing, no memory usage testing, and the planned internal api caching layer isn’t built yet.

So, as we build out more and more features, we’ll also start to do this kind of testing and optimisation to ensure that Ghost is the best it can be. We’re also working to make sure that Ghost plays nicely with caches like Varnish, although that’s not ‘out-of-the-box’ setup.

The update to the tests is very interesting. I really hope you keep trying different combinations, because if there is a point at which Ghost stops coping so well, we want to know about it

php without opcode cache is a pretty bad idea and unprofessional. anyway a pear vs. apple comparison, because the two systems has very different features … WP: plugin architecture, templating engine, comments, database layer, … what about ghost?

http://pasteht.ml/ phillips1012

Just because wordpress has more features doesn’t mean node.js isn’t faster, powerful, and flexible. It’s been proven time and time again that node.js processes faster and non-blocking http servers perform better than blocking ones such as apache.

http://bohuco.net/blog MF

exactly … it means if you want compare node.js against php you should find a better benchmark then comparing popular cms-systems …

don’t like. title is misleading and shows bias from the begining. as the test setup is invalid for showing any evidence of whatsoever for the objective as layed out in the title, everything that might sound like a conclusion is NOT! to be fair – you can learn how to install things and run tools to get data … and how to write invalid comparisons. second it has the bad smell of an marketing ad that comes in disguise.

WebTechLabs

This is one of the most unusual comparisons I’ve seen between two platforms. You are comparing the performance of 2 different languages and 2 completely different scripts at the same time.

In laymen terms. This is what you are asking:

Coach to two students: “I want one of you to jog around the track. I want the other one of you to climb the hill. Then I’ll see which one of you is better.”

One platform (WordPress) is a heavyweight, full featured CMS platform that has enormous flexibility to do more than just blogging. Compared to another lightweight, limited feature set, blog only platform (Ghost). Ghost doesn’t even have a built-in commenting system nor run on a real database, it just uses SQLite.

If you wanted to have an even more unfair comparison…you might as well have stacked Magento on PHP vs Nodeshop on node.js. Then you could have bragged that node.js is 10000X faster than PHP.

http://www.appdynamics.com/ Jim Hirschauer

Thanks for your comment. You might want to reconsider your analogy. I had these two platforms perform the exact same tasks. A more accurate analogy (building off of yours) would be this…
Coach to two students: “I want both of you to run around the track as fast as you can.”

If you want to get even more accurate with an analogy I would use this…
Two people are sitting in a room. One is a generalist and one is a specialist. They are both asked to perform the same task over and over again as fast as they can.

Your comment implies that there is some sort of bias on my part when testing these platforms and that I somehow unfairly stacked the deck against WordPress. This is absolutely not the case, I just tested these platforms as close as I could get to how they came configured “out of the box”. The results are the results.

WebTechLabs

There is obvious bias here. When you said that these two platforms did the exact same tasks…that is a bold lie. Is Ghost a node.js port of WordPress?? No it isn’t.

Jim, do you not understand the technology?

Doing an unbiased test would entail you just changing 1 parameter in the test — either the script or the server, definitely not both. Compare WordPress vs Pyrocms on the same Apache server (the constant). Compare Node.js vs PHP with a hello world script. Compare Ghost vs Poet on node.js.

Also if you want to compare Ghost vs WordPress, then compare everything. Compare ease of finding hosting, how affordable hosting options are, ease of installation, templating capabilities, how many free templates are available, how easy it is to manage, user permissions options, comment features, community support, search engine optimization, plugins available, etc.

http://www.appdynamics.com/ Jim Hirschauer

You’re obviously very passionate about WordPress. I like WordPress for many of the reasons that you state at the end of your comment.

For the record, I never stated that Ghost and WordPress do the exact same things (WordPress is obviously rich with functionality compared to Ghost). My statement was that I asked them to do the same thing in my test (retrieve blog posts as fast as they could).

I doubt I’ll be able to convince you that I have no bias here. Have you noticed that this blog site uses WordPress?

WebTechLabs

Jim, it is just a bad comparison from a technical perspective. If you showed the Ghost dev team this post and asked them for their response, they would probably have the same issue I have — the comparison is not fair at all.

The title of the post should be “Ghost on Node.js is 700% faster than WordPress on Apache”.

Then your audience would have clearly seen the comparison is apples to oranges; and I as well as others who have chimed in here will have no complaints.

http://shanx.com/ NearlyNormal

You make sense. Sadly the test creator of this ridiculous test does not make any sense. It’s like comparing the running speed of two business executives — one is dressed in the whole business attire and carrying a suitcase ready to work (WordPress) while the other is in underpants and can’t really do much work on arrival (Ghost).

WordPress has a heavier code base and a proper database because we need all that functionality. Ghost has nada in comparison. Of course it’ll be faster. Compare WordPress to a homegrown blog-only script you write in PHP with entries being saved in text files. The latter will trounce even Ghost. So what?

WebTechLabs

And at least with WordPress.com you don’t get to see errors like this:

The server is temporarily unable to service your request due to the site owner reaching his/her bandwidth limit. Please try again later.

Anonymous

This just in, A McLaren F1 is faster than a golf buggy. That’s the level of stupidity with the comparison.

You’re comparing Ghost (essentially a 1-dataset C.R.U.D system) to WordPress, a bloated CMS. We may as well compare Ghost to Joomla, or Drupal, or any number of PHP CMS systems that have a blog. The title is way off base – you arent comparing Node.js to PHP in the slightest here, you’re just creating linkbait with no technical comparisons taking place at all.

You are comparing performances of 2 different CMS, not of the languages. The fact that both are called “blog” are not obviously relevant. WordPress has very, very poor performances on EC2.

To have a meaningful comparison you should probably write a custom script, in both languages, that doeas exactly the same thing, eg reading and writing random data in a database.

http://www.appdynamics.com/ Jim Hirschauer

Hi Luigi, you mention that WordPress has has “very, very poor performance on EC2″. Do you have some information to back up this statement or is it from personal observation? I’m curious how you arrived at that conclusion.

Luigi Clemente

Hi Jim
Since CPU performances are very poor on EC2 (compared to similar competitors) any PHP CMS suffers a lot, since it requires parsing several MB of code at every request. Even with APC enabled, Drupal and WordPress are very expensive to run if you have dynamic applications that cannot be cached. This comes form personal observations, load tests and other performance reports available on the web.

http://www.appdynamics.com/ Jim Hirschauer

Very interesting Luigi. I’m going to have to do some research and look into this. Thanks for sharing.

cybernet2u

if you tried apache on both platforms why haven’t you tried nginx on both ?

http://www.appdynamics.com/ Jim Hirschauer

No particular reason really. Since people were saying that Apache was slowing down the WordPress tests I figured I would just test Ghost with Apache too. Do you think testing both Ghost and WordPress with a nginx front end would change the results relative to each other?

cybernet2u

i think you should use back and front-end / just use them as they are / i’m using nginx with wordpress and you can visually see the difference ( page loading + RAM & CPU )

foofy

Just love php users and their apples to oranges comments.
In other benchmark – connect to db, execute sql query, return json, who is faster? they are arguing that that’s too simple for real world comparision and doesn’t mean anything

rolfen

Uh, sorry, this is in no way node.js vs PHP (so your title is really misleading).

It’s an interesting test, but I think it kind of fails right from start.

“Ghost is just a blogging platform and nothing more while WordPress is a full up CMS. I wanted to make this comparison as fair as possible so I limited my load testing scripts to executing against only the blog pages.”
Yeah well unfortunately WordPress is still a “full up CMS”, even if you just load blog pages. Popping the hood, it still does all those hooks, non-optimized db-thingies etc. A blog page is still just a content type, so it will still do a lot of overhead that a simple blog tool wouldn’t.
Judging from that WordPress more or less should be slower

Anyway, it was still interesting reading. What I would like to see though is what difference Nginx would do for WordPress. I think that there will be more difference than running Ghost on Apache, as Ghost is (should at least) be more lightweight.

Interesting read. The presentation layout is very nice and the approach is strutured well. What might add value to the comparison would be using Nginx to front WordPress and Node.js running standalone. This represents a real world scenario as Node.js is built with the idea of replacing the programming language + Web Server combo , it would make sense to test Node.js standalone with the best available today for php like Nginx and to an extent lighttpd.
Thanks

To travel from Point A to Point B you can use A BUS and A CAR/TAXI.
Now can you really take 50 people in a CAR ?

1) Can you have different User Types in Ghost ? Does it have a plugin to do so ? – NO
2) Can you create wonderful launching pages with GHOST ? – NO
3) Can you do wonderful Galleries with Blog ? – NO
4) Can you have loads of commenting options in GHOST ? – NO
n5) ….. NO
nn) …… NO

So stop doing such a bad comparison which just results in misguiding general people. If you wanted to really do a review of Ghost, you can do so separately, but accept that, it is no match or even anywhere near to the league of wordpress even as a Blogging tool.

INFO FOR READERS, a lot of wordpress issues/slowdowns happen because of shitty templates/Plugins written by crappy 2 years old experienced people who do not understand well how the plugin system works and how proper themes need to be written. Most of them even do not know that a caching plugin is an absolute must for any wordpress installation in spite of any kind of Hardware, With suitable caching plugins, wordpress works pretty well.

GHOST Does what it does(may be beautifully too), however, it can hardly do the most necessary and basic things that one would typically need on a daily basis even as a blogger.

WHOOPS !!! what does this page run on where you blogged all this about ?

Your comparison is more than poor, as well as your knowledge of both technologies. Compare a script that reads it to the pre-run time versus one that can be changed in real time is nonsense. I suggest you know best on both platforms. And sorry for my bad english.