Was just wondering whether use of timerfd (timerfd_create) for linux would give any performance benefit over Timer_Heap or Timer_Wheel. Surely, this is a very high level question and the only place I have seen it being used in any framework is "muduo".Also, I don't have any performance comparisons as well.
Thanks.
Event-loop libraries like libevent, maintain the timers in a min-heap and pass the timeout till the next timer expiry to select
/epoll
. Note that adding and removing a timer does not involve any system calls in this scenario, it just adds a new element into the min-heap.
When you use timerfd
, it takes 3 system calls (timerfd_create()
, timerfd_settime()
and epoll_ctl()
) just to create a timer. And every time it expires you need to read()
from that file descriptor.
timerfd
could be useful for applications without an event loop, but for ones that already use a decent event loop it is pretty much useless.