Friday, June 11th, 2010
Connect: Great middleware for Node!
<p>Tim Caswell has been doing awesome work, and his latest project is Connect, a high performance middleware framework for node.js. Ruby has Rack. Python has WSGI. Java has Servlets. Now, JavaScript has Node/Connect.I was able to set it up in minutes and took the following screencast of a sample application in action:
Take a peak at the examples as they show you how easy it is to rack up the middleware. In the Raphael circle multi-touch collaborative dragging example shown, you get a nice set of filters:
-
-
module.exports = new Connect.Server([
-
{filter: "log"},
-
{filter: "response-time"},
-
{filter: "body-decoder"},
-
{provider: "pubsub", route: "/stream", logic: Backend},
-
{filter: "conditional-get"},
-
{filter: "cache"},
-
{filter: "gzip"},
-
{provider: "cache-manifest", root: root},
-
{provider: "static", root: root}
-
]);
-
Awesome. And with the Heroku support it is tempting to git a version up there and see how many Ajaxians can muck around with it....
Related Content:











Actually, JSGI is really the middleware of JavaScript. Connect is node-specific, and is actually much slower and has critical flaws compared to JSGI:
http://www.sitepen.com/blog/2010/06/11/jsgi-vs-connect-for-node-middleware/
And Perl has Plack (http://plackperl.org)
Connect’s has grown and changed a lot since this article. The new code is at SenchaLab’s account on github http://github.com/senchalabs/connect.
As far as being slow, the sitepen article pulls apart a very minute part of the total cost of serving a web page and shows that that particular part of connect is several times slower than JSGI. This is totally irrelevant since the overall cost of serving a website is not affected in any significant way by the difference. In fact, connect’s built-in layers and filters can make a basic setup be able to serve 35,000 requests/second of real http traffic over a lan for small responses. For large responses I’ve clocked it at 40% faster than nginx or apache on the same machine! Connect is many things, but slow is not one of them.
Connect is node specific on purpose and this is a feature!