Of course, there is also a significant body of research on this topic, showing for example that user-level thread implementations tend to get very similar performance to event-based servers. There is also the issue that the purity of "no blocking APIs" is somewhat naive on a modern Unix, because blocking on I/O can happen in lots of different non-obvious places. At the very least, you may encounter a page-fault, and this may even be desirable in order to use memory mapped files.
In those cases, the fact that you have purified all your APIs makes no difference, you are still blocked on I/O, and if you've completely foregone kernel threads like node.js appears to do, then your entire server is now blocked!
Anyway, baving seen some interesting node.js benchmarking, I was obviously curious to see how my little embedded Objective-C http-server based on the awesome GNU microhttp stacked up.
The baseline is a typical static serving test, where Apache (out-of-the box configuration on Mac OS X client) serves a small static file and the two app servers serve a small static string.
Platform | # requests/sec |
Static (via Apache) | 6651.58 |
Node.js | 5793.44 |
MPWHttp | 8557.83 |
Platform | # requests/sec |
Static (via Apache) | - |
Node.js | 88.48 |
MPWHttp | 47.04 |
Platform | # requests/sec |
Static (via Apache) | - |
Node.js | 9.62 |
MPWHttp | 7698.65 |
To make the comparison a little bit more fair, I added an xor with a randomly initialized value so that the optimizer could not remove the loop (verified by varying the loop count).
Platform | # requests/sec |
Static (via Apache) | - |
Node.js | 9.62 |
MPWHttp | 222.9 |
Cross-checking on my 8 core Mac Pro gave the following results:
Platform | # requests/sec |
Static (via Apache) | - |
Node.js | 10.72 |
MPWHttp | 1011.86 |
In conclusion, I think it is fair to say that node.js succeeds admirably in a certain category of tasks: lots of concurrency, lots of blocked I/O, very little computation, very little memory use so we don't page fault. In more typical mixes with some concurrency, some computation some I/O and a bit of memory use (so chances of paging), a more balanced approach may be better.
Is your Objective-C wrapper around GNU microhttp available as open source? thanks.
ReplyDeleteYes: https://github.com/mpw/ObjectiveHTTPD
ReplyDelete