Connect - Middleware For NodeJS

Yesterday myself and Tim Caswell open-sourced the first Ext JS nodejs project, Connect. Connect is an abstraction layer, providing node developers with an effective, high performance solution for rapid development using interchangable components called “middleware”.

Middleware

Middleware provides node developers with simple “plug and play” modules, which may be stacked in any order desired, aiding in rapid development. Connect middlware are regular node modules exporting the handle() method, however conceptually they fall into two categories, filters, and providers.

A “filter” conceptually sits arbitrarily within the middlware stack, processing incoming and outgoing traffic, but typically does not respond to a request. An example of this is the log filter provided by Connect, it does not respond to any request, it simply proxies function calls in order to log request data.

A “provider” differs conceptually in the fact that it provides an end-point in the stack. However this may not always be the case. For example a json-rpc provider may choose not to process or respond to a request if the Content-Type header is not application/json. A classical example of a provider is the static provider which serves static files.

Executable

Connect is a dual purpose library, rapid development is not the only goal in mind. Also provided is the connect executable which can be used to daemonize Connect servers (and regular node servers) using an extremely simple command-line interface.

For more information on the connect executable install Connect and run:

$ man connect

Performance

Performance is a top priority for Connect, and we have the benchmarks to prove it. The following benchmarks were performed with ApacheBench, node 0.1.97, thin 1.2.7, sinatra 1.0, and rack 1.1.0.

The benchmarks bundled with Connect consistently showed that the library has nearly no overhead compared to a regular node server when responding with the typical “Hello World” response.

Hello World

Next up we have node, sinatra (thin), and Connect serving jquery.js, a roughly ~57kb.

Static jQuery

If you wish to run the benchmarks on your own machine, first execute:

$ make benchmark

Then generate the graphs with gnuplot:

$ make graphs

Once complete:

$ open results/graphs

Conclusion

Connect is awesome, what are you waiting for! head over to the Github repo and fork away.

Notes

  1. msbrogli reblogged this from tjholowaychuk
  2. book-of-ra-online reblogged this from senchainc
  3. tjholowaychuk posted this