I've been working on a small application based on libevent, where I have found it very useful to have an "idle" callback. That is, my application gets a callback when the libevent loop is idle. I use this to provide low-latency processing of "high priority" events, and processing "low priority" events only when otherwise idle.

It seems like it should be possible to implement this with libevent by using priorities and timeouts: Set the priority on all network events to be "high", and set an immediate timeout with a lower priority. However, this is not possible because timeouts are triggered without regarding priority.

This seems like it might be useful to others, although it may also be too application specific to be included in libevent. If anyone is interested in seeing the code, let me know and I'll send out the patch.



Motivation:

My application reads messages from a large number of clients. Roughly, these messages can either be "high priority" and "low priority." The high priority messages need to be acted on with minimal latency, while the low priority messages can be processed whenever. In order to reduce the latency for high priority messages, I only process a small number of "low priority" messages between polling the network (via libevent). I implemented it as follows:

* In my libevent callback, read all messages from the clients. If they are high priority messages, process them, if they are low priority messages, queue them.

* Modify libevent to trigger an "idle" callback at the bottom of the libevent polling loop. In this callback, my application can execute a small number of "low priority" messages, before indicating if libevent should poll the network, or if it should block waiting for network I/O (no more low priority messages to process).


It is possible that it would be "cleaner" to implement this by integrating priorities into the timeout mechanism, so that low priority timeouts would only be processed after high priority network events. This would require fairly extensive changes to libevent though.

Evan Jones

--
Evan Jones
http://evanjones.ca/
_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkeymail.org/mailman/listinfo/libevent-users

Reply via email to