虎嗅

Why is Google trying to redefine what a second means?

原文:为什么 Google 要重新定义一秒钟?

Summary of Key Points

This article discusses how the instability in Earth's rotation has led to a discrepancy between astronomers' and computer scientists' definitions of a "second," causing significant issues for computer systems due to the need for leap seconds to synchronize the two. To address this, Google developed a technique called "Time Smear," which breaks down leap seconds into smaller portions and distributes them over 24 hours, making the time change imperceptible to systems. Other tech companies have adopted this approach, which even led the International Bureau of Weights and Measures (CGPM) to decide to eliminate leap seconds by 2035. However, the issue of time discrepancies across cloud platforms has not been completely resolved.

1. Why Are Leap Seconds Necessary? The "Time War" Between Astronomers and Computer Scientists

Astronomers and computer scientists have fundamentally different definitions of a second:

  • Astronomical Time (UT1): Based on Earth's rotation, one complete rotation takes 24 hours (86,400 seconds). However, Earth's irregular movements due to internal processes and external factors make this not exactly 86,400 seconds.
  • Computer Science Time (TAI): Measured using atomic clocks, which provide a fixed and consistent number of oscillations per second, regardless of Earth's rotation.

This discrepancy has grown more pronounced as astronomers aim to align time with celestial events (e.g., noon at 12 PM), while computers require time to progress in a continuous and linear manner. In 1972, UTC (Coordinated Universal Time) was established as a compromise, using atomic clocks as the standard. If UTC deviates from Earth's rotation by more than 0.9 seconds, a leap second is added, resulting in the unusual time format of 23:59:60.

2. Leap Seconds as a "Nightmare" for Computers: Real-World Examples of Disruptions

Computer systems rely on the continuous and linear progression of time for various operations:

  • Logs need to be sorted by time, database transactions depend on timestamps, and distributed locks prevent deadlocks.

The introduction of leap seconds disrupts these processes:

  • The appearance of 23:59:60 causes crashes in software that does not handle this time format.
  • A temporary pause in time can lead to duplicate timestamps for the same events, invalidating deadlock detection.
  • A sudden shift in time can cause chaos in distributed systems' locking and transaction mechanisms.

A notorious example was the 2012 leap second, when a bug in the Linux kernel triggered deadlocks, causing widespread system failures on platforms like Reddit, Mozilla, and Australian Airlines, with server CPUs reaching 100% usage. This highlights how what seems like a minor adjustment by astronomers can have serious consequences for digital systems.

3. Google's "Time Smear" Technique: A Temporary Solution

Google developed Time Smear to mitigate the problems caused by leap seconds:

  • How it works: Before a leap second, Google's internal time servers slow down slightly (each second is slightly longer than usual). The additional second is then distributed evenly over 24 hours.
  • Effect: Systems do not detect any change in time; there are no 23:59:60 moments, and all services, databases, and locks function normally.

Although this approach creates a "pseudo-time" that does not conform to either UTC or TAI, for engineers, the stability of systems is far more important than strict adherence to standards.

4. Industry Adoption and the CGPM's Decision to Eliminate Leap Seconds

Google's technique proved so effective that other companies like AWS, Meta, and Microsoft also adopted it with their own implementations. In 2022, the CGPM decided to phase out leap seconds from UTC by 2035. Astronomers have conceded to computer scientists' needs, choosing a more consistent and predictable time model in the digital age.

5. Remaining Issues: Time Discrepancies Across Cloud Platforms

Despite the widespread use of time smoothing techniques, different cloud providers implement them differently:

  • Google distributes the adjustment evenly over 24 hours from the moment of the leap second.
  • AWS starts the adjustment from noon the previous day and applies a linear or cosine-based distribution over 24 hours.
  • Meta used a 17.5-hour smoothing approach.

If systems are distributed across different cloud platforms (e.g., some on AWS and some on GCP), time stamps may differ by several milliseconds during the adjustment period, potentially leading to data inconsistencies in sensitive distributed transactions. This indicates that the time gap between the physical and digital worlds has not been completely bridged.

In conclusion: To prevent system failures, Google's approach to defining a second has changed the global time standard, demonstrating how practical engineering solutions can override academic principles. However, the time discrepancy between the digital and physical worlds continues to exist in more subtle forms.