Why Node.js?

In the last few weeks I have built from scratch a new SMTP server (based loosely on the concepts in Qpsmtpd) using Node.JS. A number of people have asked me why, so I thought I would create a blog and start writing about it.

The main reason really was to just learn something new. I’ve been coding mostly in perl now for 15 years, and while I still appreciate the language, the rough edges do start to wear on you. A few years ago I decided that new thing would be Ruby, but the performance of the language just wasn’t there, and so I gave up. I tried Python for a while, but didn’t like it either. I had coded in Java before, and so I knew that wasn’t what I wanted.

What sparked my interest in using Javascript was reading about the performance of Google’s V8 engine. It appears to have taken all of the scripting performance expertise developed in the lisp and smalltalk arenas and implemented them in a very fast Javascript engine. Great for the browser, but equally nice to have on the server.

The other thing that really got me interested is that I’ve been programming async-IO systems in Perl for a while now, and the major problem I find there is that none of the other perl coders are used to writing async systems, and so all the libraries out there are synchronous. This is a real problem if you plug those into an asynchronous system because it blocks the event loop.

With Node.JS everyone is coding async libraries, because the core libraries are asynchronous, and so everyone just expects it to work that way. Genius!

So I got cracking with some coding, figured out how the weird and slightly fragile OO system works, and came up with Haraka.

What I am really enjoying about hacking on this (rather than Qpsmtpd for example) is I have some really solid plans from the start of how I want monitoring, configuration, etc to work across a cluster of mail servers, rather than just an individual server. This will at some point (it hasn’t yet, but it’s early days) influence my design. One way we’re seeing this right now is very early on I have implemented a web-based graph built-in to it which shows you which plugins rejected your mail. I hope to advance that some day to include a full breakdown on things like which DNSBL rejected your mail, which will be very sweet indeed. And then maybe at some point even have it going down to the individual domain and recipient level… Oh that would rock.


Haraka Test graphs (note this is just a mock up, not real data)

So how is performance? Well so far it looks pretty good. I can process and save to disk about 5000 mails/sec on my iMac. I’m not sure yet how that stacks up to other mail servers (even Qpsmtpd) but I’m willing to bet it’s not bad.

Next post: The weaknesses of Node.JS and Javascript in general.


2 thoughts on “Why Node.js?

    • I’m pretty sure that was with 5kB messages (about the average for spams, but on the low side for non-spam).

      Bear in mind that is NOT doing an fsync, as in that case you’re limited by disk spin speed anyway.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s