Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libevent, windows and .NET programming

Tags:

.net

libevent

I experiment with a lot of open source software and I've noticed a fair amount of server type applications in the open source world use libevent to facilitate event-based processing rather than spawn multiple threads to handle requests.

I also do a lot of .NET programming (it's my core job function), and I'm interested in learning how libevent relates to the .NET event model. Are events in .NET the equivalent of libevent for C programs? Should I try to learn libevent and attempt to use it in custom .NET server applications or is using the standard .NET event model basically the same thing?

like image 492
Chris Avatar asked Jul 03 '09 06:07

Chris


1 Answers

.NET events and libevent are not equivalent, though they share abstract concepts.

.NET events allow non-deterministic communication between CLR components. In C#, the component is an object - events are class members. In other languages, like F#, objects are not required. An event allows consumers to subscribe to notifications that occur on specific conditions in the source - a button is clicked, a download is complete, an exception occurred, etc. A few characteristics of .NET events:

  • They're not tied to the underlying OS
  • You can define events for any condition.
  • They're not inherently asynchronous (the notifier and the notified aren't necessarily running at the same time, though they can be).

libevent allows non-deterministic, asynchronous communication between the OS and a consumer. This might feel similar to .NET events because they both invert control, but the mechanisms are very different.

  • libevent uses OS-specific, non-blocking I/O(/dev/poll, kqueue, epoll) to improve performance. Your results will vary depending on the OS and mechanism you use.
  • libevent event conditions include state changes in file descriptors, OS signals, or timeouts. You can't define arbitrary callback conditions.
  • libevent is inherently asynchronous. The consumer doesn't block while waiting for the OS to return.

Should I try to learn libevent and attempt to use it in custom .NET server applications...?

If you're doing it for fun, sure. If you're doing it for work, probably not. libevent claims its biggest performance gains on *nix systems. Windows uses a different networking paradigm. The libevent developers are addressing these differences in version 2 but 2.0.5 is still a beta release.

In addition, .NET offers its own non-blocking I/O libraries including asynchronous sockets.

like image 84
Corbin March Avatar answered Nov 13 '22 22:11

Corbin March