使用 NTP 进行事件同步

发布于 2024-10-15 17:04:32 字数 415 浏览 1 评论 0原文

我想在两台(或更多)有线网络 Linux 机器之间同步两个事件。我可以使用 NTP 来执行此操作吗?

NTP似乎主要专注于同步到时间服务器,我需要两台机器相互同步。这里有一个细微的差别。例如,如果一台计算机距离时间服务器的跳数是第二台计算机的一半,如果我尝试直接将两台计算机相互同步而不是将两者同步到时间服务器,我可能能够获得更好的同步。

一个稍微不同的问题:如果我要使用 NTP,安排事件的最佳方式是什么? cronjob 还是 at 脚本?如果我要使用像这个这样的库,我可以获得更好的(亚秒)同步吗?

最后,有谁知道任何时间同步软件包适合将两台(或更多)机器同步在一起,而不一定同步到时间服务器。

感谢您的任何帮助。

I would like to synchronize two events between two (or more) wire networked Linux machines. Can I use NTP to do this?

NTP seems to be mostly focused on synchronizing to a time server, where I need two machines to be synchronized to each other. There is a subtle difference there. For example, if one machine is located half as many hops away as a second machine from the time server, I might be able to get better synchronization if I try to synchronize the two machines to each other directly instead of synchronizing both to a time server.

A slightly different question: If I were to use NTP, what would be the best way to schedule events? A cronjob or at script? Could I get better (sub second) synchronization if I were to use a library like this one.

Finally, does anyone know of any time synchronization software packages that are suited to synchronizing two (or more) machines together, not necessarily synchronizing to a time server.

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

时光礼记 2024-10-22 17:04:32

您可以尝试将一台机器委派为主机,将其余机器委派为从机。当同步事件发生时,主设备触发从设备开始。

同步仅受机器之间的延迟 (ping) 限制,您无需担心系统时钟的一致性。

You might try delegating one machine as the master, and the remaining machines as slaves. When the synchronized events should occur, the master triggers the slaves to commence.

The synchronization would be limited only by the latency (ping) between the machines, and you wouldn't need to worry about system clocks consistency.

相守太难 2024-10-22 17:04:32

主机之间的 ping 延迟差异是多少?协调进程之间什么样的启动时间差异适合您?将如何启动流程? Cron 非常不精确,并且还需要考虑进程的启动时间。

如果不同主机的 ping 时间差异很大,我会这样做。

  • 使用可靠的公共 NTP 服务器在事件发生前几分钟同步所有协调主机上的时钟。不过,对于频繁发生的事件,每天 3-4 次同步应该足够了。

  • 使用像 cron 这样的低精度调度程序,提前 2-3 分钟启动一个简单的包装器 shell 脚本,该脚本将 wait() 直到提前 15 秒事件。然后包装器脚本以高于正常的优先级启动 tagert 应用程序。

  • 应用程序加载(磁盘访问和动态链接很慢),读取所需的任何数据文件,进行所有耗时的计算等。然后它使用 usleep() 以亚秒精度等待开始时刻 和 ftime()gettimeofday(),放在 fireLasersAtTheMoon() 或您的目标操作之前。

显然,如此精确地同步本来就不精确的操作(例如网络通信)是没有意义的。如果您的网络具有可预测的延迟,您只需使用 ping 的往返时间来测量它,并在一台主机上创建一个主进程,通过 ssh 向其他主机发送启动命令,同时考虑延迟。

What is ping latency variation between your hosts? What kind of start time discrepancy between coordinated processes is ok for you? How are going to start processes? Cron is very imprecise, and startup time for processes needs to be accounted for, too.

If ping times to different hosts vary significantly, I'd do something like this.

  • Use a reliable public NTP server to synchronize clocks on all coordinated hosts a few minutes before the event. With frequent events, 3-4 synchronizations a day should be plenty enough, though.

  • Using a low-precision scheduler like cron, 2-3 minutes ahead of time, start a simple wrapper shell script that will wait() until e.g. 15 seconds before event. Then the wrapper script starts the tagert app, with higher-than-normal priority.

  • The app loads (disk access and dynamic linking is slow), reads whatever data files needed, makes all time-consuming calculations, etc. Then it waits until the start moment with subsecond precision using usleep() and ftime() or gettimeofday(), put right before the fireLasersAtTheMoon() or what happens to be your target action.

Obviously, it makes little sense to synchronize so precisely actions that are naturally imprecise, like network communication. If your network has predictable latency, you just measure it using round-trip times of ping and make a master process on one host to send a start command via ssh to other host(s) taking latency to account.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文