Dealing with leap seconds under Linux

Source: Internet
Author: User
Tags system log

Article Luxianghao

Article Source: http://www.cnblogs.com/luxianghao/p/6339470.html reprint Please specify, thank you for your cooperation.

Disclaimer: The content of the article represents only personal opinions, if not, please correct me.

---

Why do you have a leap second?

There are several ways to measure time in the world,

World Time (UT1): Is a way of astronomical measurement, astronomers by observing the Earth's rotation, and the rotation of a week of time (one day) and so divided into 864,000 parts, each for one second,

Due to tidal and other factors, the time of the Earth's rotation is not constant, which is the direct cause of the leap second phenomenon.

Atomic Time (TAI): Because the world described above is not stable, physicists use more stable quantum metrology to count time, and in 1967, the International Metrology conference used cesium 133

(Cs133) The transition between the two ultra-fine levels of the atomic ground state is defined as the duration of the 9,192,631,770 cycles of the radiation corresponding to 1 seconds, which is the most accurate time currently

Measurement, the error is 1.4 million years a second, the basic negligible

Coordinated Universal Time (UTC): Also known as world standard Time or World coordinated Time, UTC is based on Tai, but also UT1, when the deviation between UTC and UT1 is close to 1 seconds,

The International Earth Rotation and Reference Service (IERS) will announce the next leap second time 6 months in advance.

Leap second whether there is a regular, how long time leap seconds?

As shown, there seems to be no law, as previously said, the factors affecting the rotation of the earth are not regular, then the leap seconds naturally there is no regularity.

What is the impact of leap seconds?

For ordinary people, normal work, off duty, work, study, the life of the deviation of this second irrelevant, this will not be like a leap year, leap month, the impact of people's birthday

For the more accurate time requirements of aviation, aerospace, military, etc., the impact will be relatively large

For my internet industry, server exclusively Linux system, leap seconds may cause a sudden increase in machine CPU, machine downtime, the corresponding services will be hung off,

Because the internet has flourished in recent years, so the impact of the previous leap second on Linux has not been amplified, with the widespread use of Linux, leap seconds have been more and more attention.

Impact of leap seconds on Linux and the application of run on Linux

When the system prints leap seconds to insert information , the bug will be triggered when NTP notifies the kernel about the leap second action, and the bug will occur at any time before the leap second occurs .

The reason this bug was triggered early is that the NTP time server will notify the Linux server connected to it one day in advance, a leap second will occur at some point in the future, and the NTP of the Linux server receives this message.

will do some processing of Linux time in leap seconds, add one second, or subtract one second

leap second live lock causes the system to tamper with: because this BUG,NMI watchdog will detect the system tamping, the system will not stop crash, the leap seconds after the insertion of this bug will be triggered, not yet determined

Which version fixed the bug

CPU Load Rapid increase : The reason is that the application can not handle the sudden change of system time caused by leap seconds, the Linux system provides two system time, wall and montonic times, where

Wall Time records the fact that it can be adjusted forward or backward, and montonic time records the number of seconds since the start of the system and can only be incremented forward, so if the application gets

The time-wall time is affected by the system timing (such as leap seconds), while the latter is not affected, specifically to the JDK to show that the latter is being used in JDK 7u6.

The system log that cannot process the kernel in leap seconds when processing a leap second failure

Eg:kernel panic-not Syncing:watchdog detected hard LOCK up on CPU 21

What is logged in the system log after leap seconds?

EG:KERNEL[81951.244556] clock:inserting leap second 23:59:60 UTC

Kernel bug fix situation

The above mentioned bug in each version of Linux on a succession of repair, here to provide a safe version, the kernel is 2.6.39-200.3 or later can be considered safe

NTP && leap seconds

The host uses NTP

At this point the host's performance in leap seconds will depend on the version of NTP used

Version 1 above equals 4.2.2p1-9 or higher (except NTP-4.2.6P5-19.EL7, Ntp-4.2.6p5-1.el6 and Ntp-4.2.6p5-2.el6_6)

A with the-x parameter run: Leap seconds is not directly added to the kernel, but the second is dispersed to about 2000 seconds, 1 seconds longer than before, a slow change in time,

Advantages of doing this:

1) Avoid application logic problems caused by time regression

2) The odd point of time 23:59:60 does not appear

3) The kernel bug described above does not appear because the leap seconds are not actually added

Disadvantages of doing so:

1) due to the time period of adjustment, the length of a second is actually inaccurate, so the time-precision requirements of the scene is not applicable

2) Because of the NTP update mechanism, this approach also does not apply to clusters that require consistent time across all nodes

b run without the-x parameter, NTP notifies the kernel to add a second (burst, discontinuous)

2 version less than 4.2.2p1-9

NTP notifies the kernel to increase the number of seconds directly, or to stop one second

Note: If NTP is running on the host, run "File/etc/localtime" to make sure "no leap seconds" is in the output (this indicates no leap seconds are added)

Host does not use NTP

1 No use of tzdata

Then the host's time is completely self-tuning, it is recommended to use NTP plus the-x parameter

2 used the Tzdata

Version A is less than 2015a and does not add leap seconds

B is greater than or equal to 2015a and runs "File/etc/localtime" with "x leap seconds" in the output (x is a number)

The leap seconds will appear in the form of "23:59:60", which causes problems with the Date/timestamp data type,

You need to copy the appropriate/usr/share/zoneinfo file to overwrite the/etc/localtime (this operation is dynamically adjusted and does not need to be restarted)

Coping with leap seconds summary

1 upgrading the kernel to make the version greater than or equal to 2.6.39-200.3, the kernel can handle leap seconds, but still beware of the application of time sensitivity, the case can refer to this,

For such an application, you need to

A refactoring code

b upgrade the corresponding software such as JDK

2 If the host is any version of the kernel, the upgrade NTP is version greater than or equal to 4.2.2p1-9, in response to those scenarios where time accuracy requirements are not high

3 for those who do not care about time accuracy and do not want to upgrade anything, then restart NTP

A stop NTP before the advanced time server sends a LEAP second notification (requires a day in advance/etc/init.d/ntpd stop),

b date-s "' Date '" (Resets the system time, which the individual thinks might be to solve the deadlock caused by the leap seconds)

C Starting ntp/etc/init.d/ntpd start

4 Copy time file should be tzdata added in leap seconds

Postscript

The above content is I review the summary of the material, has not yet done the actual verification, if need to apply in the production environment, please check the rationality of the method in advance

Dealing with leap seconds under Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.