#10 Run faster on win32.

General (24)

Right now, win32 performance with libevent is about as bad as you can get. This is a shame, since win32 has a lovely IOCP system that matches very will with libevent's bufferevents abstraction.

Christian King, a student working for Tor via the EFF for this past Google Summer of Code, wrote the beginnings of an implementation for bufferevents based on IOCP. We should integrate it, or something like it.

It probably needs more work; you can see it in the Tor svn repository at

The code is based on libevent-1.3b.


  • Nick Mathewson

    Nick Mathewson - 2007-12-07

    Logged In: YES
    Originator: YES

    So, this is improved a little thanks to the non-persistent event refactoring. Now that a backend can safely call event_active a lot, and then later have the event core take care of deleting non-persistent events, we could rewrite the win32 dispatch logic to:
    for each fd in read_set: event_active(event-with-that-fd, EV_READ, 1);
    for each fd in write_set: event_active(event-with-that-fd, EV_WRITE, 1);
    instead of the older code that did:
    for each added event:
    check if its fd is in read_set and write_set, and set e to 1 or 2 of EV_READ|EV_WRITE
    maybe call event_active(). maybe call event_del().

    With the addition of a red-black tree to map fds to events, the win32.c backend is now
    O(lg n) to add or remove an event, and O(a lg n) to run the dispatch loop, where n is the number of added events, and a is the number of active events. The old code was O(n) to add or remove an event, and O(a n) to run the loop.

    We still need an IOCP backend, but with any luck the new code should do way better in programs with lots of open sockets.

  • Nick Mathewson

    Nick Mathewson - 2009-10-26

    We've merged some IOCP logic based on the bufferevent refactoring, with an eye on Christian's original code. Closing this bug.

  • Nick Mathewson

    Nick Mathewson - 2009-10-26
    • status: open --> closed

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks