Leap year Leap months are well known, but have you ever heard of leap seconds?
Leap years are meant to bridge the gap between our calendar of 365 days and the earth’s actual revolution of 365.25 days, so one leap year every four years has an extra day on February 29.
The leap month is related to the lunar calendar, different from the solar calendar in the way of the revolution, the lunar calendar to the moon around the earth to calculate the time, so will be 365.25 days and solar calendar difference of 10 days and 21 hours, so, the extra time accumulated together into a month, that is, the leap month.
So what is a leap second? What will the leap second do? What’s the solution to the leap second problem?
A leap second is defined
To understand leap seconds, you need to understand a few basic concepts.
Mean solar day: The time it takes for the sun in the sky to have two consecutive maximum elevations (90 degrees) is one solar day, and since the length of the solar days varies, the average of the solar days over a year is taken, so it can be roughly considered that a mean solar day is 24 hours.
UTC is Coordinated Universal Time (UTC) in English and Universal Time (UTC) in Chinese. I believe all students who have developed UTC know well that it is the world’s main Time standard for regulating clocks and Time and one of the Time systems closest to Greenwich Mean Time (GMT).
In the earliest days, a second was defined as 1/86,400 of the average solar day, depending on the earth’s rotation and revolution. Later, until 1967, the second was redefined by physics in terms of the oscillating frequency of cesium 133, which could be measured by atomic clocks.
The UTC time is defined based on this, and it is a fixed length of time.
But because the speed of earth’s rotation is affected by many factors, such as accelerated tides, the average solar day is not fixed.
The leap second was created to keep UTC close to the mean solar day.
Leap seconds come in two forms:
- A leap second, where one second after 23:59:59 is 23:59:60 and then 00:00:00.
- A negative leap second, which is 00:00:00 after 23:59:58, has not been observed.
Leap seconds are usually adjusted on June 30 or December 31. The most recent leap second adjustment will take place on December 31, 2016.
From 1972 to now, there have been more than 20 times a leap second, for our system configuration, through NTP service for time synchronization, if the server receives notice processing of leap seconds, will themselves to the edge of the issuance of the NTP server, and then inform to the client operating system, and finally by the operating system to deal with leap seconds.
The chart below shows when leap seconds occur over the years:
years | On June 30 | On December 31 |
---|---|---|
In 1972, | + 1 | + 1 |
In 1973, | 0 | + 1 |
In 1974, | 0 | + 1 |
In 1975, | 0 | + 1 |
In 1976, | 0 | + 1 |
In 1977, | 0 | + 1 |
In 1978, | 0 | + 1 |
In 1979, | 0 | + 1 |
In 1981, | + 1 | 0 |
In 1982, | + 1 | 0 |
In 1983, | + 1 | 0 |
In 1985, | + 1 | 0 |
In 1987, | 0 | + 1 |
In 1989, | 0 | + 1 |
In 1990, | 0 | + 1 |
In 1992, | + 1 | 0 |
In 1993, | + 1 | 0 |
In 1994, | + 1 | 0 |
In 1995, | 0 | + 1 |
In 1997, | + 1 | 0 |
In 1998, | 0 | + 1 |
In 2005, | 0 | + 1 |
In 2008, | 0 | + 1 |
In 2012, | + 1 | 0 |
In 2015, | + 1 | 0 |
In 2016, | 0 | + 1 |
Influence brought about
Although the leap second has no impact on ordinary People’s Daily life, it is fatal to the Linux operating system running the NTP service. The Linux kernel version before 2.6.29 has a bug. When the leap second is adjusted, the NTPD process may be locked and crash. In addition, CPU load spikes because applications cannot handle leap seconds, causing time changes.
Reddit, Mozilla, FourSquare, Yelp, LinkedIn and Gawker all had problems during the last leap second, with Reddit down for more than an hour and a half. Kernel [81951.244556] Clock: Inserting Leap Second 23:59:60 UTC
In addition, for the database, 23:59:60 time compatible with the problem is not the same.
PostgreSQL: PostgreSQL is compatible with 23:59:60 and does not report errors.
Mysql: The Mysql database does not support the 60-second script. The Unix time must be used for leap seconds. Otherwise, errors will be reported.
Based on current information, Linux kernel versions higher than 2.6.29 fix this problem, NTP versions higher than 4.2.2 P1-9 spread this second over about 2000 seconds, and lower versions add or subtract a second.
The solution
The simplest way to do this is to stop the NTPD service before a leap second occurs and start it again after the leap second.
Stop NTP /etc/init.d/ NTPD stop Resetting the system time date -s "date" Restart NTP NTP /etc/init.d/ NTPD startCopy the code
However, there is an obvious problem that a large company serving thousands of machines is too successful to operate, and whether stopping synchronization will cause other problems. Evaluate the impact level.
At present, such as Google, Ali, Amazon have some specific solutions, the use of cloud services may not need users to care about this problem, if it is their own computer room hosting then it may need operation and maintenance developers to deal with manually.
Take the processing scheme of Alibaba Cloud in China for example, Amazon also adopts this scheme
The NTP service of Ali Cloud’s ECS cloud server is designed to handle leap second events by ignoring the leap second and slowly synchronizing to eliminate the one-second error caused by the leap second. The actual plan is that every second is 1/86400 slower than UTC before the leap second occurs and 0.5 second slower than UTC after 12 hours (43,200 seconds). After the leap second occurs, The second and UTC errors are reduced by 1/86400, and after 12 hours (43,200 seconds), the -0.5 error is eliminated. Foreign Amazon also offers such a solution.
The following table shows the specific time synchronization scheme:
UTC | Aliyun time (Beijing time zone | Ali Cloud time and UTC error | note |
---|---|---|---|
2016/12/31 11:59:59 | 2016/12/31 19:59:59 | + 0 | Fully synchronized with UTC |
12:00:00 | 20:00:00 | + 0 | |
12:00:01 | 1/86400 slower than UTC per second, and 0.5 second slower than UTC after 12 hours (43,200 seconds) | ||
20:00:01 | + 1/86400 | ||
12:00:02 | |||
20:00:02 | + 2/86400 | ||
… | … | … | |
23:59:59 | |||
2017/1/1 07:59:59 | + 43199/86400 | ||
23:59:6 0 | A leap second | ||
2017/1/1 08:00:00 | 0.5 seconds – | And UTC error -0.5 seconds | |
2017/1/1 00:00:00 | The second and UTC errors are reduced by 1/86400, and after 12 hours (43,200 seconds), the -0.5 error is eliminated | ||
08:00:01 | 43199/86400 – | ||
00:00:01 | |||
08:00:02 | 43198/86400 – | ||
… | … | … | |
19:59:59 | 1/86400 – | ||
11:59:59 | … | … | |
2017/1/1 12:00:00 | 2017/1/1 20:00:00 | 0 | Sync with UTC again |
12:00:01 | 20:00:01 | 0 | |
… | … | … |
How to predict avoidance
In fact, due to the time unable to calculate the earth’s rotation, he may have faster, is also likely to slow, tides, weather, and the flow of the molten metal in the earth’s core and so on various aspects factors, unable to forecast the next leap second time, but the international earth rotation and reference systems service (IERS) will be published 6 months in advance the time of the next leap seconds.
Shoulders of giants:
Zh.wikipedia.org/wiki/%E9%97…
Developer.aliyun.com/article/682…
Yq.aliyun.com/articles/80…
www.cnblogs.com/luxianghao/…