So, let us understand concepts related to timekeeping along with NTP and PTP.
Time synchronization is the process of improving the accuracy of a clock by aligning its time and frequency to a reference time standard.
The two well known time sync protocols for IP based networks are Network Time Protocol (NTP) and Precision Time Protocol (PTP). Precise timekeeping is a key attribute for many applications to accurately construct sequence of events that have occurred or is occurring in real time.
- NTP has time accuracy in millisecond.
- NTP implementations uses software time stamping for reception and user-space time stamping for transmission.
- It is a widely implemented industry standard for time synchronization.
- NTP has been around several decades, and has become cheaper, easy and robust.
- NTP is easier to implement as NTP clients are already included with any computers, servers or routers we buy.
- NTP can synchronize a clock to a wide range of time sources; from high-precision atomic clocks and GPS receivers to servers geographically distributed over the Internet.
- The NTP protocol uses a client-server model, with the clock that needs to be synchronized acting as the client, requesting one or more servers for timing information.
- NTP does provide fault tolerance. In fact, NTP does better here than PTP.
- The client gets time from all of NTP servers and ignores one which seems to be too far off in time compared to the other servers time.
- NTP is unicast, requires no special routing rules, and only the sender and intended recipient have to see or handle those packets.
NTP for Virtual machines:
- ESXi server has built-in NTP capability, including a port of the reference implementation and the necessary kernel APIs to support it.
- NTP operates on port number 123.
- NTP operates seamlessly inside virtual machines, as long as the guest OS has support for it and network connectivity to time servers is in place.
- Under most circumstances this should have no impact on time synchronization, except when life-cycle events disrupt guest execution for example suspending a VM.
- Another point to be considered, virtualization adds additional network layers like virtual NIC and virtual switch between the guest clock and the time servers.
- These additional software layers can potentially affect time synchronization variables.
PTP (IEEE 1588):
- PTP maintains microsecond accuracy of timing as it uses Hardware time stamping (NICs with PTP support and PTP time machines).
- PTP, defined by IEEE 1588-2008 works by exchanging messages between master clocks and slave clocks.
- Above diagram shows the exchange of messages between a PTP master clock and a PTP slave clock.
- The departure and arrival times of the Sync and Delay_Request messages are saved as the four timestamps T1-T4.
- The Follow_Up and Delay_Response messages are used to transport the timestamps recorded at the master clock to the slave clock, so that it has the information needed to adjust its time.
- At the end of these exchanges the slave clock has all four timestamps. So it calculates the offset of it’s clock with respect to the master as
- Offset = (T2 + T3 – T1 – T4) /2
- PTP is currently employed to synchronize financial transactions, mobile phone tower transmissions, sub-sea acoustic arrays, and networks that require precise timing.
- PTP does support fault tolerance.
- In the case of PTP, a slave synchronizes to a master clock, which other masters listen to.
- If active master goes down, the other master will take over. This is done using Best Master Clock(BMC) algorithm
- PTP is usually distributed as multicast. That can be a hassle to adminster because it can generate extra traffic and requires special rules to forward between network segments – especially between distant sites.
- PTP uses 2 UDP ports – 319 and 320.
PTP for Virtual machine:
- A precision clock is a virtual device that runs on a virtual machine and accesses the system time of a host.
- PTP provisions precise time synchronization for the virtual machines within a network.
- PTP was designed for local networks with broadcast/multicast transmission and, in ideal conditions, the system clock can be synchronized with sub-microsecond accuracy to the reference time.
- NTP was primarily designed for synchronization over the Internet using unicast (also can be used on local networks as well), where it can usually achieve accuracy in the single-digit millisecond range.
However, accuracy isn’t the only thing which matters. There are usually other criteria’s like resiliency and cost that need to be considered.
- PTP requires extra cost for setup and hardware, so if you are not using PTP already, then continuing with NTP would be a better option unless you have workloads that require PTP accuracy.
- While NTP can serve the majority of non critical workloads, PTP can serve the workloads that are time sensitive like in financial sector.
In order to get both accuracy and resiliency at the same time,
- Another case, PTP would be the primary source for synchronization of the clock when everything is working as expected. NTP would keep the PTP sources in check and allow for fallback between different PTP sources, or to NTP servers when all PTP sources fail.