🎯 What is Peer-to-Peer Synchronization?
In this model, there is no central time server. Peers synchronize with each other to agree on a common time. This simulation uses a method where the peer with the faster clock slows down its clock rate temporarily to allow the slower peer to catch up.
🧮 Synchronization Algorithm
The simulation uses a simplified algorithm inspired by NTP:
- One peer sends a burst of packets to the other.
- For each packet, the round-trip time (RTT) and clock offset are calculated.
- The measurement with the smallest RTT is considered the most accurate.
- The offset from this best measurement is used to determine which peer is faster.
- The faster peer's clock is then slowed down by a small factor until the clocks are aligned.
Clock Offset: θ = ((T₁ - T₀) + (T₂ - T₃)) / 2
Round-trip Delay: δ = (T₃ - T₀) - (T₂ - T₁)
🎮 How to Use This Simulation
- Set Initial State: Adjust the "Peer 2 Initial Offset" to make one peer start ahead of the other. You can also give them different "Drift" rates.
- Start Simulation: Click "Start Simulation" to let the clocks run. They will drift apart based on their settings.
- Synchronize: Click "Synchronize Now" to initiate a packet exchange.
- Observe: Watch the "Activity Logs" to see the calculated offset. A popup will announce which peer is slowing down. The "Status" for that peer will also change to "Slowing Down".
- Analyze: Observe how the "Current Offset" decreases and converges toward zero after a synchronization event.
🔬 Experimental Observations
- Convergence: Watch how many sync events it takes for the clocks to become closely aligned.
- Drift Impact: Higher drift rates will cause the clocks to diverge faster, requiring more frequent synchronization.
- Network Effects: Increase RTT and RTT variation to see how network instability makes it harder to get an accurate offset measurement.