Physical clocks What is time in the physical world. Earth revolves about the sun once per year Earth rotates on its axis once per day 1/24 day is hour, etc for min and sec But earth "day" isn't exactly the same all the time so now use atomic clocks to define one second to be the time for a cesium 133 atom to make 9,192,631,770 "transitions" We don't care about any of this really. For us the right time is that boradcast by the NIST on WWV (short wave radio) or via GEOS satelite. How do we get the times on machines to agree with NIST? Send a msg to to NIST (or a surrogate) asking for the right time and change yours to that one. How often? If you know 1. the max drift rate D (each machine drifts D from reality) 2. the max error you are willing to tollerate E can calculate how long L you can wait between updates. L = E / 2D If only one machine drifts (other is NIST) L = E/D HOMEWORK 11-3 Remind me to go over this next time. How change the time? Bad to have big jumps and bad to go backwards. So make an adjustment in how much you add at each clock tick. How do you send msg and get reply in zero (or even just "known in advance") time? You can't. See how long it took for reply to come back, subtract service time at NIST and divide by 2. Add this to the time NIST returns. What if you can't reach a machine known to be perfect (or within D)? Ask "around" for time Take average Broadcast result Eliminate outliers Try to contact nodes who can contact NIST or nodes who can contact nodes who can contact NIST. ---------------- Mutual Exclusion ---------------- Try to do mutual exclusion w/o shared memory Centralized approach Pick a process a coordinator (mutual-exclusion-server) To get access to CS send msg to coord and await reply. When leave CS send msg to coord. When coord gets a msg requesting CS it Replies if the CS is free Enter requesters name into waiting Q When coord gets a msg announcing departure from CS Removes head entry from list of waiters and replies to it The simplist soln and perhaps the best Distributed soln When you want to get into CS Send request msg to EVERYONE (except yourself) Include timestamp (logical clock!) Wait until receive OK from everyone When receive request If you are not in CS and don't want to be, say OK If you are in CS, put requester's name on list If you are not in CS but want to If your TS is lower, put name on list If your TS is higher, send OK When leave CS, send OK to all on your list Show why this works Homework 11-7 Token Passing soln Form logical ring Pass token around ring When you have the token can enter CS (hold token until exit) Comparison Centralized is best Distributed of theoretical interest Token passing good if HW is ring based (e.g. token ring) ---------------- Election ---------------- How do you get the coord for centralized alg above? Bully Algorithm Used initially and in general when any process notices that the process it thinks is the coord is not responding. Processes are numbered (e.g. by their addresses or names or whatever) The algorithm below determins the highest numbered process, which then becomes the elected member. Called the bully alg because the biggest wins. When a process wants to hold an election, It sends an election msg to all higher numbered processes If any respond, orig process gives up If none respond, it has won and announces election result to all processors (called coordinator msg in book) When receive an election msg Send OK Start election yourself Show how this works When a process comes back up, it starts an election. HOMEWORK 11-9 Ring algorithm (again biggest number wins) Form a (logical) ring When a proc wants a new leader Send election msg to next proc (in ring) include its proc # in msg If msg not ack'ed, send to next in ring When msg returns Election done Send result msg around the ring When req msg arrives Add your # to msg and send to next proc Only necessary if you are bigger than all there (I think) If concurrent elections occur, same result for all HOMEWORK 11-10