• Young
    2022-02-02
    1. clock - Wall clock; Used to represent date and time; After synchronization, the local clock of our server can jump backward or forward in time - Monotonic clock; Used to calculate duration; The time ALWAYS moves forward and will not be impacted by variations leading to jumps in time 2. Wall clock - Linux uses UTC as wall clock - UTC is not accurate because earth's rotation speed varies - UTC does not contain Leap Second, so Linux adjust the UTC time to real earth rotation by inserting leap seconds into UTC time scale 3. Wall clock Synchronization - Normal solution: synchronize with NTP (Network Time Protocol). Because of the network delay, there will be at least a 35 millisecond deviation, and the maximum may exceed 1 second. - Good solution: receive accurate wall time with GPS, synchronize with other servers via PTP, and can achieve sub-microsecond precision - Google solution: Google uses a GPS receiver to receive a standard wall clock, and then deploys the atomic clock through the computer room, so that its accuracy can reach an error of only 1 second every 20 million years, in this way to prevent the failure of the GPS receiver. Send accurate time to other servers with TrueTime API - Google Spanner (distributed database) is based on this. 4. Resolve Leap Second Issues - Bad Solution: notify the kernel, and allow it to insert the leap second, which cause stepping the system clock backwards - Good Solution: Slew the leap second (since RHEL 6.8 and RHEL 7.2), allowing this second to be spread out over a period of time instead of an immediate step back in time 5. How computer manage time? - Clock interrupts is based quartz crystal oscillator. Computer update the wall time during each clock interrupt - How to deal with 1 microseconds (small precision)? BogoMIPS Ref: https://access.redhat.com/articles/15145 https://itnext.io/as-a-software-developer-why-should-you-care-about-the-monotonic-clock-7d9c8533595c https://donggeitnote.com/2021/06/23/clock/
    展开

    作者回复: 非常棒👍🏻

    
    9
  • 努力努力再努力
    2022-02-02
    总结: 1. 目标: 分布式系统中 时间尽量准确 2. 时钟的分类: 2.1 墙上时钟: 2.2 单调时钟: 3. 墙上时钟: 3.1 时间同步出现误差的原因:计算机内部用的是石英钟 不够准确,而墙上时钟的标准是计算机外部定义的 3.2 现有的解决方案: 3.2.1 计算机与 NTP 时间服务器定期通过网络同步 (受限于网络延时,至少35ms的误差) 3.2.2 GPS接收机 接收标准的墙上时钟 ,然后在机房内部通过 PTP进行同步(亚微妙级精度, 需要交换机支持PTP协议) 3.2.3 Google GPS接收机 接收标准的墙上时钟,通过机房内部去部署原子钟 (来防止GPS接收机的故障) 3.3 闰秒出现的原因 3.3.1 时间计量系统: 世界时和 原子时,他们之间发生了误差 3.4 闰秒的处理方式 3.4.1 linux系统上进行跳跃式调整 3.4.2 NTP服务上进行渐进式调整的 Slew模型 4. 单调时钟 4.1 墙上时钟是 绝对时钟 4.2 墙上时钟的比较是有误差的 不可信。相对时钟是 相对时钟 是 自己机器的,比较没有任何意义 5. 时间的管理 Q1 计算机系统是没有时间概念的,那么他怎么来计算与 管理时间 答: 通过时钟中断 内核周期性的更新系统的墙上时间和单调时钟 Q2 计算机系统可以 提供微妙甚至 纳秒,那么他怎么处理这么高精度的时间呢? 答: 目前系统定时器的中断频率为 1000Hz,在每次计算机启动的时候 会计算一次BogoMIPS BogoMIPS; 处理器在给定的时间内执行指令数,通过BogoMIPS值 计算机就可以得到非常小的精度了。 需要实践: 1. 交换机如果不支持PTP 协议 提示什么(不一定能实践,先记一下) 2. 3.2.3 怎么做到防止GPS接收机的故障的 思考题: 出现的原因:系统中年份 用的2位数字表示(计算机内核的问题) 怎么解决: 新主版用4位表示年 想到的 一个类似的事件是 2038年 mysql数据库 timestamp 超出的问题(字段的问题) 解决方法: timestamp 转换到 datetime 百度就有
    展开

    作者回复: 非常棒!

    共 2 条评论
    3
  • 静心
    2022-03-26
    感觉加餐内容很棒呀!

    作者回复: 😄

    
    1
  • wd
    2022-02-03
    这个主题非常棒。如果老师能够在正文中把这些重要概念的英文单词也列出来就更好了,这样的话如果需要学习英文文献的时候可以直接Google加深理解(看到前面网友在评论区已经贴出了一些英文原文,作为课程内容的补充来读,很有帮助)

    作者回复: 好的,后面再补上~

    
    1
  • peter
    2022-02-02
    请教老师一个问题: Q1:是否闰秒,是linux自己判断吗?还是从外部设备获取?

    作者回复: 闰秒是墙上时钟才有的概念,是从外部设备获取的,比如 NTP 服务器。

    
    1
  • springXu
    2022-02-02
    千年虫是上世纪由于历史上对年这个字段使用的是记录当年是用后两位来表示,如1995年是记成95的方式,当到了2000年时变成了00这样了,会产生问题。这个问题就是千年虫问题。 不知道我说的对不对?

    作者回复: 对的!

    
    1
  • 约书亚
    2022-04-12
    Linux是怎么知道UTC时间的呢?

    作者回复: 通过外部设置的,比如手动设置或者NTP同步。在设置好初值后,通过 Linux 内部的时钟中断来管理时间。

    
    
  • Ankhetsin
    2022-02-16
    chrony怎么样?

    作者回复: chrony 挺不错的

    
    
  • javaadu
    2022-07-03
    查到一篇不错的文章:http://gk.link/a/11ulp
    
    
  • 李志军
    2022-04-27
    UTC插入正闰秒时,怎么会跳秒?跳秒应该是负润秒
    
    