SlideShare a Scribd company logo
BY
NANDAKUMAR P,
AP/CSE,
CAHCET
INTRODUCTION
In a centralized system: all processes reside on the
same system utilize the same clock.
In a distributed system: like synchronize everyone’s
watch in the classroom.
Time is monotonous
Time and Clocks
Measuring Time
Traditionally time measured astronomically
Transit of the sun (highest point in the sky)
Solar day and solar second
Problem: Earth’s rotation is slowing down
Days get longer and longer
300 million years ago there were 400 days in the year
Modern way to measure time is atomic clock
Based on transitions in Cesium-133 atom
Still need to correct for Earth’s rotation
Result: Universal Coordinated Time (UTC)
UTC available via radio signal, telephone line, satellite (GPS)
Global Time
Global Time is utilized to provide timestamps for
processes and data.
 Physical clock: concerned with “People” time
 Logical clock: concerned with relative time and
maintain logical consistency
Physical Clocks
There are two aspects:
Obtaining an accurate value for physical time
Synchronizing the concept of physical time
throughout the distributed system
These can be implemented using centralized
algorithms or distributed algorithms
Obtaining an Accurate Physical
Time
A physical time server is needed to access the
current time from a universal time coordinator
(UTC).
Two sources for UTC:
 WWV shortwave radio station in Ft. Collins,
Colorado
 Geostationary Operational Environmental
Satellites (GEOS)
Synchronizing Physical Time
The difference in time between two clocks due to
drifting is defined as clock skew.
As long as any and every two clocks differ by a value
less than the maximum skew value, the time service is
considered to be maintaining synchronization.
Skew between computer
clocks in a distributed system
How to synchronize two clocks in A
and B?
The information necessary to read the value must
be communicated across the network to location
B.
B’s clock value must be read.
B’s clock value is communicated back to location
A.
B’s clock value is adjusted to reflect the time
necessary to travel across the network.
B’s clock value is compared to A’s clock value.
Centralized Physical Time Services
Broadcast Based
Request Driven
Broadcast Based – first approach
The centralized time server’s action:
The physical time service broadcasts periodically the current time to
members of the distributed systems.
The participants’ action:
 If a given participant’s clock is ahead of the time server’s clock, the
participant slows down its clock so that it will continually move closer
to the accurate time.
 If a participant’s clock is behind the time server’s clock, the
participant moves its clock forward. Alternatives do include gradually
speeding up the clock.
Current time
= 720
Location A
Broadcast based
Time server
Current time=740
Delay of 10
Current time=720
Adjusted current time=750
New current time=750
Location A
Current time=720
Move forward=6
Location A
Current time=740
Adjusted location A
=730
Adjusted location B
=738
Average and the new
current time=736
Time Server
Current time=732
Slow clock down to
accommodate 2
Location B
1 1
2 2
4 5
1. Current time = 740
2. My current time = 720
3. My current time = 732
4. Adjust forward = 6
5. Adjust slowdown to accommodate 2
Delay=10 Delay=6
Current time=730
Adjusted time=750
New current time=750
Current time=740
Location A Timer Server
Request for
current time
Current time=740
Delay=10
Distributed Physical Time Service
Each location broadcasts its current time at predefined set
intervals.
Once a location has broadcast its time, it starts a timer. It
then collects time messages that it receives.
 Each time message that arrives is stamped with the local
current time.
This process continues until the timer expires.
Upon the expiration of the timer, each message is adjusted
to reflect the network delay time estimated for the
message source.
At this stage, the participant calculates the average time
according to one of the following approaches:
Calculate the average of all messages
720
724
726
718
722
723
Adjusted received times
Delete the times that are above the threshold and
then average the rest.
760 X
724
726
718
702 X
723
Adjusted received times
The numbers besides X are deleted.
The rest are averaged.
Discard the highest x and the lowest x values and
then average
760 X
724
726
718
702 X
723
703 X
765 X
Adjusted received times
Logical Clocks
Why Logical Clocks?
It is difficult to utilize physical clocks to order events
uniquely in distributed systems.
The essence of logical clocks is based on the
happened-before relationship presented by Lamport.
Happen-Before Relationship
If two events, a and b, occurred at the same
process, they occurred in the order of which they
were observed. That is, a > b.
If a sends a message to b, then a > b. That is, you
cannot receive something before it is sent. This
relationship holds regardless of where events a
and b occur.
The happen-before relationship is transitive. If a happens before b and
b happens before c, then a happens before c. That is, if a > b and b > c,
then a > c.
Logical Ordering
 If T(a) is the timestamp for event a, the following relationships must hold in a
distributed system utilizing logical ordering.
If two events, a and b, occurred at the same
process, they occurred in the order of which they
were observed. That is T(a) > T(b).
If a sends a message to b, then T(a) > T(b).
If a happens before b and b happens before c, T(a)
> T(b), T(b) > T(c), and T(a) > T(c).
Process 1
Process 2
Process 3
A B
C D
E F
A>B>C>D>F E
Lamport’s Algorithm
Each process increments its clock counter
between every two consecutive events.
If a sends a message to b, then the message must
include T(a). Upon receiving a and T(a), the
receiving process must set its clock to the greater
of [T(a)+d, Current Clock]. That is, if the
recipient’s clock is behind, it must be advanced to
preserve the happen-before relationship. Usually
d=1.
Process 1
Process 2
Process 3
A(1) B(2)
C(3) D(4)
E(1) F(5)
Process 1
Process 2
Process 3
A(1.1) B(2.1)
D(4.2)
E(1.3) F(5.3)
C(3.2)
A>E>B>C>D>F
Mutual Exclusion
In single-processor systems, critical regions are
protected using semaphores, monitors, and similar
constructs.
In distributed systems, since there is no shared
memory, these methods cannot be used.
A Centralized Algorithm
Advantages: It is fair, easy to implement, and requires only three
messages per use of a critical region (request, grant, release).
Disadvantages: single point of failure.
coordinator
process Request
Grant
Enter crical
section
Exit
Release
REQ
REQ REQ
REQ
OK OK
Algorithm Messages
per entry/exit
Delay
before entry
Problems
Centralized 3 2 Coordinator crash
Distributed 2(n-1) 2(n-1) Crash of any process
Token ring 1 to ∞ 0 to n-1 Lost token, process
crash
Election Algorithm
The bully algorithm
When a process notices that the coordinator is no
longer responding to requests, it initiates an
election. A process, P, holds an election as follows:
P sends an ELECTION message to all processes
with higher numbers.
If no one responds, P wins the election and
becomes coordinator.
If one of the higher-ups answers, it takes over. P’s
job is done.
7
1
2
45
36 Election
7
1
2
45
36
Ok
7
1
2
45
36
Election
7
1
2
45
36 Ok
7
1
2
45
36
Coordinator
A Ring Algorithm
1
2
4
5
3
7
6
2
2 3
2 3 42 3 4 5
2 3 4 5 6
2 3 4 5 6 1
6
Atomic Transactions
All the synchronization techniques we have studied
so far are essentially low level, like semaphores.
What we would really like is a much higher-level
abstraction such as atomic transaction.
For Example
 Atomic bank transactions:
1. Withdraw(amount, account1)
2. Deposit(amount, account2)
Stable Storage
Stable storage is designed to survive anything except
major calamities such as floods and earthquakes.
Stable storage can be implemented with a pair of
ordinary disks.
Stable storage is well suited to applications that
require a high degree of fault tolerance, such as
atomic transactions.
s a
o h
t f
b w
s a
t f
b w
s a’
o h
t f
b w
s a
t f
b w
s a
o h
t f
b w
s a
t f
b w
Stable storage
Stable storage Stable storage
Drive 1
Drive 2
(a) Stable storage (b) Crash after drive 1 is updated © Bad spot
Transaction Primitives
 1 BEGIN_TRANSACTION: Mark the start of a transaction.
 2 END_TRANSACTION: Terminate the transaction and try to commit.
 3 ABORT_TRANSACTION: Kill the transaction; restore the old values.
 4 READ: Read data from a file (or other object).
 5 WRITE: Write data to a file (or other object).
 For example,
 BEGIN_TRANSACTION
 reserve Austin-Houston;
 reserve Houston-Los Angeles;
 reserve Los Angeles-Seatle;
 END_TRANSCATION
Properties of Transactions
 Atomic: To the outside world, the transaction
happens indivisibly.
Consistent: The transaction does not violate system
invariants.
 Isolated: Concurrent transactions do not interfere
with each other.
 Durable: Once a transaction commits, the changes
are permanent.
Isolated or serializable
Isolated or serializable means that if two or more
transactions are running at the same time, to each of
them and to other processes, the final result looks as
though all transactions ran sequentially in some
(system dependent) order.
An Example
 BEGIN_TRANACATION
 X = 0;
 X=X+1;
 END_TRANSACTION
 (a)
 BEGIN_TRANSACTION
 X=0;
 X= X+2;
 END_TRANSACTION
 (b)
 BEGIN_TRANSACTION
 X=0;
 X=X+3;
 END_TRANSACTION
 (c )
Schedule 1 x=0; x=x+1; x=0; x=x+2; x=0; x=x+3; legal
Schedule 2 x=0; x=0; x=x+1; x=x+2; x=0; x=x+3; legal
Schedule 3 x=0; x=0; x=x+1; x=0; x=x+2; x=x+3; illegal
Nest Transactions
Transactions may contain subtransactions, often
called nested transactions.
If the subtransaction commits and the parent
transaction aborts, the permanence applies only to
top-level transactions.
Implementation
Private Workspace
1 02
0
1
2
1 02 1 2
Index
0’ 3’ 0 3
Index
Index
0
1
2
0’
1
2
3’
0
1
2
3
Private workspace
Writeahead log
x=0;
y=0;
BEGIN_TRANSACTION
x=x+1; log: x=0/;
y=y+2; log: x=0/1; y=0/2;
x=y * y; log: x=0/1; y=0/2; x=1/4;
END_TRANSACTION
Achieving atomic commit in a
distributed system
Two-Phase Commit Protocol
Coordinator Subordinates
Write “Prepare” in the log
Send “Prepare” message
Write “Ready” in the log
Send “Ready” message
Collect all replies
Phase 1
Phase 2
Write log record (if all are ready, commit; if not, abort)
Send “Commit” message
Write “Commit” in the log
Commit
Send “Finished” message
Concurrency Control
When multiple transactions are executing
simultaneously in different processes, some
mechanism is needed to keep them out of each
other’s way.
That mechanism is called a concurrency control
algorithm.
Concurrency control algorithms
 Locking
 In the simplest form, when a process needs to
read or write a file (or other object) as part of a
transaction, it first locks the file.
 Distinguishing read locks from write locks.
 The unit of locking can be an individual record
or page, a file, or a larger item.
Two-phase locking
The process first acquires all the locks it needs
during the growing phase, then releases them
during the shrinking phase.
In many systems, the shrinking phase does not
take place until the transaction has finished
running and has either committed or aborted.
This policy is called strict two-phase locking.
Time
Growing phase Shrinking phase
Lock point
Number
of locks
Optimistic Concurrency Control
 A second approach to handling multiple transactions
at the same time is optimistic concurrency control.
 The idea is simple: just go ahead and do whatever you
want to, without paying attention to what anybody else
is doing. If there is a problem, worry about it later.
Timestamps
TRD TWR T
(α) (α) (β)
TWR TRD T
(α) (α) (β)
Write
TRDT
(γ)(β)
TWRT
(γ)(β)
Do tentative
write
Abort
AbortDo tenative
write
TWRT
(γ)(β)
TTENTT
(γ)(β)
Abort
Read
T
(α) (β)
TTENT
(γ)(α)
TWR
T
(β)
TWR
Ok
Wait
Abort
THANK YOU

More Related Content

What's hot

Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed systemSunita Sahu
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemorySHIKHA GAUTAM
 
Key management and distribution
Key management and distributionKey management and distribution
Key management and distributionRiya Choudhary
 
Real Time Systems
Real Time SystemsReal Time Systems
Real Time SystemsDeepak John
 
Distributed Systems Real Life Applications
Distributed Systems Real Life ApplicationsDistributed Systems Real Life Applications
Distributed Systems Real Life ApplicationsAman Srivastava
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed SystemsArsnet
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systemsReza Gh
 
Hidden & exposed terminal problem
Hidden & exposed terminal problemHidden & exposed terminal problem
Hidden & exposed terminal problemVirendraKhatarkar
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems Haitham Ahmed
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating SystemsDr Sandeep Kumar Poonia
 
Locks In Disributed Systems
Locks In Disributed SystemsLocks In Disributed Systems
Locks In Disributed Systemsmridul mishra
 

What's hot (20)

Clock synchronization in distributed system
Clock synchronization in distributed systemClock synchronization in distributed system
Clock synchronization in distributed system
 
Agreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared MemoryAgreement Protocols, distributed File Systems, Distributed Shared Memory
Agreement Protocols, distributed File Systems, Distributed Shared Memory
 
Key management and distribution
Key management and distributionKey management and distribution
Key management and distribution
 
Distributed deadlock
Distributed deadlockDistributed deadlock
Distributed deadlock
 
Real Time Systems
Real Time SystemsReal Time Systems
Real Time Systems
 
Distributed Systems Real Life Applications
Distributed Systems Real Life ApplicationsDistributed Systems Real Life Applications
Distributed Systems Real Life Applications
 
Web Security
Web SecurityWeb Security
Web Security
 
Chapter 6 os
Chapter 6 osChapter 6 os
Chapter 6 os
 
Global state recording in Distributed Systems
Global state recording in Distributed SystemsGlobal state recording in Distributed Systems
Global state recording in Distributed Systems
 
Distributed web based systems
Distributed web based systemsDistributed web based systems
Distributed web based systems
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
Hidden & exposed terminal problem
Hidden & exposed terminal problemHidden & exposed terminal problem
Hidden & exposed terminal problem
 
Security in distributed systems
Security in distributed systems Security in distributed systems
Security in distributed systems
 
Octave
OctaveOctave
Octave
 
8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems8. mutual exclusion in Distributed Operating Systems
8. mutual exclusion in Distributed Operating Systems
 
Simulated annealing
Simulated annealingSimulated annealing
Simulated annealing
 
Embedded os
Embedded osEmbedded os
Embedded os
 
Locks In Disributed Systems
Locks In Disributed SystemsLocks In Disributed Systems
Locks In Disributed Systems
 
4. system models
4. system models4. system models
4. system models
 
Cloud Reference Model
Cloud Reference ModelCloud Reference Model
Cloud Reference Model
 

Similar to CS6601-Unit 4 Distributed Systems

Similar to CS6601-Unit 4 Distributed Systems (20)

Synchronization in distributed computing
Synchronization in distributed computingSynchronization in distributed computing
Synchronization in distributed computing
 
Chap 5
Chap 5Chap 5
Chap 5
 
Clock.pdf
Clock.pdfClock.pdf
Clock.pdf
 
Chapter 6 synchronization
Chapter 6 synchronizationChapter 6 synchronization
Chapter 6 synchronization
 
clock synchronization in Distributed System
clock synchronization in Distributed System clock synchronization in Distributed System
clock synchronization in Distributed System
 
3. syncro. in distributed system
3. syncro. in distributed system3. syncro. in distributed system
3. syncro. in distributed system
 
Distributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.pptDistributed system TimeNState-Tanenbaum.ppt
Distributed system TimeNState-Tanenbaum.ppt
 
Chapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.pptChapter 5-Synchronozation.ppt
Chapter 5-Synchronozation.ppt
 
6.Distributed Operating Systems
6.Distributed Operating Systems6.Distributed Operating Systems
6.Distributed Operating Systems
 
Os3
Os3Os3
Os3
 
Distributed System by Pratik Tambekar
Distributed System by Pratik TambekarDistributed System by Pratik Tambekar
Distributed System by Pratik Tambekar
 
Chapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.pptChapter 6-Synchronozation2.ppt
Chapter 6-Synchronozation2.ppt
 
Lesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptxLesson 05 - Time in Distrributed System.pptx
Lesson 05 - Time in Distrributed System.pptx
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Distributed computing time
Distributed computing timeDistributed computing time
Distributed computing time
 
Chapter 10
Chapter 10Chapter 10
Chapter 10
 
Distributed System
Distributed SystemDistributed System
Distributed System
 
Ch17 OS
Ch17 OSCh17 OS
Ch17 OS
 
OS_Ch17
OS_Ch17OS_Ch17
OS_Ch17
 
OSCh17
OSCh17OSCh17
OSCh17
 

More from Nandakumar P

UNIT - 5: Data Warehousing and Data Mining
UNIT - 5: Data Warehousing and Data MiningUNIT - 5: Data Warehousing and Data Mining
UNIT - 5: Data Warehousing and Data MiningNandakumar P
 
UNIT - 4: Data Warehousing and Data Mining
UNIT - 4: Data Warehousing and Data MiningUNIT - 4: Data Warehousing and Data Mining
UNIT - 4: Data Warehousing and Data MiningNandakumar P
 
UNIT 3: Data Warehousing and Data Mining
UNIT 3: Data Warehousing and Data MiningUNIT 3: Data Warehousing and Data Mining
UNIT 3: Data Warehousing and Data MiningNandakumar P
 
UNIT 2: Part 2: Data Warehousing and Data Mining
UNIT 2: Part 2: Data Warehousing and Data MiningUNIT 2: Part 2: Data Warehousing and Data Mining
UNIT 2: Part 2: Data Warehousing and Data MiningNandakumar P
 
UNIT 2: Part 1: Data Warehousing and Data Mining
UNIT 2: Part 1: Data Warehousing and Data MiningUNIT 2: Part 1: Data Warehousing and Data Mining
UNIT 2: Part 1: Data Warehousing and Data MiningNandakumar P
 
UNIT - 1 Part 2: Data Warehousing and Data Mining
UNIT - 1 Part 2: Data Warehousing and Data MiningUNIT - 1 Part 2: Data Warehousing and Data Mining
UNIT - 1 Part 2: Data Warehousing and Data MiningNandakumar P
 
UNIT - 1 : Part 1: Data Warehousing and Data Mining
UNIT - 1 : Part 1: Data Warehousing and Data MiningUNIT - 1 : Part 1: Data Warehousing and Data Mining
UNIT - 1 : Part 1: Data Warehousing and Data MiningNandakumar P
 
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONUNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONNandakumar P
 
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONUNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONNandakumar P
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON Nandakumar P
 
Python Course for Beginners
Python Course for BeginnersPython Course for Beginners
Python Course for BeginnersNandakumar P
 
Unit-4 Professional Ethics in Engineering
Unit-4 Professional Ethics in EngineeringUnit-4 Professional Ethics in Engineering
Unit-4 Professional Ethics in EngineeringNandakumar P
 
Unit-3 Professional Ethics in Engineering
Unit-3 Professional Ethics in EngineeringUnit-3 Professional Ethics in Engineering
Unit-3 Professional Ethics in EngineeringNandakumar P
 
Naming in Distributed Systems
Naming in Distributed SystemsNaming in Distributed Systems
Naming in Distributed SystemsNandakumar P
 
Unit 3.1 cs6601 Distributed File System
Unit 3.1 cs6601 Distributed File SystemUnit 3.1 cs6601 Distributed File System
Unit 3.1 cs6601 Distributed File SystemNandakumar P
 
Unit 3 cs6601 Distributed Systems
Unit 3 cs6601 Distributed SystemsUnit 3 cs6601 Distributed Systems
Unit 3 cs6601 Distributed SystemsNandakumar P
 
Professional Ethics in Engineering
Professional Ethics in EngineeringProfessional Ethics in Engineering
Professional Ethics in EngineeringNandakumar P
 

More from Nandakumar P (17)

UNIT - 5: Data Warehousing and Data Mining
UNIT - 5: Data Warehousing and Data MiningUNIT - 5: Data Warehousing and Data Mining
UNIT - 5: Data Warehousing and Data Mining
 
UNIT - 4: Data Warehousing and Data Mining
UNIT - 4: Data Warehousing and Data MiningUNIT - 4: Data Warehousing and Data Mining
UNIT - 4: Data Warehousing and Data Mining
 
UNIT 3: Data Warehousing and Data Mining
UNIT 3: Data Warehousing and Data MiningUNIT 3: Data Warehousing and Data Mining
UNIT 3: Data Warehousing and Data Mining
 
UNIT 2: Part 2: Data Warehousing and Data Mining
UNIT 2: Part 2: Data Warehousing and Data MiningUNIT 2: Part 2: Data Warehousing and Data Mining
UNIT 2: Part 2: Data Warehousing and Data Mining
 
UNIT 2: Part 1: Data Warehousing and Data Mining
UNIT 2: Part 1: Data Warehousing and Data MiningUNIT 2: Part 1: Data Warehousing and Data Mining
UNIT 2: Part 1: Data Warehousing and Data Mining
 
UNIT - 1 Part 2: Data Warehousing and Data Mining
UNIT - 1 Part 2: Data Warehousing and Data MiningUNIT - 1 Part 2: Data Warehousing and Data Mining
UNIT - 1 Part 2: Data Warehousing and Data Mining
 
UNIT - 1 : Part 1: Data Warehousing and Data Mining
UNIT - 1 : Part 1: Data Warehousing and Data MiningUNIT - 1 : Part 1: Data Warehousing and Data Mining
UNIT - 1 : Part 1: Data Warehousing and Data Mining
 
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONUNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 5 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHONUNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT - 2 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
UNIT-1 : 20ACS04 – PROBLEM SOLVING AND PROGRAMMING USING PYTHON
 
Python Course for Beginners
Python Course for BeginnersPython Course for Beginners
Python Course for Beginners
 
Unit-4 Professional Ethics in Engineering
Unit-4 Professional Ethics in EngineeringUnit-4 Professional Ethics in Engineering
Unit-4 Professional Ethics in Engineering
 
Unit-3 Professional Ethics in Engineering
Unit-3 Professional Ethics in EngineeringUnit-3 Professional Ethics in Engineering
Unit-3 Professional Ethics in Engineering
 
Naming in Distributed Systems
Naming in Distributed SystemsNaming in Distributed Systems
Naming in Distributed Systems
 
Unit 3.1 cs6601 Distributed File System
Unit 3.1 cs6601 Distributed File SystemUnit 3.1 cs6601 Distributed File System
Unit 3.1 cs6601 Distributed File System
 
Unit 3 cs6601 Distributed Systems
Unit 3 cs6601 Distributed SystemsUnit 3 cs6601 Distributed Systems
Unit 3 cs6601 Distributed Systems
 
Professional Ethics in Engineering
Professional Ethics in EngineeringProfessional Ethics in Engineering
Professional Ethics in Engineering
 

Recently uploaded

Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...Denish Jangid
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxShajedul Islam Pavel
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxRaedMohamed3
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfbu07226
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfDr. M. Kumaresan Hort.
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportAvinash Rai
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaasiemaillard
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPCeline George
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxJenilouCasareno
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsCol Mukteshwar Prasad
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxEduSkills OECD
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfYibeltalNibretu
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePedroFerreira53928
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfjoachimlavalley1
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringDenish Jangid
 

Recently uploaded (20)

Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...Basic Civil Engineering Notes of Chapter-6,  Topic- Ecosystem, Biodiversity G...
Basic Civil Engineering Notes of Chapter-6, Topic- Ecosystem, Biodiversity G...
 
NCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdfNCERT Solutions Power Sharing Class 10 Notes pdf
NCERT Solutions Power Sharing Class 10 Notes pdf
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdfINU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
INU_CAPSTONEDESIGN_비밀번호486_업로드용 발표자료.pdf
 
Advances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdfAdvances in production technology of Grapes.pdf
Advances in production technology of Grapes.pdf
 
The Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve ThomasonThe Art Pastor's Guide to Sabbath | Steve Thomason
The Art Pastor's Guide to Sabbath | Steve Thomason
 
Industrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training ReportIndustrial Training Report- AKTU Industrial Training Report
Industrial Training Report- AKTU Industrial Training Report
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
How to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERPHow to Create Map Views in the Odoo 17 ERP
How to Create Map Views in the Odoo 17 ERP
 
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptxMatatag-Curriculum and the 21st Century Skills Presentation.pptx
Matatag-Curriculum and the 21st Century Skills Presentation.pptx
 
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
Mattingly "AI & Prompt Design: Limitations and Solutions with LLMs"
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptxStudents, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
Students, digital devices and success - Andreas Schleicher - 27 May 2024..pptx
 
Accounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdfAccounting and finance exit exam 2016 E.C.pdf
Accounting and finance exit exam 2016 E.C.pdf
 
PART A. Introduction to Costumer Service
PART A. Introduction to Costumer ServicePART A. Introduction to Costumer Service
PART A. Introduction to Costumer Service
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
B.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdfB.ed spl. HI pdusu exam paper-2023-24.pdf
B.ed spl. HI pdusu exam paper-2023-24.pdf
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & EngineeringBasic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
Basic Civil Engg Notes_Chapter-6_Environment Pollution & Engineering
 

CS6601-Unit 4 Distributed Systems

  • 2. INTRODUCTION In a centralized system: all processes reside on the same system utilize the same clock. In a distributed system: like synchronize everyone’s watch in the classroom. Time is monotonous
  • 4. Measuring Time Traditionally time measured astronomically Transit of the sun (highest point in the sky) Solar day and solar second Problem: Earth’s rotation is slowing down Days get longer and longer 300 million years ago there were 400 days in the year Modern way to measure time is atomic clock Based on transitions in Cesium-133 atom Still need to correct for Earth’s rotation Result: Universal Coordinated Time (UTC) UTC available via radio signal, telephone line, satellite (GPS)
  • 5. Global Time Global Time is utilized to provide timestamps for processes and data.  Physical clock: concerned with “People” time  Logical clock: concerned with relative time and maintain logical consistency
  • 6. Physical Clocks There are two aspects: Obtaining an accurate value for physical time Synchronizing the concept of physical time throughout the distributed system These can be implemented using centralized algorithms or distributed algorithms
  • 7. Obtaining an Accurate Physical Time A physical time server is needed to access the current time from a universal time coordinator (UTC). Two sources for UTC:  WWV shortwave radio station in Ft. Collins, Colorado  Geostationary Operational Environmental Satellites (GEOS)
  • 8. Synchronizing Physical Time The difference in time between two clocks due to drifting is defined as clock skew. As long as any and every two clocks differ by a value less than the maximum skew value, the time service is considered to be maintaining synchronization.
  • 9. Skew between computer clocks in a distributed system
  • 10. How to synchronize two clocks in A and B? The information necessary to read the value must be communicated across the network to location B. B’s clock value must be read. B’s clock value is communicated back to location A. B’s clock value is adjusted to reflect the time necessary to travel across the network. B’s clock value is compared to A’s clock value.
  • 11. Centralized Physical Time Services Broadcast Based Request Driven
  • 12. Broadcast Based – first approach The centralized time server’s action: The physical time service broadcasts periodically the current time to members of the distributed systems. The participants’ action:  If a given participant’s clock is ahead of the time server’s clock, the participant slows down its clock so that it will continually move closer to the accurate time.  If a participant’s clock is behind the time server’s clock, the participant moves its clock forward. Alternatives do include gradually speeding up the clock.
  • 13. Current time = 720 Location A Broadcast based Time server Current time=740 Delay of 10 Current time=720 Adjusted current time=750 New current time=750 Location A
  • 14. Current time=720 Move forward=6 Location A Current time=740 Adjusted location A =730 Adjusted location B =738 Average and the new current time=736 Time Server Current time=732 Slow clock down to accommodate 2 Location B 1 1 2 2 4 5 1. Current time = 740 2. My current time = 720 3. My current time = 732 4. Adjust forward = 6 5. Adjust slowdown to accommodate 2 Delay=10 Delay=6
  • 15. Current time=730 Adjusted time=750 New current time=750 Current time=740 Location A Timer Server Request for current time Current time=740 Delay=10
  • 16. Distributed Physical Time Service Each location broadcasts its current time at predefined set intervals. Once a location has broadcast its time, it starts a timer. It then collects time messages that it receives.  Each time message that arrives is stamped with the local current time. This process continues until the timer expires. Upon the expiration of the timer, each message is adjusted to reflect the network delay time estimated for the message source. At this stage, the participant calculates the average time according to one of the following approaches:
  • 17. Calculate the average of all messages 720 724 726 718 722 723 Adjusted received times
  • 18. Delete the times that are above the threshold and then average the rest. 760 X 724 726 718 702 X 723 Adjusted received times The numbers besides X are deleted. The rest are averaged.
  • 19. Discard the highest x and the lowest x values and then average 760 X 724 726 718 702 X 723 703 X 765 X Adjusted received times
  • 20. Logical Clocks Why Logical Clocks? It is difficult to utilize physical clocks to order events uniquely in distributed systems. The essence of logical clocks is based on the happened-before relationship presented by Lamport.
  • 21. Happen-Before Relationship If two events, a and b, occurred at the same process, they occurred in the order of which they were observed. That is, a > b. If a sends a message to b, then a > b. That is, you cannot receive something before it is sent. This relationship holds regardless of where events a and b occur. The happen-before relationship is transitive. If a happens before b and b happens before c, then a happens before c. That is, if a > b and b > c, then a > c.
  • 22. Logical Ordering  If T(a) is the timestamp for event a, the following relationships must hold in a distributed system utilizing logical ordering. If two events, a and b, occurred at the same process, they occurred in the order of which they were observed. That is T(a) > T(b). If a sends a message to b, then T(a) > T(b). If a happens before b and b happens before c, T(a) > T(b), T(b) > T(c), and T(a) > T(c).
  • 23. Process 1 Process 2 Process 3 A B C D E F A>B>C>D>F E
  • 24. Lamport’s Algorithm Each process increments its clock counter between every two consecutive events. If a sends a message to b, then the message must include T(a). Upon receiving a and T(a), the receiving process must set its clock to the greater of [T(a)+d, Current Clock]. That is, if the recipient’s clock is behind, it must be advanced to preserve the happen-before relationship. Usually d=1.
  • 25. Process 1 Process 2 Process 3 A(1) B(2) C(3) D(4) E(1) F(5)
  • 26. Process 1 Process 2 Process 3 A(1.1) B(2.1) D(4.2) E(1.3) F(5.3) C(3.2) A>E>B>C>D>F
  • 27. Mutual Exclusion In single-processor systems, critical regions are protected using semaphores, monitors, and similar constructs. In distributed systems, since there is no shared memory, these methods cannot be used.
  • 28. A Centralized Algorithm Advantages: It is fair, easy to implement, and requires only three messages per use of a critical region (request, grant, release). Disadvantages: single point of failure. coordinator process Request Grant Enter crical section Exit Release
  • 30.
  • 31. Algorithm Messages per entry/exit Delay before entry Problems Centralized 3 2 Coordinator crash Distributed 2(n-1) 2(n-1) Crash of any process Token ring 1 to ∞ 0 to n-1 Lost token, process crash
  • 32. Election Algorithm The bully algorithm When a process notices that the coordinator is no longer responding to requests, it initiates an election. A process, P, holds an election as follows: P sends an ELECTION message to all processes with higher numbers. If no one responds, P wins the election and becomes coordinator. If one of the higher-ups answers, it takes over. P’s job is done.
  • 34. A Ring Algorithm 1 2 4 5 3 7 6 2 2 3 2 3 42 3 4 5 2 3 4 5 6 2 3 4 5 6 1 6
  • 35. Atomic Transactions All the synchronization techniques we have studied so far are essentially low level, like semaphores. What we would really like is a much higher-level abstraction such as atomic transaction.
  • 36. For Example  Atomic bank transactions: 1. Withdraw(amount, account1) 2. Deposit(amount, account2)
  • 37. Stable Storage Stable storage is designed to survive anything except major calamities such as floods and earthquakes. Stable storage can be implemented with a pair of ordinary disks. Stable storage is well suited to applications that require a high degree of fault tolerance, such as atomic transactions.
  • 38. s a o h t f b w s a t f b w s a’ o h t f b w s a t f b w s a o h t f b w s a t f b w Stable storage Stable storage Stable storage Drive 1 Drive 2 (a) Stable storage (b) Crash after drive 1 is updated © Bad spot
  • 39. Transaction Primitives  1 BEGIN_TRANSACTION: Mark the start of a transaction.  2 END_TRANSACTION: Terminate the transaction and try to commit.  3 ABORT_TRANSACTION: Kill the transaction; restore the old values.  4 READ: Read data from a file (or other object).  5 WRITE: Write data to a file (or other object).  For example,  BEGIN_TRANSACTION  reserve Austin-Houston;  reserve Houston-Los Angeles;  reserve Los Angeles-Seatle;  END_TRANSCATION
  • 40. Properties of Transactions  Atomic: To the outside world, the transaction happens indivisibly. Consistent: The transaction does not violate system invariants.  Isolated: Concurrent transactions do not interfere with each other.  Durable: Once a transaction commits, the changes are permanent.
  • 41. Isolated or serializable Isolated or serializable means that if two or more transactions are running at the same time, to each of them and to other processes, the final result looks as though all transactions ran sequentially in some (system dependent) order.
  • 42. An Example  BEGIN_TRANACATION  X = 0;  X=X+1;  END_TRANSACTION  (a)  BEGIN_TRANSACTION  X=0;  X= X+2;  END_TRANSACTION  (b)  BEGIN_TRANSACTION  X=0;  X=X+3;  END_TRANSACTION  (c )
  • 43. Schedule 1 x=0; x=x+1; x=0; x=x+2; x=0; x=x+3; legal Schedule 2 x=0; x=0; x=x+1; x=x+2; x=0; x=x+3; legal Schedule 3 x=0; x=0; x=x+1; x=0; x=x+2; x=x+3; illegal
  • 44. Nest Transactions Transactions may contain subtransactions, often called nested transactions. If the subtransaction commits and the parent transaction aborts, the permanence applies only to top-level transactions.
  • 45. Implementation Private Workspace 1 02 0 1 2 1 02 1 2 Index 0’ 3’ 0 3 Index Index 0 1 2 0’ 1 2 3’ 0 1 2 3 Private workspace
  • 46. Writeahead log x=0; y=0; BEGIN_TRANSACTION x=x+1; log: x=0/; y=y+2; log: x=0/1; y=0/2; x=y * y; log: x=0/1; y=0/2; x=1/4; END_TRANSACTION
  • 47. Achieving atomic commit in a distributed system Two-Phase Commit Protocol Coordinator Subordinates Write “Prepare” in the log Send “Prepare” message Write “Ready” in the log Send “Ready” message Collect all replies Phase 1 Phase 2 Write log record (if all are ready, commit; if not, abort) Send “Commit” message Write “Commit” in the log Commit Send “Finished” message
  • 48. Concurrency Control When multiple transactions are executing simultaneously in different processes, some mechanism is needed to keep them out of each other’s way. That mechanism is called a concurrency control algorithm.
  • 49. Concurrency control algorithms  Locking  In the simplest form, when a process needs to read or write a file (or other object) as part of a transaction, it first locks the file.  Distinguishing read locks from write locks.  The unit of locking can be an individual record or page, a file, or a larger item.
  • 50. Two-phase locking The process first acquires all the locks it needs during the growing phase, then releases them during the shrinking phase. In many systems, the shrinking phase does not take place until the transaction has finished running and has either committed or aborted. This policy is called strict two-phase locking.
  • 51. Time Growing phase Shrinking phase Lock point Number of locks
  • 52. Optimistic Concurrency Control  A second approach to handling multiple transactions at the same time is optimistic concurrency control.  The idea is simple: just go ahead and do whatever you want to, without paying attention to what anybody else is doing. If there is a problem, worry about it later.
  • 53. Timestamps TRD TWR T (α) (α) (β) TWR TRD T (α) (α) (β) Write TRDT (γ)(β) TWRT (γ)(β) Do tentative write Abort AbortDo tenative write