Re: [CODE4LIB] Anyone using node.js?

2012-05-09 Thread Berry, Rob
You almost certainly should not rewrite an entire codebase from scratch unless 
there's an extremely good reason to do so. JoelOnSoftware did a good piece on 
it - http://www.joelonsoftware.com/articles/fog69.html.

Why has your project manager decided Node.js is the way to go instead of 
something like Python or Perl? Just because it's a shiny new technology? 
Python's got Twisted and Perl has POE if you want to do asynchronous 
programming. They also both have a very large number of excellent quality 
libraries to do innumerable other things.


From: Code for Libraries [CODE4LIB@LISTSERV.ND.EDU] on behalf of Ed Summers 
[e...@pobox.com]
Sent: 09 May 2012 04:26
To: CODE4LIB@LISTSERV.ND.EDU
Subject: Re: [CODE4LIB] Anyone using node.js?

I've been using NodeJS in a few side projects lately, and have come to
like it quite a bit for certain types of applications: specifically
applications that need to do a lot of I/O in memory constrained
environments. A recent one is Wikitweets [1] which provides a real
time view of tweets on Twitter that reference Wikipedia. Similarly
Wikistream [2] monitors ~30 Wikimedia IRC channels for information
about Wikipedia articles being edited and publishes them to the Web.

For both these apps the socket.io library for NodeJS provided a really
nice abstraction for streaming data from the server to the client
using a variety of mechanisms: web sockets, flash socket, long
polling, JSONP polling, etc. NodeJS' event driven programming model
made it easy to listen to the Twitter stream, or the ~30 IRC channels,
while simultaneously holding open socket connections to browsers to
push updates to--all from within one process. Doing this sort of thing
in a more typical web application stack like Apache or Tomcat can get
very expensive where each client connection is a new thread or
process--which can lead to lots of memory being used.

If you've done any JavaScript programming in the browser, it will seem
familiar, because of the extensive use of callbacks. This can take
some getting used to, but it can be a real win in some cases,
especially in applications that are more I/O bound than CPU bound.
Ryan Dahl (the creator of NodeJS) gave a presentation [4] to a PHP
group last year which does a really nice job of describing how NodeJS
is different, and why it might be useful for you. If you are new to
event driven programming I wouldn't underestimate how much time you
might spend feeling like you are turning our brain inside out.

In general I was really pleased with the library support in NodeJS,
and the amount of activity there is in the community. The ability to
run the same code in the client as in the browser might be of some
interest. Also, being able use libraries like jQuery or PhantomJS in
command line programs is pretty interesting for things like screen
scraping the tagsoup HTML that is so prevalent on the Web.

If you end up needing to do RDF and XML processing from within NodeJS
and you aren't finding good library support you might want to find
databases (Sesame, eXist, etc) that have good HTTP APIs and use
something like request [5] if there isn't already support for it. I
wrote up why NodeJS was fun to use for Wikistream on my blog if you
are interested [6].

I recommend you try doing something small to get your feet wet with
NodeJS first before diving in with the rewrite. Good luck!

//Ed

[1] http://wikitweets.herokuapp.com
[2] http://wikistream.inkdroid.org
[3] http://inkdroid.org/journal/2011/11/07/an-ode-to-node/
[4] http://www.youtube.com/watch?v=jo_B4LTHi3I
[5] https://github.com/mikeal/request
[6] http://inkdroid.org/journal/2011/11/07/an-ode-to-node/

On Tue, May 8, 2012 at 5:24 PM, Randy Fischer randy.fisc...@gmail.com wrote:
 On Mon, May 7, 2012 at 11:17 PM, Ethan Gruber ewg4x...@gmail.com wrote:



 It was recently suggested to me that a project I am working on may adopt
 node.js for its architecture (well, be completely re-written for node.js).
 I don't know anything about node.js, and have only heard of it in some
 passing discussions on the list.  I'd like to know if anyone on code4lib
 has experience developing in this platform, and what their thoughts are on
 it, positive or negative.



 It's a very interesting project - I think of it as kind of non-preemptive
 multitasking framework, very much like POE in the Perl world, but with a
 more elegant way of managing the event queue.

 Where it could shine is that it accepts streaming, non-blocking HTTP
 requests.  So for large PUTs and POSTs, it could be a real win (most other
 web-server arrangements are going to require completed uploads of the
 request, followed by a hand-off to your framework of an opened file
 descriptor to a temporary file).

 My naive tests with it a year or so ago gave inconsistent results, though
 (sometime the checksums of large PUTs were right, sometimes not).

 And of course to scale up, do SSL, etc, you'll really need to put something

Re: [CODE4LIB] Anyone using node.js?

2012-05-09 Thread Berry, Rob
No, it's not all hype. I've used Node to write a server for ticket scanners at 
a festival and enjoyed working with it. It performed well and was stable. I'm 
just sceptical about someone who wants to throw away a codebase for something 
that, whether deserved or not, is generating a lot of buzz at the moment.

Though re Python I would say mixing Django with Twisted is a fairly blatant 
error. There are libraries built on Twisted to serve web-pages, and if you're 
doing event-driven programming you should really be using them.


From: Code for Libraries [CODE4LIB@LISTSERV.ND.EDU] on behalf of Ed Summers 
[e...@pobox.com]
Sent: 09 May 2012 09:24
To: CODE4LIB@LISTSERV.ND.EDU
Subject: Re: [CODE4LIB] Anyone using node.js?

On Wed, May 9, 2012 at 3:47 AM, Berry, Rob robert.be...@liverpool.ac.uk wrote:
 You almost certainly should not rewrite an entire codebase from scratch 
 unless there's an extremely good reason to do so. JoelOnSoftware did a good 
 piece on it - http://www.joelonsoftware.com/articles/fog69.html.

 Why has your project manager decided Node.js is the way to go instead of 
 something like Python or Perl? Just because it's a shiny new technology? 
 Python's got Twisted and Perl has POE if you want to do asynchronous 
 programming. They also both have a very large number of excellent quality 
 libraries to do innumerable other things.

I totally agree, it's all about the right tool for the job.

Just to clarify, NodeJS is quite a bit different than Twisted and POE
because the entire language and its supporting libraries are written
for event driven programming from the bottom up. When using Twisted
and POE you may end up needing existing libraries that are
synchronous, so the wins aren't as great, and things can
get...complicated. For a pretty even handed description of this check
out Paul Querna's blog post about why Rackspace decided to switch from
Twisted to NodeJS for their cloud monitoring dashboard applications
[1].

I am not saying Perl and Python are not good tools (they are) just
that the benefits of using NodeJS are not all hype.

//Ed

[1] 
http://journal.paul.querna.org/articles/2011/12/18/the-switch-python-to-node-js/


Re: [CODE4LIB] Anyone using node.js?

2012-05-09 Thread Berry, Rob
No, fair enough, you are right. If that's the paradigm you want it would be a 
better bet to go for a language that has it built in from the ground up.

From: Code for Libraries [CODE4LIB@LISTSERV.ND.EDU] on behalf of Ed Summers 
[e...@pobox.com]
Sent: 09 May 2012 10:05
To: CODE4LIB@LISTSERV.ND.EDU
Subject: Re: [CODE4LIB] Anyone using node.js?

On Wed, May 9, 2012 at 4:50 AM, Berry, Rob robert.be...@liverpool.ac.uk wrote:
 Though re Python I would say mixing Django with Twisted is a fairly blatant 
 error. There are libraries built on Twisted to serve web-pages, and if you're 
 doing event-driven programming you should really be using them.

Heh, but part of your argument for using POE or Twisted was that they
also both have a very large number of excellent quality libraries to
do innumerable other things. I think it's more like a slippery slope
of mixing programming paradigms than it is a blatant error. Also, I
think it was specifically the Django ORM code that bit them hardest,
not HTTP calls. Yes there are ORM options like adbmapper, but I think
you increasingly find yourself in the weeds on the fringe of the
Python community.

//Ed