107

Both 2 libs are designed for async i/o scheduling, and both engages epoll on linux, and kqueue on FreeBSD, etc.

Except superficial differences, I mean what is the TRUE difference between these two libraries? regarding to architecture, or design philosophy?

ciphor
  • 8,018
  • 11
  • 53
  • 70

3 Answers3

245

As for design philosophy, libev was created to improve on some of the architectural decisions in libevent, for example, global variable usage made it hard to use libevent safely in multithreaded environments, watcher structures are big because they combine I/O, time and signal handlers in one, the extra components such as the http and dns servers suffered from bad implementation quality and resultant security issues, and timers were inexact and didn't cope well with time jumps.

Libev tried to improve each of these, by not using global variables but using a loop context for all functions, by using small watchers for each event type (an I/O watcher uses 56 bytes on x86_64 compared to 136 for libevent), allowing extra event types such as timers based on wallclock vs. monotonic time, inter-thread interruptions, prepare and check watchers to embed other event loops or to be embedded and so on.

The extra component problem is "solved" by not having them at all, so libev can be small and efficient, but you also need to look elsewhere for an http library, because libev simply doesn't have one (for example, there is a very related library called libeio that does asynchronous I/O, which can be used independently or together with libev, so you can mix and match).

So in short, libev tries to do one thing only (POSIX event library), and this in the most efficient way possible. Libevent tries to give you the full solution (event lib, non-blocking I/O library, http server, DNS client).

Or, even shorter, libev tries to follow the UNIX toolbox philosophy of doing one thing only, as good as possible.

Note that this is the design philosophy, which I can state with authority because I designed libev. Whether these design goals have actually been reached, or whether the philosophy is based on sound principles, is up to you to judge.

Update 2017:

I was asked multiple times what timer inexactness I refer to, and why libev doesn't support IOCPs on windows.

As for timers, libevent schedules timers relative to some unknown base time that is in the future, without you knowing it. Libev can tell you in advance what base time it will use to schedule timers, which allows programs to use both the libevent approach and the libev approach. Furthermore, libevent would sometimes expire timers early, depending on the backend. The former is an API issue, the latter is fixable (and might have been fixed since - I didn't check).

As for IOCP support - I don't think it can be done, as IOCPs are simply not powerful enough. For one thing, they need a special socket type, which would limit the set of handles allowed on windows even more (for example, the sopckets used by perl are of the "wrong" type for IOCPs). Furthermore, IOCPs simply don't support I/O readyness events at all, they only can do actual I/O. There are workarounds for some handle types, such as doing a dummy 0-byte read, but again, this would limit the handle types you can use on windows even more and furthermore would rely on undocumented behaviour that is likely not shared by all socket providers.

To my knowledge, no other event library supports IOCPs on windows, either. What libevent does is, in addition to the event library, it allows you to queue read/write operations which then can be done via IOCPs. Since libev does not do I/O for you, there is no way to use IOCPs in libev itself.

This is indeed by design - libev tries to be small and POSIX-like, and windows simply does not have an efficient way to get POSIX-style I/O events. If IOCPs are important, you either have to use them yourself, or indeed use some of the many other frameworks that do I/O for you and therefore can use IOCPs.

Remember Monica
  • 3,897
  • 1
  • 24
  • 31
  • Marc are you the author of libeio as well? – juanpavergara Mar 09 '14 at 15:21
  • sadly, it was removed and replaced by libuv: https://github.com/joyent/libuv/issues/485 and this: https://groups.google.com/forum/#!topic/nodejs/UwHkaOksprw – Peter Teoh Jan 13 '15 at 11:11
  • 1
    I've made a nice addition to libev called libevfibers, it adds a fiber level on top of libev, libcoro and libeio. Can be found here: https://github.com/Lupus/libevfibers – Lupus Aug 24 '15 at 07:12
  • 1
    `libev` is painful on Windows platform. MinGW compiler always sigfault on `++activecnt` (function `ev_ref`) and I does not understand how to resolve this problem. Second problem is using old `select` socket interface withour modern IOCP version of socket interoperation. Could you improve Widnows support? – Vitold S. Jan 03 '16 at 02:51
  • 3
    Sorry to have to say, but there seems to be another "philosophy" behind libev, which has broken many open source projects. Evident for example in http://lists.schmorp.de/pipermail/libev/2017q1/002710.html or http://lists.schmorp.de/pipermail/libev/2010q1/000912.html. Potential users should probably consider this, too. – dbrank0 Mar 22 '17 at 08:36
  • @dbrank0 the first is a shortcoming in valgrind, not a bug in libev, and the second is simply somebody getting scared by a compiler warning that does not actually say what he thinks it says, as the given place is not breaking any known aliasing rules. libev's "philosophy" is indeed a correctness in the real world. – Remember Monica Sep 16 '17 at 17:55
  • @Vitold: I extended my answer – Remember Monica Sep 16 '17 at 18:09
16

The great advantage of libevent for me is the built-in OpenSSL support. Bufferevent interface, introduced in 2.0 version of libevent API, handles the secure connections almost painlessly for the developer. May be my knowlege has gone out of date but it seems like libev does not support this.

Vitaly Isaev
  • 5,392
  • 6
  • 45
  • 64
0

Here are souce code link, libev: https://github.com/enki/libev libevent: https://github.com/libevent/libevent
I find the latest commitee of libev is 2015, but the livevent still have commitees untill July 2022, so a library have persons to maintain it is also important.

Jamishon
  • 72
  • 7
  • That isn't the official libev repository. Official website here: http://software.schmorp.de/pkg/libev.html – bw1024 May 11 '23 at 23:22