For linux leap seconds, for linux leap seconds
Author: luxianghao
Article Source: http://www.cnblogs.com/luxianghao/p/6339470.html reprint please note, thank you for your cooperation.
Disclaimer: The content of this article only represents your personal opinion. If you have any improper content, please correct me.
---
Why is there a leap second?
There are several ways of measuring time in the world,
Universal Time (UT1): It is an astronomical metering method. By observing the rotation of the earth, astronomers divide the cycle of one week (one day) into 864000 parts, each of which is one second,
Due to the influence of the tide and other factors, the cycle of the Earth's rotation is not constant, which is also the direct cause of the leap second phenomenon.
Atomic Time (TAI): Due to the unstable world as described above, physics used a more stable quantum metering method to calculate the time. On July 6, 1967, the international conference on metrology used the Zee 133
(Cs133) the duration of the first cycle of the radiation corresponding to the transition between two super-fine levels in the ground state of an atom is defined as 1 second. This is the most accurate time currently.
The metering method has an error of 1400000-One second, which is negligible.
Coordinated Universal Time (UTC): It is also known as the world standard time or the world coordination time. UTC is based on TAI and UT1. When the deviation between UTC and UT1 is close to one second,
The IERS will announce the next leap second six months in advance.
Is there a regular leap second? How long is it a leap second?
As shown in, there seems to be no regularity. As mentioned previously, there are no laws on the factors that affect the rotation of the earth, so leap seconds naturally do not have any regularity.
What is the impact of a leap second?
For ordinary people, the second of normal work, off-duty, work, learning, and life deviation is irrelevant. It will not affect people's birthdays like a leap year or a leap month.
For aviation, aerospace, military, and other industries that require time accuracy, the impact will be greater.
For linux systems in the Internet industry where I am located, a leap second may cause sudden increase in machine cpu usage and machine downtime, and the corresponding services will be suspended,
Since the Internet has only been booming in recent years, the previous leap second impact on linux has not been amplified. With the widespread use of linux, leap second has become more and more important.
Impact of leap second on linux and run applications on linux
When the system prints the information inserted in a leap second: When NTP notifies the kernel about the action of leap second, this bug will be triggered and will occur inThe day before the occurrence of a leap secondAt any time,
This bug is triggered in advance because the NTP time server will notify the linux server to connect to it one day in advance. A leap second will occur at a certain time point in the future. ntp on the linux server will receive this message.
Later, some processing will be performed on linux time in a leap second, adding one second or subtracting one second.
The live lock of a leap second causes the system to hold down:Due to this bug, the NMI watchdog detects that the system is holding on, and the system will not stop crash. After a leap second is inserted, this bug will be triggered. It is not confirmed yet.
Which version fixes the bug?
Cpu load increases rapidly: The reason is that the application cannot handle sudden changes in system time caused by leap seconds. linux provides two types of system time: wall time and montonic time.
The wall time records the fact time and can be adjusted forward or backward. The montonic time records the number of seconds since the system was started and can only be incremented forward.
The wall time used is affected by the system time adjustment (such as leap second), but the latter is not affected. The jdk indicates that the latter is used in jdk 7u6.
What kind of system logs will be generated when the kernel cannot handle a leap second failure?
Eg: Kernel panic-not syncing: Watchdog detected hard lock up on cpu 21
What records will the system log have after a leap second?
Eg: kernel [81951.244556] Clock: inserting leap second 23: 59: 60 UTC
Kernel bug fixes
The bug mentioned above has been fixed in various linux versions. A secure version is provided here. The kernel version 2.6.39-200.3 or later can be considered safe.
Ntp & leap seconds
The host uses ntp
In this case, the performance of the host in the leap second depends on the ntp version used.
Version 1 is later than or equal to version 4.2.2p1-9 or later (except for ntp-4.2.6p5-19.el7, ntp-4.2.6p5-1.el6 and ntp-4.2.6p5-2.el6_6)
Run the-x parameter: The leap second is not directly added to the kernel, but distributed to about 2000 seconds. The first second is longer than the previous one and the change time is slow,
Advantages:
1) Avoid application logic problems caused by time fallback
2) Strange time points 23: 59: 60 won't appear
3) because the leap second is not actually added, the kernel bug described above will not appear.
Disadvantages:
1) because the length of one second is not accurate within the adjusted period, the scenario with high time precision is not applicable.
2) due to the ntp update mechanism, this method is also not applicable to clusters that require the time consistency of all nodes.
B runs without the-x parameter. ntp will notify the kernel to increase the value by one second (sudden increase, non-continuous)
Version 2 is earlier than 4.2.2p1-9
Ntp will notify the kernel to add one second or stop one second.
Note:If ntp is run on the host, Run "file/etc/localtime" to make sure there is "no leap seconds" in the output result (this indicates that no leap seconds will be added)
Ntp is not used on the host.
1. tzdata is not used.
The host time is completely adjusted by yourself. We recommend that you add the-x parameter to ntp.
2. tzdata is used.
Version a is earlier than 2015a and no leap second is added.
B is greater than or equal to 2015a and runs "file/etc/localtime". The output result contains "X leap seconds" (X is a number)
A leap second will appear in the form of "23: 59: 60", which will cause a problem with the DATE/TIMESTAMP data type,
You need to copy the appropriate/usr/share/zoneinfo file to overwrite/etc/localtime (this operation is dynamically adjusted and does not need to be restarted)
Summary of Leap seconds
1. Upgrade the kernel so that the version is later than or equal to 2.6.39-200.3. The kernel can process leap seconds, but it still has to guard against the time sensitivity of applications. For details, refer to this section,
For such applications, you need
A reconstruction code
B. Upgrade the corresponding software, such as jdk.
2. When the host is any version of the kernel, the ntp upgrade is later than or equal to 4.2.2p1-9 to deal with scenarios with low time precision requirements.
3 for those who do not care about time precision or want to upgrade anything, restart ntp.
A stops ntp (one day in advance/etc/init. d/ntpd stop ),
B date-s "'date'" (Reset System Time, I think this may be done to unlock the deadlock caused by leap seconds)
C start ntp/etc/init. d/ntpd start
4. copy the time file to cope with the leap seconds added to tzdata
Postscript
The above content is my summary of the materials, and there is no actual verification yet. If you need to apply it in the production environment, please check the rationality of the method in advance