Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
"STAT time" drifts when computer is put to sleep #278
When I restart memcached, the server's clock is in sync with system time. (I'm checking the clock by reading "STAT time" from the command below).
If I put the computer to sleep, the clock doesn't advance until the system resumes. As a result, the clock drifts w.r.t system clock. If I check the entries in memcached (with
Consider an example :
Expiration timestamp is still 2 AM UTC, but memcached's clock is 30 minutes behind the computer clock. As a result, the object would expire at 2:30 AM (as opposed to 2:00 AM, the intended time).
Is this a memcached bug or is my understanding incorrect ? I've experimented this by setting an actual object and I found that the expiration time drifts by the time the computer is put to sleep.
That's intentional, unfortunately. Memcached implements a monotonic clock to ensure it always goes forward generally when time goes forward for the computer. When a computer is asleep time isn't going forward.
Without the monotonic clock NTP can jump time both forward and backwards; and if time goes backwards then forwards again you can create immortal objects with underflowed expiration times. Or if time goes forward then backward an object which was supposed to expire in 5 minutes could take hours or days (or years, if the clock is pretty screwed up on boot).