Navigate / search

For MySQL: Goodbye NodeJS, Welcome Back PHP

Talk about words you never thought you’d hear yourself saying!

If you’ve ever worked with me (or probably even spoken with me) you know I love Node.js. I love everything about it…Javascript, the frameworks, the community, everything. I’m especially fond of the trend toward NoSQL data stores in combination with Node.

Having used one or more NoSQL databases in my last few projects, I know they’re fast, usually Javascript based, and the absolute wrong choice for a project I just started. The right choice: a relational database. MySQL being my choice.

I’m not going to go into why that’s the right choice, or MySQL over PostgreSQL, or InnoDB over MyISAM. There are a number of reasons, but it mostly comes down to the project requirements and personal preference.

FTW!
FTW!

What does it matter? Isn’t the database independent of the scripting language?

Yes and no. They’re independent systems, but we still need drivers to interface between them. That’s where the problem lies.

With the focus on NoSQL data stores, I don’t think anyone has taken the time to write a performant MySQL driver. The situation gets even worse with ORMs and worse still with newer versions of Node. Most of the solutions I found don’t support Node 0.7.x.

Wanting desperately to “make it work,” I spent some time this weekend comparing different combinations of Node drivers and frameworks/ORMs with those available in PHP.  PHP is the clear winner.

+----------------------+--------+-------+-------+-------+-------+
| Driver/ORM           | Type   | Run 1 | Run 2 | Run 3 |Average|
+----------------------+--------+-------+-------+-------+-------+
| NodeJS_mysql         | driver | 4.53  | 4.58  | 4.65  | 4.58  |
| NodeJS_sequelize     | orm    | 11.64 | 11.70 | 11.74 | 11.69 |
| PHP_PDO              | driver | 2.14  | 2.21  | 2.21  | 2.18  |
| PHP_laravel_raw      | driver | 3.33  | 3.37  | 3.38  | 3.36  |
| PHP_laravel_eloquent | orm    | 4.52  | 4.38  | 4.37  | 4.42  |
| PHP_doctrine         | orm    | 2.43  | 2.44  | 2.54  | 2.47  |
| PHP_zenddb           | driver | 2.39  | 2.48  | 2.48  | 2.45  |
+----------------------+--------+-------+-------+-------+-------+

If you’re wondering how I arrived at those results, the repo is on GitHub. Feel free to fork it f you have another driver or ORM you think should be included.

The Point

Pick the right tool for the right job. Look at the results above. The right tool for MySQL is not Node. Not yet anyway.