strange performance differences of 1.2.2 vs 1.2.5

Sean Chittenden sean at
Sun Jun 1 22:45:54 UTC 2008

> I was wondering if anyone here has experience with FreeBSD 6.2? I  
> was compiling 1.2.5 for one of the groups at Yahoo and they saw  
> dramatic performance decreases with 1.2.5 over 1.2.2. Has there been  
> an introduction of code I am forgetting that may cause this?

Summary: For 90% of all cases: "clock_gettime(CLOCK_MONOTONIC, ...)"  
== good.  "gettimeofday(2)" == bad.

I haven't benched 1.2.5, but I'd bet a beer that the culprit is the  
following 1.2.5 change:

        * Use gettimeofday(2) instead of time(2).

For background on why gettimeofday(2) is more expensive, see the  
following thread:

or for a brief discussion of this in a white paper format:

Essentially, gettimeofday(2) is supposed to be highly accurate  
according to POSIX, FreeBSD guarantees accuracy and Linux makes no  
such guarantees (hence the performance hit when going from time(2) to  
gettimeofday(2) for BSD and not Linux).  Proper implementation of  
gettimeofday(2) requires synchronization across CPUs, whereas time(2)  
does not.  memcached *should not* use gettimeofday(2) unless highly  
accurate and sub-second resolution is a requirement.  If highly  
precise, but inaccurate time keeping is acceptable,  
clock_gettime(CLOCK_MONOTONIC, ...) should be used instead (using a  
system call that requires CPU synchronization is the opposite of good  
for a performance oriented daemon).

The above thread has all the gory details, but the performance of time  
system calls is an FAQ that should be widely understood at this point.


Sean Chittenden
sean at

More information about the memcached mailing list