两台远程计算机之间的(时钟)同步 [英] Synchronization (of clocks) between two remote computers

查看:157
本文介绍了两台远程计算机之间的(时钟)同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在考虑将简单的同步功能写入我的应用程序,并且出现的问题之一是两台远程计算机之间的时间同步,每台计算机都有自己的时钟(特别是关于文件/对象的修改日期) )。



我敢肯定,对此主题已经做了很多研究,并且不想太理论化,但是我想知道是否有例如,为了避免时区问题,开始时总是使用通用时间(UTC),这是开始时总是使用通用时间(UTC),但没有确保两台计算机的系统时间完全相同。幸运的是,我正在做的工作不是很细致,所以这不是一个非常重要的问题,但是我仍然很好奇。



一个解决方案是在两端始终使用相同的时钟,例如全局时间服务器,而不是本地系统时钟。大概这(与共享资源锁结合使用)可以保证同步时间不会意外重叠,但这不是很实用。



一个想到我的脑海里突然跳出来的想法是将每个节点(每个客户端)与在某个时间点之前计算出的偏移量进行同步,这也许是通过与全局时间服务器计算系统时钟的偏移量来实现的。这仅需要偶尔执行,因为偏移量本身在短期内不太可能发生很大变化。



更新:只需补充一点,我实际上并不希望同步两台计算机的系统时钟-我假设操作系统将在大多数情况下进行处理。这只是一个有关如何确保应用程序的两个实例使用同步时间的问题,尽管在当今这个时代,我认为系统时钟几乎可以肯定地同步到某个很小的增量内。

解决方案

像其他人所建议的那样依靠NTP进行应用很容易出错。正确的方法是使用Lamport的分布式时钟同步算法。 1978年经典论文时间,时钟,以及事件在分布式系统中的顺序


I'm looking into writing a simple synchronization ability into my app and one of the concerns that has popped up is synchronization of time between two remote computers, each with their own clock (in particular concerning the modification dates of files/objects).

I'm sure a lot of research has been done on this topic and don't want to get too theoretical, but I'm wondering if there are any accepted best practices for minimizing temporal discrepancies between remote clocks?

For example, a start is to always use universal time (UTC) as that avoids timezone problems, but there is no guarantee that two computers will have exactly the same system time. Luckily the work I'm doing isn't very fine-grained, so it's not a terribly important concern, but I'm still curious nonetheless.

One solution would be to always use the same clock on both ends, such as a global time server, rather than the local system clock. Presumably this (combined with shared resource locks) could guarantee no accidental overlap of synchronized time, but it's not very practical.

One thought that just popped into my head would be to synchronize each node (each client) with an offset calculated at some point prior, perhaps by calculating the offset of the system clock with a global time server. This would only need to be done occasionally as the offset itself would not likely change greatly over a short period of time.

Update: Let me just add that I'm not interested in actually synchronizing the system clocks of two computers--I'll presume that the operating system will handle this in most cases. This is just a question of how to ensure two instances of an application are using synchronized times, though in this day and age I suppose the system clocks would almost assuredly be synchronized to within some very small delta anyway.

解决方案

Relying on NTP for your application as others have recommended is the easy fudge. The correct approach is to use Lamport's distributed clock synchronization algorithm. It is explained in his classic 1978 paper Time, clocks, and the ordering of events in a distributed system.

这篇关于两台远程计算机之间的(时钟)同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆