




























































































Studia grazie alle numerose risorse presenti su Docsity
Guadagna punti aiutando altri studenti oppure acquistali con un piano Premium
Questa pagina non è visibile nell’anteprima
Non perderti parti importanti!





























































































Coordinating a set of computational entities to solve a common task despite failures and unpredictable communication is
hard!
Definitions
A distributed system is a set of spatially separated entities , each of these with a certain computational power that
are able to communicate and to coordinate among themselves for reaching a common goal
A distributed system is one in which the failure of a computer you didn't even know existed can render your own
computer unusable (by Leslie Lamport)
Examples of a Distributed System
○ The world wide web: information, resource sharing
○ Clusters, Network of workstations
○ Distributed manufacturing systems (e.g. automated assembly line)
○ Network of branch office computers: Information system to handle automatic processing of orders
○ Network of embedded systems (e.g. redundant systems on airplanes)
P2P networks (BitTorrent) ○
○ Blockchain and Distributed Ledgers
Common points across definitions
○ Set of entities: computers, machines, software;
○ Distributed: spatially separated, independent.
○ Common Goal: communication, coordination, resource sharing
We will focus on static networks of processes - > static means that the links are fixed and that they can change only if a link
fails
Every process has the so called local view : everything that the process knows is known only by the messages that it receives
directly and undirectly
Failures are a problem, because if there are failures or unreliable communications the agreement problem is impossible to
solve
It's useful to create probabilistic solutions for limited failures - > the agreement problem is impossible to solve with a
deterministic solution that always works
All computer systems fail (sooner or later) - > It is a good design practice to build robust systems.
○ Failure detection - > Example: Checksum detects a corrupted packet
○ Failure masking - > Example: message retransmission, redundancy
○ Failure tolerance - > Example: intrusion tolerant systems
○ Failure Recovery
○ Failure forecasting
There are limits to the accuracy with which computers on a network can synchronize their clocks:
○ Network delays are not constant (or even bounded).
○ Clock drift cannot be known in a precise way.
lunedì 25 settembre 2023 14:
A fight against uncertainty
○ Asynchrony
○ Failures
Outcomes of the distributed system's theory
○ Chubby - google: distributed lock manager - > Used in MapReduce, BigTable, Google Filesystem.
○ Zookeeper - yahoo (now apache): Hadoop, Kafka.
○ Blockchains
Methodology
a. Formalize models
b. Make abstractions of the models
c. Write specifications
d. Build algorithms
We have n processes in with distinct identities, which identify the processes, where n is known by every
process
A process is a (possibly infinite) State Machine (I/O
Automaton).
○ Internal states q := set Q
○ Initial states := set Qi \subset Q
Messages := set of all possible messages M in the form
<sender, receiver, payload>
○ InBuf_j := multiset of delivered messages
OutBuf_j := multiset of ``inflight’’ messages (messages
sent but not delivered).
3 kinds of models
1. Asynchronous
Synchronous
▪ if there is fixed bound on the delay of messages
The execution can be built with timestamps if the processes are
synchonized by a global clock
3. Eventually synchronous
There is an adversary that schedule a set of events (scheduler) which decides the sequence of the events:
○ Delivery of a msg - > Del(m, i, j ) := move message m from OutBuff_i to InBuff_j
○ Execution of a local step - > Exec(i) := process i executes one step of its state machine.
Problem : if we do not force the scheduler to execute, the system can be stuck in time - > so if it doesn't create the delivery
event, the event will be infinite
An execution E is fair if each process p_i executes an infinite number of local computations (Exec(i) events are not finite) and
each message m is eventually delivered (is not possible to stall forever a message: there must exists a Del(m, x, y))
○ Eventually means that it happens, but we don't know when
A process can't sleep forever, but it has to execute something, since the scheduler will move all the actions to another
process
Given an execution E and a process p_j, we define has local execution (E|p_j) of p_j the subset of events in E that
``impact" p_j
We say that p_1 (and p_2) cannot
distinguish E from E’.
Two main models:
Byzantine Failure - > Byz(p_j) := after this event process p_j behaves in an arbitrary way (when we have Exec(j) we do not
follow anymore the automaton of p_j)
We indicate with f the maximum number of processes that can experience a failure event in an execution.
○ Usually we bound f - > Example: f cannot be more than n-1.
○ We never do assumptions on when a failure event happens - > we don't know the process in which the failure will happen
FL1 or Fair-Loss is a Liveness property
If p sent a message m, and q has not delivered it at time t, there is always hope that it can deliver it at
time t + Delta.
In a finate time p cannot send infinite messages
E = (e_1, e_2, e_3, e_4, e_5)
E’ = (e_1, e_2, e_3, e_4, e_5, del(p, q, m))
FL2 or Finite Duplication is a Liveness property
▪ It cannot be violated in finite execution
In a finate time p cannot send infinite messages
E = (del(p, q, m), del(p, q, m), del(p, q, m), …, del(p, q, m))
E’ = (del(p, q, m), del(p, q, m), del(p, q, m), …, del(p, q, m), e_1, e_2, e_3, ….)
Such that no e_j is del(p, q, m).
FL2 or At most-7 duplication
If a correct process p sends m a finite number of times to q, then q cannot deliver m more than 7 times
E=(del(p, q, m), del(p, q, m), del(p, q, m), del(p, q, m), del(p, q, m), del(p, q, m), del(p, q, m), del(p, q, m))
○ E cannot be extended, it always violates At-most7 duplication.
○ At-most7 duplication is a safety property.
Mutual Exclusion
if a process p is granted a resource r at time t, then no other process q is granted r at t ○
○ It is a safety property
No-deadlock
○ if r is not already granted, eventually someone get a grant on resource r
○ It is a liveness property
No-Starvation
if a process p request a grant on resource r, it will eventually get it ○
○ It is a liveness property
At most-f failures
○ An execution E can contain at most f failures
○ It is a safety property
It is mixing two aspects:
It should be decomposed in two properties:
Let us fix:
FL1 or Fair-loss: If a correct process p sends infinitely often m to a process q, then q
delivers m an infinite number of times.
FL2 or Finite duplication : If a correct process p sends m a finite number of times to q,
then q cannot deliver m an infinite number of times.
In SL1 or Stubborn-delivery: If a correct process p sends m to q, then q delivers m an infinite
number of times.
While we keep FL3 or No creation: If some process q delivers a message m with sender p,
then m was sent by p to q.
The pseudo code reflects a reactive computing model where
The input of a protocol is an event that can be handled by an handler ○
○ components of the same process communicate by exchanging events
○ the algorithm is described as a set of event handlers
○ handlers react to incoming events and possibly trigger new events.
Handlers are atomic: if an handler is activated, another handler can not be activated on the same piece of code,
but it has to wait the end of it
○ They can only be interrupted in case of a crash
Events:
○ Requests: <Send | q,m> send a message m to process q.
○ Indication: <Deliver, p,m> delivers message m from process p.
Properties:
○ SL1 or Stubborn-delivery: If a correct process p sends m to q, then q delivers m an infinite number of times.
○ FL3 or No creation: If some process q delivers a message m with sender p, then m was sent by p to q.
Send a message
infinitely because we
don't know the Pr of
loss of the link, so it
assure that at least one
message has to pass
Proof By contradiction
○ Suppose process q executing our algorithm receives message m that was not sent by p.
○ Fact 1 - > If q delivers a message, then it delivers here:
Fact 1 implies that fll, is delivering a message that was not sent by p ○
○ This implies that fll is not fair-lossy
○ This contradicts our hypothesis: fll is fair-lossy
In fact, if trigger <sl, Deliver | p, m> is executed, this means that <fll, Deliver | p, m> executed, but the
message m was not created by p, so it was created by fll that has No Creation property - > so it violates the
property and it is impossible
Proof By contradiction
○ Suppose q delivers m a finite number of times.
○ Fact 1 - > p sends m on fll an infinite number of times:
○ Fact 2 - > if q "stubborn delivers" m a finite number of times, then fll delivered m a finite number of times.
○ If a message is in the sent set, it won't be never removed
○ V iolates the FL1 because if a message is sent infinite times, it has to be delivered infinite times
Reason 2
▪ the delivery handler is never triggered with <p,m>
▪ If <sl, Deliver | p, m> is not executed, the sl don't send the message infinitely
▪ This means that sl is not stubborn, violating our hypothesis.
Show that our stubborn algorithm does not work if we change the first property in:
SL1 or Stubborn-delivery: If a process p sends m to q, then q delivers m an infinite number of times. {Pay attention
something is missing}.
Show that there is no algorithm that satisfies the property above using a fair-lossy link.
○ In the SL1 property the word "correct process" is missing
○ This means that a process p could crash
○ It is necessary to build an algorithm that sends a message that has to be delivered even if the process crashes
It is impossible to build it, since the process has to stay awake infinitely to see if eventually the message is delivered
even if it has crashed
Asynchronous:
○ There is no bound on the delay that a message can cumulate
○ No Global-clock - > you have only a local clock that can be used to order the events locally
No Bound on message delays ○
○ Local-computational steps, Exec, happen at unpredictable time thanks to the scheduler
○ Agreement Impossible and a lot of other things
○ Models Everything
1.
Synchronous:
There is a known bound on the delay that a message can cumulate ○
○ Es. If I send a message at time t, it has to be received by t+delta
○ There is a dealy, but the system can't be slower than this delay
○ Delays are bounded
You can synchronise clocks, up-to a certain precision ○
○ You can assume that local execution steps happen at certain predetermined interval, and that they take bounded time
○ Predetermined interval means that we can see that the execution follows some steps
○ Almost everything is possible
Models only restricted networks ○
2.
I cannot predict how long the spike in which the system is asynchronous will last and there will be a time in the future in which the
system will be synchronous forever
Are the largest possible since every execution
can be modeled by an asynchronous model
lunedì 2 ottobre 2023 14:
An hardware clock H is correct if its drift rate is within a limited bound of ρ > 0, since the real clock oscillates around a lower and
an upper bound (Es. 10
secs/sec).
It makes the clocks perfect but only one time
If we want to keep the Skew synchronize, we have to synchronize it with the drift-rate at any in time
Observation: what does slowing down a clock mean?
It is not possible to impose a clock value in past - > This action can violate the cause/effect ordering of the events produced by a
process and the time monotonicity.
○
Consequently we slow down clocks hiding interrupts - > Hiding interrupts, the local clock is not updated so that we have to hide
a number of interrupt equals to slowdown time divided by the interrupt period.
○
○ If we set a clock in the past, we will break algorithms that use clocks - > Fast clock have to be slowed down
Based on International Atomic Time: 1 sec = time a cesium atom needs for 9192631770 state transitions - > Physical clocks based on
atomic oscillators are the most accurate clocks (drift rate 10
)
UTC-signals come from shortwave radio broadcasting stations or from satellites (GPS) with an accuracy of
○ 1 msec for broadcasting stations
○ 1 μsec for GPS
Processes synchronize their clock C i
Clocks C i
We say that clocks C i
The difference between the time of the source S and the time of the clocks C i
All the processes synchronize their clocks C i
Let D > 0 be a synchronization bound and let C i
and C j
be the clocks at any two processes p i
and p j
Notes:
Clocks that are internally synchronized are not necessarily externally synchronized - > Es. even thought they agree with each
other, they drift collectively from the external time source.
○
A set of processes P, externally synchronized within the bound of D, is also internally synchronized within the bound of 2D. ○
○ This property directly follows from the definition of internal and external clock synchronization.
○ Externally synchonized within the bound of D => internally synchronized within the bound of 2D, but not viceversa
Synchonization by mean of time server
Centralized Time Service
Request-driven: Christian’s Algorithm for external synchronization ○
○ Broadcast-based: Berkeley Unix algorithm - Gusella & Zatti (1989) for internal synchronization
1.
2. Distributed Time Service (Network Time Protocol) - External synchronization algorithm - Use a time server S that receives a signal from an UTC source
Works (probabilistically) also in an asynchronous system
○ Is based on the measurement of message round trip times (RTTs)
○ Synchronization is reached only if RTTs are small with respect to the required accuracy
A process p asks the current time through a message m r
and receives t in m t
p sets its clock to t + T round
/2, T round
Notes:
○ A time server can crash
○ Cristian suggests to use a cluster of synchronized time servers
A time server can be attacked ○
Accuracy
○ Channels are not perfect
Case 1
▪ Reply time is greater than estimate (RTT/2)
▪ Assume it is equal to RTT-min
▪ It sets the clock in the past
○
Time service over Internet - > synchronizes clients with UTC
Reliability by mean of redundant servers and paths
Scalable
You are on a synchronous system, and you have a fair-lossy channel with the additional property:
Using such channel could you create a stronger version of perfect point2point? A version that gives you a bound on the
delivery time?
If the message is sent at time => the
property of timed delivery is violated since the
message cannot be delivered in time
You built a COUNTING SERVER that communicates with you using our Perfect-p2p algorithm over a stubborn link.
Assume that no one can crash and that the messages cannot be lost
The server stores a variable v (initially equal to 0) and it exposes three operations:
The server executes an operation when it delivers the corresponding message. As example, the increase happens when the
server sees the event <pl, Deliver | INC,client>.
You act as a client and you invoke exactly three operations in the following order: <pl, Send| INC, server>,<pl, Send| INC,
server>,<pl, Send| GET, server>.
You are really puzzled when, after a while, on your client you see <pl, Deliver, 1, server>. Startled, you asked again <pl, Send|
GET, server>. Unfortunately, you are still waiting for an answer.
Note that, there are two possible explanations, try to find both. (Hint: you can see one of the explanation by answering to the
question: How much will you wait for an answer?)
The two messages INC are identical so one messages is already in the delivered set and the second one cannot be
delivered
The messages are out of order
To fix problems I introduce timestamps or I add a sequence number on the messages following the order in which
they have been sent
○
○ If I receive message x + 1 before x, it stores x + 1 in a buffer and than executes it after the deliver of message x
○ It is called FIFO Link, where a Link is always something that happens between two rpocesses
P roperties:
Physical clock synchronization algorithms try to coordinate distributed clocks to reach a common value
○ They are based on the estimation of transmission delay but in several systems it could be hard to obtain a “good” estimation.
○ For several applications it is not important when things happened but in which order they happened
However in a Distributed System, each system has its own “logical clock” - > If clocks are not aligned it is not possible to order events
generated by different processes
Scenario: Distributed chat used in a mission critical workplace
Why distributed?
○ No central point of failure;
○ No server can stores encrypted copies of messages, no metadata records.
Asynchronous model: why?
○ Mission critical, it has to work even if the system loses synchrony
○ Es. adversary in some routers or broadcast storm
Lamport introduced the happened-before relation that captures the causal dependencies between events (causal order
relation)
We denote with → i
the ordering relation between events in a process p i
○
○ We denote with → the happened-before relation between any pair of event
Two events e and e’ are related by happened-before relation (e → e’) if:
Snd-rcv ordering:
○ e = send(m) is the event of sending a message m
○ e' = receive(m) is the event of receipt of the same message m
Logical Clock
mercoledì 4 ottobre 2023 11:
Notes:
The sequence e 1
, e 2
, …, e n
○ may not be unique
○ It may exists a couple of events <e 1 , e 2 > such that e 1 and e 2 are not in happened-before relation
If e 4
and e 3
○ are not in happened-before relation then they are concurrent (e4 || e3)
There is no total order: if two events are concurrent, they don't know about each other since there is not a sequence that
defines the execution
○
For any two events e x
and e y
in the execution history of a distributed system, either e x
→ e y
, e y
→ e x
or e y
|| e x
○ The happened-before relation is a poset
The Logical Clock, introduced by Lamport, is a
monotonically increasing software counting register
Each process p i
employs its logical clock Li to apply a
timestamp to events
i
(e) is the “logical” timestamp assigned, using the
logical clock, by a process pi to events e.
Property: If e → e’ => L(e) < L(e’) and the vicerversa is
not true
Observation:
The ordering relation obtained through logical
timestamps is only a partial order.
Consequently timestamps could not be sufficient
to relate two events
Since there isn't a path that define their
order and they don't know about each other
e
3
2
and e
5
3
are concurrent and if L(e
5
3
) > L(e
3
2
) => e
5
3
e
3
2
Rule 1: Each process p i
initializes its logical clock L i
When pi sends a message m
○ creates an event send(m)
increases L i
timestamps m with t = L i
Rule 2: When p i
receives a message m with timestamp t
Updates its logical clock L i
= max(t, L i
○ Produces an event receive(m)
Increases L i
Rule 1= increase by one, with respect to
timestamp of previous event on casual path
Rule 2= increase by at least one