I was running truss on memcached today and noticed a lot of calls to clock_gettime caused from event_base_loop while I was assuming only a few.

From looking in the code I see that it will also try to get the current time even if we don't have any attached timed events for that event base. The following patch seemed to fix the problem for me:

tr...@storm:2025> gdiff -Naur libevent-1.4.11-stable/event.c libevent-1.4.11-stable.patch /source
--- libevent-1.4.11-stable/event.c    2009-01-20 04:03:27.000000000 +0100
+++ libevent-1.4.11-stable.patch/event.c 2009-06-04 00:34:40.347082761 +0200
@@ -526,19 +526,24 @@
            return (1);
        }

-        /* update last old time */
-        gettime(base, &base->event_tv);
-
-        /* clear time cache */
-        base->tv_cache.tv_sec = 0;
+                if (!(min_heap_empty(&base->timeheap))) {
+                   /* update last old time */
+                   gettime(base, &base->event_tv);
+
+                   /* clear time cache */
+                   base->tv_cache.tv_sec = 0;
+                }

        res = evsel->dispatch(base, evbase, tv_p);

        if (res == -1)
            return (-1);
-        gettime(base, &base->tv_cache);

-        timeout_process(base);
+                if (!(min_heap_empty(&base->timeheap))) {
+                   gettime(base, &base->tv_cache);
+ + timeout_process(base);
+                }

        if (base->event_count_active) {
            event_process_active(base);


Cheers,

Trond

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

Reply via email to