Distributed Systems: Synchronization - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Distributed Systems: Synchronization

Description:

Only need to recompile part of the app. Separate compilation. Libraries. Reuse? ... Okay, why split into header file and implementation file? ... – PowerPoint PPT presentation

Number of Views:20
Avg rating:3.0/5.0
Slides: 22
Provided by: Ken667
Category:

less

Transcript and Presenter's Notes

Title: Distributed Systems: Synchronization


1
Distributed SystemsSynchronization
  • CS 654Lecture 15November 6, 2006

2
C/C Source Code Organization
  • Why break code up into multiple files?
  • Ease of finding things?
  • Compilation speed.
  • Only need to recompile part of the app.
  • Separate compilation
  • Libraries
  • Reuse?
  • If I put a class separately into A.cpp, it is
    easy to move to another application.

3
  • Okay, why split into header file and
    implementation file? What (bad) things would
    happen if we did not?
  • For libraries, the case is clear.
  • Need declarations to tell the compiler how to
    call code.
  • What about your application? Why not put
    everything into A.cpp, like in Java?
  • Suppose B.cpp needs to use class A.
  • The compiler needs the declarations.
  • Why not just include the whole source file?
  • Why need header file if already linking the
    library?
  • Why need library if already have the header file?

4
  • What goes in a header file?
  • The minimum amount necessary for the
    implementation in a file (classes and/or
    standalone functions) to be used by other files.

5
A.hpp
B.hpp
C.hpp
includes
A.cpp
main.cpp
B.cpp
C.cpp
compiled to
A.o
main.o
B.o
C.o
link
a.out(exe)
Libraries
6
Mutual Exclusion
7
Mutual Exclusion
  • Prevent simultaneous access to a resource.
  • Two basic kinds
  • Token based.
  • Process with the token gets access.
  • Hard part is regenerating a lost token.
  • Permission based.

8
Centralized Algorithm
  • Use a central coordinator to simulate how it is
    done in a one-processor system.

9
A Centralized Algorithm
Step 2 Process 2 then asks permission to access
the same resource. The coordinator does not
reply.
  • Step 1 Process 1 asks the coordinator for
    permission to access a hared resource. Permission
    is granted.

Step 3 When process 1 releases the resource, it
tells the coordinator, which then replies to 2.
10
Distributed Hash Table
  • Nodes and names have keys, which are large
    integers. You get the key from the name by
    hashing. Nodes get keys (called IDs) by some way,
    usually just random.
  • Given a name, hash it to the key.
  • Now find the node that is responsible for that
    key. It is the node that has an ID gt key.

11
A Centralized Algorithm (2)
  • Process 2 then asks permission to access the same
    resource. The coordinator does not reply.

12
A Centralized Algorithm (3)
  • When process 1 releases the resource, it tells
    the coordinator, which then replies to 2.

13
Structured Peer-to-Peer Architectures (1)
  • The mapping of data items onto nodes in Chord.

14
Structured Peer-to-Peer Architectures (2)
  • Figure 2-8. (a) The mapping of data items onto
    nodes in CAN.

15
Distributed Hash Tables
  • Resolving key 26 from node 1 and key 12 from node
    28 in a Chord system.

16
A Decentralized Algorithm
  • Use a distributed hash table (DHT).
  • Hashes to a node.
  • Each resource has n coordinators (called replicas
    in the book). A limit m (gt n/2) is pre-defined.
  • A client acquires the lock by sending a request
    to each coordinator.
  • If it gets m permissions, then it gets it.
  • If a resource is already locked, then it will be
    rejected (as opposed to just blocking.)

17
n 5m 3
1. Send lock requests
2. Receive responses. Blue succeeds.
3. Release if failed.
18
Coordinator Failure
  • If a coordinator fails, replace it.
  • But what about the lock state?
  • This amounts to a resetting of the coordinator
    state, which could result in violating mutual
    exclusion.
  • How many would have to fail?
  • 2m - n
  • What is the probability of violation?

19
Probability of Violation
  • Let p be the probability of failure during some
    time ?t. The probability that k out of m
    coordinators reset is
  • To violate mutual exclusion, you need at least
    2m-n failures.
  • With node participation for 3 hours, ?t of 10
    seconds, and n 32 and m 0.75n, the
    probability of violation is less than 10-40.

20
A Distributed Algorithm
  • When a process wants a resource, it creates a
    message with the name of the resource, its
    process number, and the current (logical) time.
  • It then reliably sends the message to all
    processes and waits for an OK from everyone.
  • When a process receives a message
  • If the receiver is not accessing the resource and
    is not currently trying to access it, it sends
    back an OK message to the sender.
  • Yes, you can have it. I dont want it, so what
    do I care?
  • If the receiver already has access to the
    resource, it simply does not reply. Instead, it
    queues the request.
  • Sorry, I am using it. I will save your request,
    and give you an OK when I am done with it.
  • If the receiver wants to access the resource as
    well but has not yet done so, it compares the
    timestamp of the incoming message with the one
    contained in the message that it has sent
    everyone. The lowest one wins.
  • If the incoming message has a lower timestamp,
    the receiver sends back an OK.
  • I want it also, but you were first.
  • If its own message has a lower timestamp, it
    queues it up.
  • Sorry, I want it also, and I was first.
  • When done using a resource, send an OK to
    everyone.

21
Step 2
Step 1
Step 3
Accesses resource
Timestamp
Accesses resource
When process 0 is done, it sends an OK also, so 2
can now go ahead.
Process 0 has the lowest timestamp, so it wins.
  • Two processes (0 and 2) want to access a shared
    resource at the same moment.

22
Evaluation
  • How many messages are required? More or less than
    centralized?
  • One request and OK from everyone else, so 2(n-1).
  • More scalable? How much work per node, per lock?
  • Is it better than centralized? How many points of
    failure?
  • We have replaced a poor one with a worse one.
  • Can we figure out how to handle failure?

23
A Token Ring Algorithm
  • (a) An unordered group of processes on a network.
  • (b) A logical ring constructed in software.

24
  • When ring is initiated, give process 0 the token.
  • Token circulates around the ring in
    point-to-point messages.
  • When a process wants to enter the CS, it waits
    till it gets the token, enters, holds the token,
    exits, passes the token on.
  • Starvation?
  • Lost tokens?
  • Other crashes?

25
A Comparison of the Four Algorithms
Write a Comment
User Comments (0)
About PowerShow.com