Think about it

... Or not

1 note & Comment

PHP, Node.JS, Mysql and Mongo

I’ve spent few weeks looking at performance between Apache/PHP vs Node.JS and Mysql vs MongoDB.

All test were run on my local computer with ApacheBench :

- Intel Core 2 Duo E8500 @ 3.16GHz

- 8Gb of Ram

- Ubuntu 11.10 Desktop 64bits

- Apache 2.2.20

- PHP 5.3.6

- Node.JS 0.6.6

- Mongodb 1.8.2

- Mysql 5.1.58

The first graph comparing PHP and Node.JS is based on a simple return “Hello world” application. You can see that Node.Js perform a bit better than Apache/PHP which event fail to give any result in high concurrency test (PS: There is actually a lots of good request but too much of them failed to get any accurate reading). This test is just a brute force representation on the capability of Node.js.

The second graph represent the performance between PHP/Mysql vs PHP/Mongodb vs Node.Js/Mysql vs Node.js/Mongodb. This is a basic application which just retrieve 1 random row out of the database of 100,000 rows and return “Good” on success. You can quickly notice that the degradation of the performance of Node.js when you have to connect to a database at each server request but if we keep the connection open, Node.Js will perform better. I will have to to the same test with PHP and a persistent connection.

Obviously those test for Mongo vs Mysql were made to test a specific use case. I didn’t test performance when retrieving more than one row, or ordering a set of rows or querying a field without index or even looking through a 100Million rows.

I did test writing in MonogB compare to writing in MySQL. For example writing 10,000 rows in MongoDB took 0.6 second where the same code with MySQL took 7 minutes (I was inserting one row at the time). MongoDB end-up being faster here because it’s actually not writing to the disk right away.

Those technologies should be use accordingly, MongoDB is really fast in writing, so you could use it for storing user activity on a social network or login page views. Node.JS is really fast to handle a request, some people even use Node.JS as a load balancer.

Source code:

  1. zzarbi posted this