Notes from libuv: The Little Library That Could


These are my notes from a talk July 2, 2012 at NodeConf.

Who remembers the 0.5 days of node? Node was moving, and the foundations were shifting. On 0.4, node was on libev and libeio. At some point, we decided to switch to libuv. To understand why we had to do this, let's talk about libev.

Libev is a very simple and clean event loop library and it has one important feature, which is that it wraps many variations of a particular UNIX function called select. Suppose you're working with a connection to some other server and you want to do that in a non-blocking fashion; someone needs to inform you that data is available and you should process it. That is what libev does. The implicit assumptions are that the select model is the best model for scalable network apps, and that read(), write() and accept() are the best methods.

We didn't need to move off libev, but we decided to; Ryan especially wanted to move. Finally 0.6 comes out which uses this stuff. Let's look at the design decisions were were making for libuv


  • Abstract operations, not events.
  • Support different nonblocking I/O models (especially important on Windows)
  • Focus on embeddability and performance
  • Looks like libev

What can libuv do for you?

  • TCP/UDP sockets
  • DNS
  • Timers and other event loop primitives
  • Files and file system operations
  • Child processes
  • Pipes

What is the future of libuv? We want to queue more, and queue on Windows. Streams should be just streams. People don't want to care whether they're dealing with a TCP connection or some other connection. Edge triggered epoll, we are working on making it even faster on Linux because we're extracting so much stuff inside this library. We also want to make files streams, too and make files much faster!

This library was written to make our life as node developers easier. That doesn't mean only node can use it. Look around, you'll find other projects struggling with the same problems. Rust (from Mozilla) is using libuv, as well as Julia (a new language from MIT,) pyuv (direct bindings in Python,) Luvit (Tim Caswell) and many others.

Did you enjoy this post? Please spread the word.