Conversations about life & privacy in the digital age

Wibbly Wobbly Timey Wimey, or How to Gracefully Compensate for an Incorrectly Set Clock

Part of being a good sysadmin is being flexible. Quite often when something breaks you’re solving a new problem, and the developers, users, and management turn to you to find a solution. One day you’ll be sorting out IP misconfiguration, the other you’ll be debugging Python libraries, and another you’ll be working around yet another limitation of your web server. You wind up reading a lot of documentation and learning a little about everything.

We had a particularly puzzling problem on one of our servers the other day. Somehow, its clock had been set eight hours fast1. We were running NTP, but it wasn’t set to jump the clock on start2, so even though NTP was synced to an upstream server, the clock was still a long ways off.

Normally, this is pretty easy to fix — you set the clock back, and you’re done. For us, though, it was a serious problem because uploads are ordered by commit time, which is dependent on the server’s clock. The guy who wrote our nagios time check was summarily flogged, and Alan and I set out to find a solution. We came up with a few ideas:

  1. Wait eight hours for real time to catch up
  2. Rewrite all the logs and database entries to have correct times
  3. Find a way to slow down what our daemons thought was the correct time in order to gradually bring their time in sync with real time

#1 was right out — we weren’t going to stop uploads for that long. #2 was heinously difficult and fraught with peril, so we went with #3. Alan’s quick googling found libfaketime, one of those great utilities that shouldn’t exist, but does. Libfaketime works as a LD_PRELOAD hack to change the way certain time library calls work. It can create a time offset and/or speed up and slow down the passage of time relative to the system clock3.

After two hours pondering and hacking, we put our plan into action. We set our server’s time back to normal and modified our daemons’ time to pretend to be six hours in the future, running at half-speed. Twelve hours later, the times synced up, and we undid the hack. Problem solved, and I’ve added one more unmentionable hack to my toolbox. :)

1: I’m not entirely sure, but I think the reason for this is a recent motherboard swap. We set our system clocks to UTC, and the motherboard probably arrived with its clock set to Pacific time.

2: Debian/Ubuntu admins note: this option is turned off by default in the openntpd package.

3: Interestingly, Erlang provides similar behavior by default. If erl detects a jump in the system clock, it will slowly adjust its concept of current time to match.

Comments

  1. Annie says:

    Maybe to make it future-proof you should build a timey-wimey detector that goes ding when there's stuff.

  2. IcyEars says:

    Maybe to stop it happening again, you should sit watching the clock and Don't turn your back, don't look away, and don't blink!

  3. Olive says:

    1. I do hope that the server software refuses to start or immediately stops if time is found to go backwards then.
    2. perform a ntpdate at boot just before starting ntpd, to account for large offsets
    2. On some systems you have "date -a" to slowly adjust your clock back to normal.

  4. jna says:

    Probably time to remove the time dependency from your upload system. Ordering by system clock is unreliable in large environments. Have a look at Twitter's snowflake, for creating id's which creates scalable, monotonically increasing IDs without duplication, regardless of clock time.

  5. Anonymous says:

    Twitter's snowflake sets the high bits of the ID from the system clock (hopefully synchronized over NTP or something similar) — it ain't "regardless of clock time." And their technique for generating monotonically increasing IDs in the presence of clock regression is to refuse to generate a new ID until the clock has retraced past its previous high value. For these guys, that would have meant holding everything up for eight hours.

  6. John says:

    You might want to look into DJB's clockspeed package for managing your systems clocks. It corrects for skew, too.

  7. Cliff says:

    Reading this reminded me of something Google did…
    http://googleblog.blogspot.com/2011/09/time-technology-and-leaping-seconds.html

  8. backlink service says:

    Best backlinks and website traffic service – we post your marketing post up to 100'000 forums worldwide price starting only from $29 Get large web traffic using superb backlink blast today. We can post your marketing post up to 100’000 forums worldwide, get insane amount of backlinks and incredible targeted online web traffic in shortest time. Most affordable and most powerful service for web traffic and backlinks in the world!!!! Your post will be published up to 100000 forums worldwide your website or blog will get instant traffic and massive increase in seo rankings just after few days or weeks so your site will get targeted long term traffic from search engines. Order now: <a href=http://xrumerservice.org>backlinks</a>

  9. cash for survey says:

    If you want to make $10-$150/hour and up to $3500/month of your free time working at
    home part-time then this is the most important message you’re ever
    going to read.

    Here’s why:

    “Businesses need ME! They’re paying me money – CASH – to a
    36-year-old work-at-home mother to get my opinion.”

    http://www.cash-reward-surveys.info/surveys.html

    Guess what?

    They also need YOU!

    I’m not a marketing expert or a sales gal. In fact, I know very
    little about business. But I do know exactly what I like and what
    I don’t like. I know what products I would buy and what services
    I would use.

    Guess what? This is exactly what large companies are paying me
    for. They need to know what their average customer needs and
    wants. So these companies pay millions of dollars every month to
    the average person. In return, the average person, myself
    included, answers some questions and gives them their opinion.

    You’ve got to try this out. Just click on the link below and
    check it out yourself.

    http://www.cash-reward-surveys.info/surveys.html

  10. backlinks service says:

    Best backlinks and website traffic service – we post your marketing post up to 100'000 forums worldwide price starting only from $29 Get great online web traffic using best backlink blast today. We are able post your custom message up to 100’000 forums worldwide, get insane amount of backlinks and great targeted online web traffic in very short time. Most affordable and most powerful service for web traffic and backlinks in the world!!!! Your post will be published up to 100000 forums worldwide your website or blog will get instant traffic and massive increase in seo rankings just after few days or weeks so your site will get targeted long term traffic from search engines. Order now: <a href=http://xrumerservice.org>backlinks</a>

  11. LEssCoall says:

    Hi, This just came across my desk and I had to pass it on to you ASAP…
    Internet multi-millionaire Mack Michaels has a few new positions available right now…
    If accepted you can easily rake in $11, 917 per month starting from scratch.
    ==> http://www.maverickmoneymaking.info/maverick.html
    Once you’re accepted just follow the training Mack gives you. It’s really quite simple…
    Learn how Mack went from not being able to afford Christmas gifts to a millionaire lifestyle and how you can too!
    BUT…
    Due to the extremely high level of Hands-On time Mack spends with every new member he has to limit the number of positions that are open.
    Right now there are only 2 available in your area. If you’re interested you should move quickly.
    ==> http://www.maverickmoneymaking.info/maverick.html
    Your Friend, – Mike

  12. oonxhsxtvj says:

    lzwngtqjefspbl, <a href="http://www.emzzvcoegd.com">xvyvdjdusw</a&gt; , [url=http://www.ysqhcqmiie.com]wvtarhaayt[/url], http://www.cybgqfxrfs.com xvyvdjdusw

  13. uicppopiin says:

    fyfbvtqjefspbl, <a href="http://www.qvodmhxyyu.com">ctpcowgzqw</a&gt; , [url=http://www.ktdghkmybb.com]aaekxdongz[/url], http://www.aokwhuutst.com ctpcowgzqw

  14. hokaceivoq says:
  15. yxaivfonaw says:

    lwkartqjefspbl, http://www.aumqqjesar.com szglcbluzo

  16. lpnkjddnml says:

    fxhoutqjefspbl, http://www.obklesvdjz.com qgsqyzdwzk

  17. fpghmuhegu says:

    axlpftqjefspbl, http://www.vsqqwxqogb.com fqdgvcfkxk

  18. zsdglbeubc says:

    hvczvtqjefspbl, <a href="http://www.frumxetqta.com">ecfpetancb</a&gt; , [url=http://www.jdjlqyecin.com]tcnvpmblyt[/url], http://www.tscyvrqoep.com ecfpetancb

  19. otjksxwkvy says:

    lofjctqjefspbl, <a href="http://www.cfsqigkozb.com">xjwzxmplmm</a&gt; , [url=http://www.hbibgirucp.com]lrnvgaricy[/url], http://www.ymtlbhmcpb.com xjwzxmplmm

  20. kosaftjlst says: