How Computers Synchronize Their Clocks - NTP and PTP Explained

  Рет қаралды 48,736

Gary Explains

Gary Explains

2 жыл бұрын

It is important for computers to know the correct time. Everything from online shopping to stock market trades rely on accurate time keeping. But how do computers know what time it is? Here is a quick look at how computers synchronize their clocks including a look at NTP and PTP.
Introduction to Android app development: www.dgitacademy.com
Let Me Explain T-shirt: teespring.com/gary-explains-l...
Twitter: / garyexplains
Instagram: / garyexplains
#garyexplains

Пікірлер: 110
@JxH
@JxH 2 жыл бұрын
6:21 "...we'll talk about that in a minute..." 7:21 "What about network delay?" Exactly a minute later, as promised. Well played sir, very well played.
@samarthtandale9121
@samarthtandale9121 Жыл бұрын
Excellent Video Explanation !!!
@1MarkKeller
@1MarkKeller 2 жыл бұрын
The Professor = Time Lord: CONFIRMED!
@GaryExplains
@GaryExplains 2 жыл бұрын
🤣
@LinuxinaBit
@LinuxinaBit 2 жыл бұрын
Those atom clocks have gotten pretty cheap, LTT did a video about them, and it looks very interesting.
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, I have the same card as Linus. That will be in the next video in this series.
@monalisaray2616
@monalisaray2616 2 жыл бұрын
I agree
@eric.is.online
@eric.is.online 2 жыл бұрын
@@GaryExplains I suspected this was why you were laying such a solid foundation re: computer time
@herrbanane
@herrbanane 2 жыл бұрын
Have look at Jeff Gerling's video, it's pretty good too: kzbin.info/www/bejne/qoaTqXZnrtOUipo
@BakrAli10
@BakrAli10 2 жыл бұрын
What is the name of LTT’s video?
@JohnnieHougaardNielsen
@JohnnieHougaardNielsen 2 жыл бұрын
I'm also running a local NTP server on my network (on a machine doing other things too). One reason for that was to avoid my IoT devices (ESP8266 or ESP32) asking the public NTP servers for real time, instead getting synchronization from my local NTP server. Of course, my local server will synchronize with a public server, and in case of an outage, my IoT devices (running Tasmota) can also fall back to public NTP servers. Some home "routers" will do a similar thing to reduce network traffic.
@James_Knott
@James_Knott 2 жыл бұрын
I run pfsense for my firewall/router and have an NTP server running on it.
@JxH
@JxH 2 жыл бұрын
I have a 'radio controlled' wall clock, one of the very nice ones (UltrAtomic) using the newer PSK WWVB signal. Then I got a 2nd one and hung it up right next to the first, just so that I could enjoy their synchronicity. Typically they're within a very small fraction of a second, and tick in seemingly-perfect synchronization, which is strangely satisfying. Not bad radio performance for about 3400 km from the transmitter site near Fort Collins CO.
@vladislavkaras491
@vladislavkaras491 3 ай бұрын
Very greatly explained theme! Thanks!
@GaryExplains
@GaryExplains 3 ай бұрын
Glad it was helpful!
@gwen-cloud
@gwen-cloud 6 ай бұрын
An excellent lecture! Thanks a lot it helps a ton!
@GaryExplains
@GaryExplains 6 ай бұрын
Glad it was helpful!
@_..---
@_..--- 2 жыл бұрын
"that's how we might ask what is the time", lmao I hope not
@GaryExplains
@GaryExplains 2 жыл бұрын
I did say *might*! 🤣
@AjinkyaMahajan
@AjinkyaMahajan 2 жыл бұрын
Impressive explanation.
@GaryExplains
@GaryExplains 2 жыл бұрын
Glad you liked it!
@greg6094
@greg6094 2 жыл бұрын
NSW Australia are gold standard Great video btw!
@ArnabBose
@ArnabBose 2 жыл бұрын
Very nice video! So, basically, NTP is really the most natural way you would device to determine the offset to apply, if you assume that the latency is symmetric between the client and the time server. I suppose the reason for the symmetry assumption is that there's simply no way to deduce the asymmetry in the latency.
@youraverage90sguys7
@youraverage90sguys7 2 жыл бұрын
such great acting, oscar nomination worthy! lmao great stuff gary, keep it coming, really love your content!
@GaryExplains
@GaryExplains 2 жыл бұрын
Thanks!
@LotusFlowerrr
@LotusFlowerrr 2 жыл бұрын
:) thank you!
@1MarkKeller
@1MarkKeller 2 жыл бұрын
*GARY!!!* *Good morning Professor!* *Good morning fellow classmates!* Stay Safe Out There Everyone.
@GaryExplains
@GaryExplains 2 жыл бұрын
MARK!!!
@duanedsilva3573
@duanedsilva3573 2 жыл бұрын
Please do a detailed video on how PTP works, and its usecases
@Mosfet510
@Mosfet510 2 жыл бұрын
I was always interested in how it was kept, thanks!
@GaryExplains
@GaryExplains 2 жыл бұрын
Glad you enjoyed it!
@autohmae
@autohmae 2 жыл бұрын
6:35 I wonder what Low-Frequency Array (LOFAR) uses
@samarthtandale9121
@samarthtandale9121 Жыл бұрын
If the time taken to travel from client to server is different from server to client, then would it still give correct offset and round trip delay?
@bowzert
@bowzert 3 ай бұрын
The round trip delay will still be correct but not the offset, as it depends on the back and forth travel times being equal.
@SwissPGO
@SwissPGO 2 жыл бұрын
Hi Gary, I think there is a misrepresentation of stratum 0. If I understand you correctly, you represent statum 0 as the gps satellites, and that the stratum 1 servers obtain their time from those satellites. This is in my opinion incorrect: a stratum 1 server needs direct connection to the atomic clock, and it cannot rely on satellites as the timing signals from those satellites is impacted also by atmospheric conditions, clouds, air pressure etc... Each stratum 1 server is sitting really close to its atomic clock, and gets his time from these devices directly.
@GaryExplains
@GaryExplains 2 жыл бұрын
No. GNSS satellites have atomic clocks on board and are considered Stratum 0.
@SwissPGO
@SwissPGO 2 жыл бұрын
@@GaryExplains The satellite has indeed an atomic clock onboard, but it is Stratum 0 only for the satellite: any device on earth (or in space) reading the time signal cannot determine correct time (at high precision) without knowledge of the orbital parameters, the exact location of the receiver, and atmospheric conditions (temperature, pressure, humidity) along the signal path to the satellite. The parameters cannot be measured in the way you demonstrated on the NTP protocol, as GPS only transmits: it is not possible to measure the transmission delay based on roundtrip times. I assisted in the accurate determination of positions of scientific infrastructure to sub mm accuracy based on GPS signals: such measurements take long data acquisition times (hours) and require post processing of all the data, including atmospheric data in order to reach such level of precision. As such, I would personally not (yet) consider a GPS satellite (a single one) sufficiently accurate to be Stratum 0 time reference. But, I'm not a specialist in this field, and I welcome some inputs from specialist, with references to reliable technical documentation. After all, you may be correct Gary - I just have some doubts.
@amosreginaldjr.4200
@amosreginaldjr.4200 2 жыл бұрын
This is a channel that I would love to watch to pass time when I was 13. I’m 19 now and I’m very happy I came across it because now that I’m older I can understand the information provided
@Lexitivium
@Lexitivium 2 жыл бұрын
Where can I get one of those Gary Nest Hubs..? "Hey, Gary!" ;-)
@eyeshezzy
@eyeshezzy 2 жыл бұрын
Nice explanation Gary, Who pays the time servers?
@jonmclaughlin4128
@jonmclaughlin4128 2 жыл бұрын
Anyone can run a time server and make it publicly accessible(don't do that). Companies run them I know that Apple has a few, I assume Google does as well. You can get a list of public ones at: support.ntp.org/bin/view/Servers/WebHome
@sabriath
@sabriath 2 жыл бұрын
t1 and t2 are unreliable due to how networks can change on-the-fly, as well as the queued-in-force for network messages. The best you can hope for is all on the clientside, the less the server has to work, the faster you get a response. This means the client saves the time as T0, and when it receives the message back, it's T3.....there is an assumption that the average round trip will be twice the length of a one-way trip, so you take (T3-T0)/2 and that's your offset from the time you receive to set. The time it takes for the response is also unimportant, as it takes time for the client to also queue the data and calculate/set the time, so it's going to be off regardless. This formula works very well in dead-reckoning code to sync servers and clients.
@MegasXLR
@MegasXLR 2 жыл бұрын
The only Stratum I know is the car from GTA lmao
@user-kc1tf7zm3b
@user-kc1tf7zm3b 2 жыл бұрын
My Sony DAB+ clock radio is only 2 seconds slow to atomic time. Apparently, time syncing to the radio station only takes place when the DAB+ radio function is used. Otherwise, the internal quartz clock is in effect, which is drift just like any other clock. So, briefly listen to DAB+ radio every so often to keep the clock accurate.
@JxH
@JxH 2 жыл бұрын
I listen to BBC WS via XM Satellite radio (I'm in North America). BBC has those time signals at the top of the hour. It one case the time signal was about 20s slow (!) by the time the audio eventually made it through all the buffers and reached my ears. Comically bad. More recently it's more like 8-10s late.
@user-kc1tf7zm3b
@user-kc1tf7zm3b 2 жыл бұрын
@@JxH Or, one could very easily stream and cast BBC World Service with their smartphone. Now everyone around the world with a smartphone of some description can listen to the premiere world news service. 🇬🇧
@xeridea
@xeridea 2 жыл бұрын
The accuracy for setting on your home computer is probably within 5ms. If your latency is 10-80ms (depends on internet), it isn't 10-80ms off, since it calculates the trip time to consider. It also sends multiple packets to work out an average. Assuming your jitter isn't bad, it may even be within 1-2ms.
@BrockMak
@BrockMak 2 жыл бұрын
I still have the old ClocksSync app on my S10+, but it's no longer on Google play Store.
@James_Knott
@James_Knott 2 жыл бұрын
I noticed that too. You can get a app that backs up Android apps, so you can install them, even if no longer on GP.
@hansisbrucker813
@hansisbrucker813 2 жыл бұрын
Why doesn't my phone use GPS to get the time when I have that switched on? 🤔
@pilotavery
@pilotavery 2 жыл бұрын
It can and does.
@James_Knott
@James_Knott 2 жыл бұрын
@@pilotavery Actually, phones get there time from the cell network. My phone, anyway, won't let me sync to NTP, though my tablet does.
@TheDevil259
@TheDevil259 2 жыл бұрын
The skit at the start reminds me of Vault 103 in Fallout 3. You know, the one with the Gary clones.
@Michael_Brock
@Michael_Brock 2 жыл бұрын
Hopefully you can do a video on that open access atomic clock project that is spooling up for PCs and explain its advantages in certain circumstances. Linus showed it of but didn't really explain how a prosumer or small business could benefit from it properly, really only how big data, banks, social media etc can benefit. Believe it has an open source? Any way open access board plan which you can get a board manufacturer to make plus an atomic clock costing around 2,000$ plus the open source software to send timing signals to other PCs, single board PCE is the core of the hardware, you can synchronize computers on your network to a couple of nanoseconds rather than the milliseconds the current (baseline) software system does now software only. Plus it can grab it's master time (GMT etc) from one of the government clocks. IE UK or EU or USA etc all have these master clocks, then it will carry-on internally with minimal drift, correcting drift or leap seconds from the master clock as needed.
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, I have the same card as Linus. But really there is little benefit for a prosumer.
@petersilva037
@petersilva037 2 жыл бұрын
Interesting video. Please note that NTP does not make computers have the same time. Rather it makes clocks on computers run at the same speed. @3:53... servers in NTP do not synchronize with each other. They ask eachother what time their peer thinks the it is, and compare multiple such requests over time, and use this sampling to figure make the clocks run at the same rate. A server never sets it's time to match a server's, rather, it says... oh... comparing local and remote time stamps it tries to make them run at the same speed... so it might tweak the local clock to run a little faster. Typically, you need to set the time initially, and then use NTP to get the clock to run at closer to accurate rate with hints from the peers. Typically if NTP sees an offset of >1 second. it will just complain, it will not reset. You have to adjust such large offsets manually. Even with a large offset, NTP will try to keep the offsets consistent, and does not attempt to correct it.
@Turboinvesting
@Turboinvesting Жыл бұрын
Thanks for the wonderful video Gary. Could you care to make a video on the differences of System time between iPhone and Android devices? Any Time Sync app would show you that [once you do multiple measurements] iPhone system clock is much more accurate [ > 200 ms] than Android’s [ often off by more than 2 s ]. Even this anomaly applies to premium Android devices. I understand than Cell phones take the Date, Time and Time zone information from cell towers. Why then the iPhones would have better system time than Androids. Are iPhones also syncing to Apple NTP servers; while Androids do not.
@davidmurphy563
@davidmurphy563 2 жыл бұрын
Is the UK central stratum up in Derby, it is it maybe Rugby, I forget... Anyone know?
@GaryExplains
@GaryExplains 2 жыл бұрын
From 1950 until 1 April 2007 it was transmitted from Rugby, Warwickshire. The transmitter's original location meant that the clock was referred to as "the Rugby clock". Following its relocation in 2007 to Cumbria, the UK's National Physical Laboratory (NPL) now formally calls the signal "The Time from NPL".
@davidmurphy563
@davidmurphy563 2 жыл бұрын
@@GaryExplains Ah, I didn't know they stopped in 2007. No wonder I was struggling to recall, I was clearly rummaging through some very old memories!
@cmilkau
@cmilkau 2 жыл бұрын
A graphical explanation would have been nice. I picture it like two sticks, a long one client side spanning t0 to t3 and a short one server side spanning t1 to t2. The client then adjusts its clock so the middle of both sticks align in the timeline, basically assuming the delay is the same in both directions. The round-trip time (total time with packets inflight) is basically the time the client waited minus the time the server took, so the difference in length between the two sticks.
@Hagledesperado
@Hagledesperado 2 жыл бұрын
5:30 Kilometers is shortend "km", not "KM". When you write it with capital letters, it could be read as KelvinMega, which would be an ... interesting unit.
@alexlandherr
@alexlandherr 2 жыл бұрын
Stratum 0 are also ground based atomic clocks.
@James_Knott
@James_Knott 2 жыл бұрын
Actually, atomic clocks are not the only stratum 0 servers. A GPS receiver, which in turn is synced with something called "International Atormic Time" can also be a stratum 0 server. Then the NTP server connected to it is stratum 1, etc. Also, the old 2G CDMA cell phone network was accurate enough to be a stratum 0 source. It's a good idea to connect to at least 3 servers. One reason is for redundancy. If one fails, the others are still avaialble. Also, with 3, should one become inaccurate, it will be ignored. And, NTP averages the times from multiple servers, so the result is more accurate than any single source. I connect my NTP server to 3 stratum 1 sources and 2 stratum 2. BTW, cell phones get their time from the cell network. I don't know if they use NTP or some other protocol. Wikipedia has a good article on NTP. Does Anybody Really Know What Time It Is? kzbin.info/www/bejne/b3fddIqChK2Im9U Well, time to go! ;-)
@SalvatoreEscoti
@SalvatoreEscoti Жыл бұрын
So is the BIOS /UEFi Clock also synchronized via NTP? Is the OS telling the BIOS the right time?
@artem.boldariev
@artem.boldariev 2 ай бұрын
The OS.
@JxH
@JxH 2 жыл бұрын
Some of the time signal formats are poorly conceived. IIRC, WWVB (maybe GPS too?) only tells you the time after the top of the unit (minute, second). So the SW has to read in the date-time string, increment it by one unit, and then await the next unit pulse. I may be remembering some of this wrong; apologies in advance
@GaryExplains
@GaryExplains 2 жыл бұрын
GPS is every second.
@JxH
@JxH 2 жыл бұрын
Yep, the famous 1PPS. VLF Radio signals give the explicit absolute digital time code every minute. Ideally they'd give it in advance, and then "3, 2, 1, MARK!:"
@NoEgg4u
@NoEgg4u 2 жыл бұрын
How does Stratum 0 determine the time? Whatever the master clock is... how does that clock maintain its time, with accuracy down to the millisecond? A few years ago, I heard that aircraft carriers need timing accuracy down to the billionth of a second, in order to safely land airplanes on its deck. Do you know if that is true, and how they keep such accurate clocks?
@NoEgg4u
@NoEgg4u 2 жыл бұрын
@@James_Knott As it pertains to the atomic clocks around the world, that are used to obtain an average... How do each of those atomic clocks keep accurate time, such that they are suitable to be included for contributing to the average time? What is IAT?
@James_Knott
@James_Knott 2 жыл бұрын
@@NoEgg4u IAT is International Atomic Time, as I mentioned above. The cesium clocks they use are extremely precise for frequency. As for determining the actual time, it used to be based on stars, but they are no longer accurate enough. How it's done now is a longer story than suitable for here. Search for From Sundials to Atomic Clocks. It's a free download from NIST.
@user-kc1tf7zm3b
@user-kc1tf7zm3b 2 жыл бұрын
When will there be Gary Explains Covid video? 👨‍⚕️ ⚕️
@GaryExplains
@GaryExplains 2 жыл бұрын
I am not a doctor.
@MuhammadHanif-bx4pb
@MuhammadHanif-bx4pb 2 жыл бұрын
now how do we know the delay is accurate ??
@guilherme5094
@guilherme5094 2 жыл бұрын
Like.
@petermainwaringsx
@petermainwaringsx 2 жыл бұрын
If I've read it right, the assumption is that the delay is the same both ways?
@FriedEgg101
@FriedEgg101 2 жыл бұрын
I think my Casio watch is a stratum 1 device. It communicates with a satellite every night to synchronise itself.
@taidee
@taidee 2 жыл бұрын
So it’s time we talked about time 😂
@fjdkfdfjdf33
@fjdkfdfjdf33 2 жыл бұрын
Many routers run NTP servers
@johnlentokone7318
@johnlentokone7318 Жыл бұрын
I think this video is missleading. Gary says that the accuracy of NTP is eg. 50 ms, 80 ms and PTP is better than 1 us. I think this is impossible if NTP and PTP is tested in equivalent conditions.
@GaryExplains
@GaryExplains Жыл бұрын
Do you have a link to any testing that shows that this video is misleading?
@JxH
@JxH 2 жыл бұрын
9:23 "Offset....just take the absolute value." I'd suggest that the +/- of the offset is rather important... :-) e.g. "t3 + Offset" needs to include the sign of the Offset in case it's the other way around.
@piiumlkj6497
@piiumlkj6497 2 жыл бұрын
So basically NTP is just averaging the travel time of each leg of the trip , it assumes that they are equal , but if they are not ; it loses accuracy. I did the calculation and put different numbers for the time it took for the signal to get from the server to the client ( i assumed it to be 7 seconds ) and the result was 2.5 seconds off the correct time . Not that impressive !
@GaryExplains
@GaryExplains 2 жыл бұрын
Well, obviously I have show you the top level view. The actual algorithms are clever than that. Multiple messages are used, averages are taken over longer periods of time, plus there are some things to catch outliers etc.
@JohnnieHougaardNielsen
@JohnnieHougaardNielsen 2 жыл бұрын
Meanwhile, in the real world, 7 seconds would be an *extremely* long delay, about 100 times longer than what is already not that great. Still, NTP is not designed for microsecond accuracy.
@piiumlkj6497
@piiumlkj6497 2 жыл бұрын
@@JohnnieHougaardNielsen I realize that , and it seems that NTP is good enough , I just expected a fancier principle of operation .
@piiumlkj6497
@piiumlkj6497 2 жыл бұрын
@@GaryExplains I guess they don't call it a PROTOCOL for nothing !
@deconline1320
@deconline1320 2 жыл бұрын
Yes you are correct. What mainly screws up the time synchronization is network asymmetry (not the same path delay between both directions) and also the variations in travel time of the NTP/PTP packets. PTP provides ways to take into account these problems and generate more accurate results.
@ed-jf3xh
@ed-jf3xh 2 жыл бұрын
My computer doesn't ask. Or, more correctly, Windows 10 doesn't ask. I always have to update it via manual sync, even though it is set to auto sync. On Linux, it's always correct.
@fmphotooffice5513
@fmphotooffice5513 2 жыл бұрын
Some countries have a 30 minute offset.
@GaryExplains
@GaryExplains 2 жыл бұрын
Yes, but this video isn't about time zones.
@fmphotooffice5513
@fmphotooffice5513 2 жыл бұрын
@@GaryExplains ...just a trivial comment. I was surprised when I discovered that.
@JosuaKrause
@JosuaKrause 2 ай бұрын
hmm, the algorithm relies on each network request to take the same time. this isn't really true in the internet
@GaryExplains
@GaryExplains 2 ай бұрын
No it doesn't.
@JosuaKrause
@JosuaKrause 2 ай бұрын
@@GaryExplains do the math when choosing two different network delays. The final time on the client will be off by half the difference in delays
@GaryExplains
@GaryExplains 2 ай бұрын
There are four timestamps and a total round trip delay calculation. But the key is that the reply is timestamped at send and receive, as is the request.
@JosuaKrause
@JosuaKrause 2 ай бұрын
@@GaryExplains yes, the issue comes from asymmetric network delays which are not accounted for by this algorithm (among other things). PTP attempts to solve this using an additional Delay_Req step. But there can only ever be an approximate solution to this. But cheers, your video made me look up the details of PTP to figure out how the asymmetry is (attempted to be) resolved and how time syncing actually works
@FedJimSmith
@FedJimSmith 2 жыл бұрын
it's basic arithmetic guys.. so simple
@akarimsiddiqui7572
@akarimsiddiqui7572 2 жыл бұрын
Gary uses OnePlus
@anullhandle
@anullhandle 2 жыл бұрын
Don't do too deep a dive on this we'll never see you again lol. GPS time? UTC nist? USNO? International? UTC1? Atomic? Upcoming new (optical) definition of the second? We're approaching time resolution where gravity changes from the ground to the 2nd floor changing what a second is, matters. It's a deep rabbit hole.
@darin7553
@darin7553 2 жыл бұрын
I'm going to put a atom click in my pc
@lorenzomijorus
@lorenzomijorus 2 жыл бұрын
Sorry.... Do you have the time?
@bigbirdwpg
@bigbirdwpg 2 жыл бұрын
Too bad Microsoft can't figure out how to sync time properly.
@j_ribeiro
@j_ribeiro 2 жыл бұрын
please don't start making powerpoint stile videos. It's very annoying because I read it faster than you say it so I tend to pause the video, read it and then pass to the next slide so to speak. I like the usual format better
@GaryExplains
@GaryExplains 2 жыл бұрын
It isn't a case of "don't start", I have many videos in this style.
Put An Atomic Clock in Your PC - Open Source Time Card
11:57
Gary Explains
Рет қаралды 28 М.
How a PTP slave syncs with a PTP master
14:46
David Gessner
Рет қаралды 61 М.
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 117 МЛН
THEY made a RAINBOW M&M 🤩😳 LeoNata family #shorts
00:49
LeoNata Family
Рет қаралды 33 МЛН
Heartwarming: Stranger Saves Puppy from Hot Car #shorts
00:22
Fabiosa Best Lifehacks
Рет қаралды 21 МЛН
KINDNESS ALWAYS COME BACK
00:59
dednahype
Рет қаралды 136 МЛН
Can Paris fix its poop problem before the Olympics?
8:06
EVERYONE Needs to Learn a Little Bit of AWK!
16:29
Gary Explains
Рет қаралды 395 М.
Nanosecond clock sync with a Raspberry Pi
13:56
Jeff Geerling
Рет қаралды 170 М.
The NTP algorithm
29:22
Martin Walls
Рет қаралды 472
How do Digital and Analog Clocks Work?
15:36
Branch Education
Рет қаралды 387 М.
Arm vs RISC V- What You Need to Know
22:19
Gary Explains
Рет қаралды 301 М.
NTP, Easy as 1-2-3... Simplifying Network Time Protocol
12:10
Kevin Wallace Training, LLC
Рет қаралды 31 М.
Clock Recovery and Synchronization
17:38
All Electronics Channel
Рет қаралды 29 М.
Using GPS with PPS to synchronize clocks over the network
20:16
Linux Tech School
Рет қаралды 10 М.
How a quartz watch works - its heart beats 32,768 times a second
17:35
버블티로 체감되는 요즘 물가
00:16
진영민yeongmin
Рет қаралды 117 МЛН