Found in 1 comment on Hacker News
inakiabt · 2011-09-21 · Original thread
I'm new with Node.js, but the "shorten" process shouldn't be an asynchronous process? Maybe something like this?:

   app.get('/shorten', function(req, res) {
      console.log('Shortening url...');
      shortener.shorten(req.param('u'), function(result){
        res.send(result);
      });	
    });
It's well known that Redis is pretty fast, but, citing "Node Web Development" (http://www.amazon.com/Node-Web-Development-David-Herron/dp/1...) on it "Architecture: Threads versus asynchronous event-driven" chapter, "(...)Depending on the query that pause can be quite long. This is bad because while the entire thread is idling another request might come in, and if all the threads are busy it will be dropped. Looks like quite a waste. Context switching is not free either, the more threads we use the more time the CPU spends in storing and restoring the state. Furthermore, the execution stack for each thread takes up memory. Simply by using asynchronous, event-driven I/O, Node removes most of this overhead while introducing very little on its own."

It is not a criticism but a question.

Fresh book recommendations delivered straight to your inbox every Thursday.