Date post: | 15-Dec-2015 |
Category: |
Documents |
Upload: | misael-arden |
View: | 231 times |
Download: | 0 times |
22
The The ServletServlet Interface Interface Java provides the interface Java provides the interface ServletServlet Specific Servlets implement this interfaceSpecific Servlets implement this interface Whenever the Web server is asked to invoke Whenever the Web server is asked to invoke
a specific Servlet, it activates the method a specific Servlet, it activates the method service()service() of an instance of this Servletof an instance of this Servlet
service(request,response)
MyServlet
(HTTP)request
(HTTP)response
CS677: Distributed OSCS677: Distributed OS
Consistency and ReplicationConsistency and Replication
Today:Today:• Introduction Introduction • Consistency modelsConsistency models
Data-centric consistency modelsData-centric consistency models Client-centric consistency modelsClient-centric consistency models
• Thoughts for the mid-termThoughts for the mid-term
CS677: Distributed OSCS677: Distributed OS
Why replicate?Why replicate? Data replication: common technique in distributed Data replication: common technique in distributed
systemssystems ReliabilityReliability
• If one replica is unavailable or crashes, use anotherIf one replica is unavailable or crashes, use another• Protect against corrupted dataProtect against corrupted data
PerformancePerformance• Scale with size of the distributed system (replicated web Scale with size of the distributed system (replicated web
servers)servers)• Scale in geographically distributed systems (web proxies)Scale in geographically distributed systems (web proxies)
Key issue: need to maintain Key issue: need to maintain consistencyconsistency of replicated of replicated datadata• If one copy is modified, others become inconsistentIf one copy is modified, others become inconsistent
CS677: Distributed OSCS677: Distributed OS
Object ReplicationObject Replication
Approach 1: application is responsible for replicationApproach 1: application is responsible for replication• Application needs to handle consistency issuesApplication needs to handle consistency issues
Approach 2: system (middleware) handles replicationApproach 2: system (middleware) handles replication• Consistency issues are handled by the middlewareConsistency issues are handled by the middleware• Simplifies application development but makes object-specific Simplifies application development but makes object-specific
solutions hardersolutions harder
CS677: Distributed OSCS677: Distributed OS
Replication and ScalingReplication and Scaling Replication and caching used for system Replication and caching used for system
scalabilityscalability Multiple copies:Multiple copies:
• Improves performance by reducing access latency Improves performance by reducing access latency • But higher network overheads of maintaining But higher network overheads of maintaining
consistencyconsistency• Example: object is replicated Example: object is replicated NN times times
Read frequency Read frequency R, R, write frequency write frequency WW If If R<<WR<<W, high consistency overhead and wasted messages, high consistency overhead and wasted messages Consistency maintenance is itself an issueConsistency maintenance is itself an issue
• What semantics to provide?What semantics to provide?• Tight consistency requires globally synchronized clocks!Tight consistency requires globally synchronized clocks!
Solution: loosen consistency requirementsSolution: loosen consistency requirements• Variety of consistency semantics possibleVariety of consistency semantics possible
CS677: Distributed OSCS677: Distributed OS
Data-Centric Consistency Data-Centric Consistency ModelsModels
Consistency model (aka Consistency model (aka consistency semanticsconsistency semantics))• Contract between processes and the data storeContract between processes and the data store
If processes obey certain rules, data store will work correctlyIf processes obey certain rules, data store will work correctly• All models attempt to return the results of the last write for a read All models attempt to return the results of the last write for a read
operationoperation Differ in how “last” write is determined/definedDiffer in how “last” write is determined/defined
CS677: Distributed OSCS677: Distributed OS
Strict ConsistencyStrict Consistency
Any read always returns the result of Any read always returns the result of the most recent writethe most recent write• Implicitly assumes the presence of a global Implicitly assumes the presence of a global
clockclock• A write is immediately visible to all A write is immediately visible to all
processesprocesses Difficult to achieve in real systems (network Difficult to achieve in real systems (network
delays can be variable)delays can be variable)
CS677: Distributed OSCS677: Distributed OS
Sequential ConsistencySequential Consistency
Sequential consistency: weaker than strict consistencySequential consistency: weaker than strict consistency• Assumes all operations are executed in some sequential order Assumes all operations are executed in some sequential order
and each process issues operations in program orderand each process issues operations in program order Any valid interleaving is allowedAny valid interleaving is allowed All agree on the same interleavingAll agree on the same interleaving Each process preserves its program orderEach process preserves its program order Nothing is said about “most recent write”Nothing is said about “most recent write”
CS677: Distributed OSCS677: Distributed OS
LinearizabilityLinearizability
Assumes sequential consistency Assumes sequential consistency andand• If TS(x) < TS(y) then OP(x) should precede OP(y) in the If TS(x) < TS(y) then OP(x) should precede OP(y) in the
sequencesequence• Stronger than sequential consistencyStronger than sequential consistency• Difference between linearizability and serializbility?Difference between linearizability and serializbility?
Granularity: reads/writes versus transactionsGranularity: reads/writes versus transactionsExample:Example:
Process P1 Process P2 Process P3
x = 1;
print ( y, z);
y = 1;
print (x, z);
z = 1;
print (x, y);
CS677: Distributed OSCS677: Distributed OS
Linearizability ExampleLinearizability Example
Four valid execution sequences for the processes of Four valid execution sequences for the processes of the previous slide. The vertical axis is time.the previous slide. The vertical axis is time.
x = 1;
print ((y, z);
y = 1;
print (x, z);
z = 1;
print (x, y);
Prints: 001011
Signature: 001011
(a)
x = 1;
y = 1;
print (x,z);
print(y, z);
z = 1;
print (x, y);
Prints: 101011
Signature: 101011
(b)
y = 1;
z = 1;
print (x, y);
print (x, z);
x = 1;
print (y, z);
Prints: 010111
Signature:
110101
(c)
y = 1;
x = 1;
z = 1;
print (x, z);
print (y, z);
print (x, y);
Prints: 111111
Signature:
111111
(d)
CS677: Distributed OSCS677: Distributed OS
Causal consistencyCausal consistency
Causally related writes must be seen by Causally related writes must be seen by all processes in the same order. all processes in the same order. • Concurrent writes may be seen in different Concurrent writes may be seen in different
orders on different machinesorders on different machines
Not permitted Permitted
CS677: Distributed OSCS677: Distributed OS
Other modelsOther models FIFO consistency: writes from a process are seen FIFO consistency: writes from a process are seen
by others in the same order. Writes from different by others in the same order. Writes from different processes may be seen in different order (even if processes may be seen in different order (even if causally related)causally related)• Relaxes causal consistencyRelaxes causal consistency• Simple implementation: tag each write by (Proc ID, seq Simple implementation: tag each write by (Proc ID, seq
#)#) Even FIFO consistency may be too strong!Even FIFO consistency may be too strong!
• Requires all writes from a process be seen in orderRequires all writes from a process be seen in order Assume use of critical sections for updatesAssume use of critical sections for updates
• Send final result of critical section everywhereSend final result of critical section everywhere• Do not worry about propagating intermediate resultsDo not worry about propagating intermediate results
Assume presence of synchronization primitives to define Assume presence of synchronization primitives to define semanticssemantics
CS677: Distributed OSCS677: Distributed OS
Other Models Other Models Weak consistencyWeak consistency
• Accesses to synchronization variables Accesses to synchronization variables associated with a data store are sequentially associated with a data store are sequentially consistentconsistent
• No operation on a synchronization variable is No operation on a synchronization variable is allowed to be performed until all previous writes allowed to be performed until all previous writes have been completed everywherehave been completed everywhere
• No read or write operation on data items are No read or write operation on data items are allowed to be performed until all previous allowed to be performed until all previous operations to synchronization variables have operations to synchronization variables have been performed.been performed.
Entry and release consistencyEntry and release consistency• Assume shared data are made consistent at Assume shared data are made consistent at
entry or exit points of critical sectionsentry or exit points of critical sections
CS677: Distributed OS
Summary of Data-centric Consistency ModelsSummary of Data-centric Consistency Models
Consistency Description
Strict Absolute time ordering of all shared accesses matters.
LinearizabilityAll processes must see all shared accesses in the same order. Accesses are furthermore ordered according to a (nonunique) global timestamp
Sequential All processes see all shared accesses in the same order. Accesses are not ordered in time
Causal All processes see causally-related shared accesses in the same order.
FIFOAll processes see writes from each other in the order they were used. Writes from different processes may not always be seen in that order
(a)
Consistency Description
Weak Shared data can be counted on to be consistent only after a synchronization is done
Release Shared data are made consistent when a critical region is exited
Entry Shared data pertaining to a critical region are made consistent when a critical region is entered.
(b)
CS677: Distributed OSCS677: Distributed OS
Caching in WWW: Case StudyCaching in WWW: Case Study Dramatic growth in world wide web Dramatic growth in world wide web
traffictraffic Web accesses are non-uniform in Web accesses are non-uniform in
naturenature• Create hot-spots of server and network Create hot-spots of server and network
load, increase latencyload, increase latency Solution:Solution: employ web proxy cachesemploy web proxy caches
• Reduces user response times, server Reduces user response times, server load, network loadload, network loadProxies End-hostsServers
NetworkNetwork
CS677: Distributed OSCS677: Distributed OS
Content Distribution NetworkContent Distribution Network
Content distribution network (CDN)Content distribution network (CDN)• Collection of proxies that act as intermediaries between Collection of proxies that act as intermediaries between
servers and clientsservers and clients• Service a client request from “closest” proxy with the objectService a client request from “closest” proxy with the object• Similar benefits as single proxy environments, but larger Similar benefits as single proxy environments, but larger
scalescale• Example: Akamai CDN - 13,000+ proxiesExample: Akamai CDN - 13,000+ proxies
Caching in CDN => must maintain cache consistencyCaching in CDN => must maintain cache consistency
End-hostsServers
CS677: Distributed OSCS677: Distributed OS
Consistency MechanismsConsistency Mechanisms
Time-to-live (TTL) valuesTime-to-live (TTL) values• Expiration time of cached documentExpiration time of cached document• Proxy must refresh from server after expiration Proxy must refresh from server after expiration
Poll:Poll: Use if-modified-since (IMS) HTTP requests Use if-modified-since (IMS) HTTP requests
• Weaker guarantees: document can change Weaker guarantees: document can change before expirationbefore expiration
Poll every timePoll every time• Poll the server upon request for a cached objectPoll the server upon request for a cached object• Increases response time of requests Increases response time of requests • Provides stronger consistency guaranteesProvides stronger consistency guarantees
CS677: Distributed OSCS677: Distributed OS
Consistency with LeasesConsistency with Leases Lease:Lease: fixed duration contract between server and fixed duration contract between server and
proxyproxy• Server agrees to notify proxy of all updates to an object over Server agrees to notify proxy of all updates to an object over
duration duration dd• ““d”d” is the lease duration is the lease duration• Lease may be renewed upon expiryLease may be renewed upon expiry
Properties:Properties:• Server needs to notify each proxy caching the object of an Server needs to notify each proxy caching the object of an
updateupdate Excessive burden for popular objectsExcessive burden for popular objects
• Leases requires a server to maintain stateLeases requires a server to maintain state Overhead can be excessive for large CDNsOverhead can be excessive for large CDNs
• Leases provide stronger consistency guaranteesLeases provide stronger consistency guarantees• Push-based approach, server-initiated consistencyPush-based approach, server-initiated consistency
CS677: Distributed OSCS677: Distributed OS
Mid-term Exam CommentsMid-term Exam Comments
Closed book, closed notes, 90 minClosed book, closed notes, 90 min Lectures 1-13 included on the testLectures 1-13 included on the test
• Focus on things taught in class (lectures, in-class Focus on things taught in class (lectures, in-class discussions)discussions)
• Start with lecture notes, read corresponding sections Start with lecture notes, read corresponding sections from textfrom text
• Supplementary readings are not included on the test.Supplementary readings are not included on the test. Exam structure: few short answer questions, Exam structure: few short answer questions,
mix of subjective and “design” questionsmix of subjective and “design” questions
Good luck!Good luck!