It's Go Time On Linux


Recommended Posts

By Albert Strasheim March 05, 2014 12:00AM

Some interesting changes related to timekeeping in the upcoming Go 1.3 release inspired us take a closer look at how Go programs keep time with the help of the Linux kernel. Timekeeping is a complex topic and determining the current time isn?t as simple as it might seem at first glance.

1axie.jpg

Go running on the Linux kernel has been used to build many important systems like RRDNS (our DNS server) at CloudFlare. Accurately, precisely and efficiently determining the time is an important part of many of the these systems.

To see why time is important, consider that humans have had some trouble convincing computers to keep time for them in the recent past. It been a bit more than a decade since we had to dust off our best COBOL programmers to tackle Y2K.

More recently, a bug in the handling of a leap second propagated through the Network Time Protocol (NTP) also took many systems off-line. As we've seen in recent days, NTP is very useful for synchronizing computer clocks an d/or DDoSing them. The leap second bug received extensive coverage. Google was ready but many other popular sites were taken offline.

We also have the Year 2038 problem to look forward to. Hopefully there will still be a few engineers around then that remember what this 32-bit thing was all about.

 

Time in Go

Everything starts with the time package that is part of Go?s standard library. The time package provides types for Time, Duration, Ticker, Timer and various utility functions for manipulating these types.

The most commonly used function in this package is probably the time. Now function, which returns the current time as a Time struct. The Time struct has 3 fields:

Detailed Full Source

Link to comment
Share on other sites

This topic is now closed to further replies.