YTread Logo
YTread Logo

Network Time Protocol (NTP) - Computerphile

Mar 11, 2024
today we're looking at the

network

time

protocol

and this is how a couple of computers synchronize, well, actually, everyone, uh, potentially, I got into this, um, by accident, I met Dave Mills, who is the godfather or something like that. He did all the initial work and I think he's still involved. Sorry, I met him at a conference and he was telling me some stories about it, so when I got back home I thought okay, I have to play with This is because at the

time

we only had a few lightly

network

ed computers and it didn't really matter too much if they ran at the same time.
network time protocol ntp   computerphile
Everyone you know just looks at their wristwatch and writes down the time. That's enough, but there are some applications where you really need the time to be much closer, especially when you share file systems, so if one computer writes a file and puts a timestamp on it and the other looks at it, It's not so bad if this one is behind that one, but if Before that, this computer gets a little confused and says, well, it hasn't happened this time and some will make crazy decisions based on that, particularly with the make program that looks a lot. timestamps so Dave Mills came up with this process um to synchronize computers and I remember talking to him and thinking it's an interesting problem how to synchronize because if you go and talk to that computer and say what time you have and it comes up and He says you know it's 10 32 and 57 seconds or something like that you think well is that now or how long did it take to get from here to there if I do it again it could be different because it may come out faster or it may come more slow so um Anyway, that's where we started with this and, sorry, I had a beer with him or something.
network time protocol ntp   computerphile

More Interesting Facts About,

network time protocol ntp computerphile...

I forgot it was a long time ago, but anyway I thought it would be interesting to show how it all works. all based on an ntp package, so there is a 32 bit this, I think there are a lot of little flags and bits here that often appear in

protocol

s at the first bite that tell you I think this is the version and this one actually tells you where a leap second is happening today because it even deals with that and there's a stratum here and I think that's the version. I forget what's there but it's not that important, then there's other stuff but the key is some timestamps coming in so there's a T1 T2 null and there's also a T3 but that doesn't actually show up in it and then there are other things here that have to do with authentication and authorization, so if you need to make sure that you're not getting fake packets from places, so this didn't used to be in the first version because everyone trusted everyone in the past , but since then everyone has focused a lot more on security, so what do you do to synchronize clocks is that we have a client on the server and the client wants to synchronize with the server, so it sends a packet with its t0 which is uh this is my time, this is what I think is my time and as soon as I get to the server it marks it with T1, that's the service time, so this would be T1 minus t0, that's the time it took to get there. there, that would be if the clocks were correct, yes, but at this point they are not correct.
network time protocol ntp   computerphile
It's almost always like that, so it does some internal processing because it could be handling a lot of things and eventually it will send back a packet and it will put T2, which is my time when I sent this and when it arrives. Getting back to that, it records when you get back to T3 and you don't need to fill it in the protocol packet because you're done with that, so you can probably see that these two times on the same machine are relatively the same, you know, if you subtract T3 minus t0, so that's how long all of this took, but you can improve it by also removing T2 minus T1 because that's how long it took to process it and this gives you a pretty good estimate of the round trip minus the service processing and then the difference in the clocks is uh T1 minus t0 you know this is the service clock and my clock and you know that's equal to zero so they're synchronized it never does but you want to get closer and closer to that so I guess if it's negative is one way and if it's positive it's another way, then you have to set your clock and say oh, we're out for three or four seconds, so that's usually where you apply this clock. biased algorithm to say right, hold on, we're a little bit ahead, so keep taking instead of every second move forward one second, we'll keep going, you know, 0.99 of a second and eventually we'll get closer and closer to the real thing. now. a system call to do that, so that on certain Unix you still think that Windows has something similar so that you don't have these big jumps in time that, uh, time moves forward slowly and imperceptibly, but to make it even better, do this several times. and you also do it on multiple servers if you can so you get an idea of ​​the different times of the different servers and they should all be pretty close if everyone is playing the game, but on some of them you will get much better. uh, round trip times, but the most important thing is that in some of them you will get a very stable round trip time, so it doesn't vary.
network time protocol ntp   computerphile
You know, if one takes a second and then the next one is five seconds, you never know where you are. You have within the protocol or the protocol state machine a way to determine which is best and say well, this is a very good source of time, but it's moving around too much, so I'm not going to trust it. that the communication links are a shame, maybe it's in South America or somewhere like that, but this one isn't that good, but at least it's stable and this is where the stratum comes from on this street, so you can have 16 strata, I think what does it mean?
The stratum then means that stratum zero is a really good clock, so it's like an atomic clock or a GPS clock or something and stratum one is a computer that uses one of those to synchronize itself, so you never talk to a stratum. zero and stratum two is something that is synchronized to a stratum one and a Stratton three to be slightly away from the sources, yes, so all types of feed would prefer to be synchronized to a stratum one because you are closer. but this Jitter and the fact that a lot of the stratum one clocks are a little bit locked, don't trust anyone because otherwise everyone would sink into it, so you go back and forth between them how often is it.
This happens, uh, it happens pretty quickly initially, I think it's every minute, but once it calms down, it decides where it is, it slowly backs off until it's about every 10 minutes, it sends a packet and it's like, are you still right? because it is already synchronized, but no. We originally had connections over the Internet to a single place that had one or two Estrada things, so we set it up from that and then distributed it throughout the apartment because we only had a very thin cable at the time. Which was cool because you'd see Stratton One come in and we'd all be strata too because we were connected to that, but when you lose that connection, it's pretty interesting what happens, so each of the computers looks around and goes oh.
I lost that one, but there's a bunch of stratum twos around here, so I'll sync to one of those and everyone's like, "Oh yeah, there's a. I missed that, but there's a bunch of stratum twos, so I'll sync it to that like this." that makes me a three and this one says oh that was two minutes ago now it's a three so now I'm a four and this one says well that's a four one out so I'm a five so they move up to 16 and then they tap on that point and say well, yeah, there doesn't seem to be anything reliable anymore, so that's where they give up and how precise they are, it can be very, very precise.
It can certainly get down to milliseconds. or even better now. I think the protocol reduces it to microseconds. What are the things in my late night conversation with Dave Mills? He spent half his life? Think about looking at the clocks and seeing how they drifted, so when the UK first connected and started syncing, was watching some of the initial traffic through that and noticed that around five o'clock all the clocks started drifting and then as it re-synced around seven o'clock only for small amounts and this was because you know it's when everyone gets kicked out of work, they put the kettle on the mains, they pull up their suits and the 50 hertz signal slowly moves slightly as they try and maintain the level of the grid, but that influences the clocks, so the clocks will drift and then when the load decreases they increase it a little bit so that all the clocks go back a little bit, but he said, I can say, you know, I can say when are coronation streets. are holding on, I can tell when the adverts are on because I can see this Gap, so for those not in the UK, these are some sort of popular TV soap operas with a break halfway through where everyone ran out and They put the kettle on to heat. having a cup of tea, you know, being British so he could detect that he calculated them in a case where there was an earthquake in San Francisco, I think, and he said the clocks got a little spooky beforehand.
I could see them drifting. I wonder if I have earthquake detection through my eyes. I don't think he ever followed that, but there are some cases like that where he said, "You know," I could see strange things happening because I got this high level of precision and fun for robotics and problem solving. which one is you choosing the car 10 of your Trips take you 71 days die a b c and d and I tell you that die a has a value of 4. how much did you learn about the data set

If you have any copyright issue, please Contact