R EPLICATED VS . C ENTRALIZED M ODEL S HARING Prasun Dewan Department of Computer Science University of North Carolina at Chapel Hill dewan@cs.unc.edu Code available at: https://github.com/pdewan/ColabTeaching
N EXT How to implement model-based sharing? How do build higher level abstractions for model- based sharing? 2
E CHOER TO IM More than one architecture to implement this user interface 3
S INGLE - USER A RCHITECTURE Interactor Model 4
C OLLABORATIVE A RCHITECTURES : C ENTRALIZED VS R EPLICATED Interactor Interactor Interactor Model Model Model Interactor What are these architectures, what are their pros and cons? 5
R EPLICATED Interactor Interactor Model Model 6
S INGLE -U SER VS R EPLICATED A LGORITHM : R UNNING E XAMPLE UI Thread For each input I I should be followed by matching ListEditInput, ListEditMade, ListEditNotified, ListEditObserved, ListEditDisplayed For each replica, I should be followed by matching ListEditSent to Others Receiving Thread For each ListEditReceived R R should be followed by matching ListEditMade, ListEditNotified, ListEditObserved, ListEditDisplayed For each replica, R should be followed by matching ListEditSent 7
G ENERAL M ODEL -I NTERACTOR P ATTERN : FROM L IST E DIT OPS TO E DIT O PS UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent to Others Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed For each replica, R should be followed by matching EditSent 8
S INGLE - USER VS R EPLICATED (C YCLES ) History elementAdded observableAdd input EchoerInteractor toOthers Replicated toOthers Communicator History observableAdd objectReceived input IMInteractor IMCoupler 9
S INGLE - USER VS R EPLICATED : R EPLICATED AND N ON R EPLICATED W RITE M ETHODS Each write method has a single-user and replicated History version elementAdded observableAdd Both notify observers EchoerInteractor Local input triggers replicated version Remote input triggers single- user version Replicated toOthers Communicator History replicatedAdd objectReceived input IMInteractor IMCoupler Multiple write methods setP(), 10 replicatedSetP()
S INGLE - USER VS R EPLICATED : C AN D ETECT IF I NCOMING E VENT HAS B EEN P ROCESSED BEFORE Notification has information about old state of changed History object elementAdded observableAdd Can determine if this object is at old state or new state EchoerInteractor Write method not called if object is at new state toOthers Replicated toOthers Communicator History objectReceived observableAdd objectReceived input IMInteractor IMCoupler 11
M ODELS VS . N OTIFICATIONS Received message contains new Beans property value Assuming no side effects Property collections If new property value same as current property value, do not call Differ in properties write method Lists Received message can contain new Variable length indexed lists size Differ based on subsets of list operations exposed If object is of new size, do not call Table model is another important kind not needed in write method this course Received message contains new key value If new key value same as old, do not call write method 12
S INGLE -U SER VS . M ULTI -U SER S TEPS 13
G ENERAL M ODEL -I NTERACTOR P ATTERN : FROM L IST E DIT OPS TO E DIT O PS UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent to Others Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed 14
R EPLICATED M ODEL : I SSUES Interactor Interactor Model Model Consistency issues of causality and concurrent operations (to be addressed later) 15
R EPLICATED A RCHITECTURE (R EVIEW ) Interactor Interactor Model Model Multiple physical models represent a single logical model 16
R EPLICATED M ODEL -I NTERACTOR A LGORITHM UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed Problems? 17
R EPLICATION G UARANTEE UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed Each model executes the same Not the same sequence! set of operations Consistency issues of causality and concurrent 18 operations (to be addressed later)
A SSUME S TRONGER G UARANTEE UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed Assume that each model executes the same sequence of operations 19 Performance issues? Correctness issues?
P ERFORMANCE Input n Interactor Interactor Inefficient replicated computations! Model Model Computation vs. communication costs Find Find prime prime factors factors 20
R EADING A C ENTRALIZED E XTERNAL R ESOURCE Input load Interactor Interactor Bottleneck! Model Model read f read f a File f 21
P ROBLEMS UI Thread For each input I I should be followed by matching EditInput, EditMade, EditNotified, EditObserved, EditDisplayed For each replica, I should be followed by matching EditSent Receiving Thread For each EditReceived R R should be followed by matching EditMade, EditNotified, EditObserved, EditDisplayed Assume that each model executes the same sequence of operations Multiple computations 22 Correctness issues? and bottlenecks
P ROBLEMS Is executing the same operation multiple times equivalent to executing the operation a single time? 23
R EADING A C ENTRALIZED E XTERNAL R ESOURCE Interactor Interactor Model Model read f read f a File f Change read to write? 24
W RITING TO A C ENTRALIZED E XTERNAL R ESOURCE Each replica writes to Input b the file! Interactor Interactor Behavior of centralized and replicated different Write is not idempotent Model Model Executing idempotent operations once is the same as executing them write f, b write f, b multiple times, operation is a function abb ab a File f of only its arguments Assumption: Only idempotent operations 25
R EPLICATE E XTERNAL R ESOURCES Input a Interactor Interactor Model Model write f, a write f, a ab ab Other examples of idempotent operations in practice? 26
S ENDING M AIL T OGETHER Mail msg Interactor Interactor Model Model Assumption: Only idempotent mail msg mail msg operations Mail Server Do not always have the option of replicating resources 27
R EPLICATED M ODEL : I SSUES Interactor Interactor Model Model Consistency issues of causality and concurrent operations (to be addressed later) Correctness and performance issues when model is non deterministic, accesses central resources, and has side effects 28
R EPLICATED VS C ENTRALIZED Interactor Interactor Interactor Model Model Model Interactor 29
C ENTRALIZED S ESSION M EMBER T YPES Interactor Slave Model Master Interactor Slave 30
S INGLE -U SER VS C ENTRALZED A LGORITHM : R UNNING E XAMPLE Slave UI Thread For each input I I should be followed by matching ListEditInput, ListEditMade, ListEditNotified, I should be followed by matching ListEditInput and ListEditSent to Master ListEditObserved, ListEditDisplayed Master Receiving Thread For each ListEditReceived R R should be followed by matching ListEditMade, ListEditSent to Others Slave Receiving Thread For each ListEditReceived R R should be followed by matching ListEditDisplayed 31
C ENTRALIZED A RCHITECTURE None of the replication issues Interactor Feedback times involve round trip delays Feed through incurs extra hop (beyond Model relaying) Refresh and query operations also involve round trip delays (e.g. searching history) Interactor Can we fix the last problem? Caching! 32
C ACHING VS . R EPLICA Model cache is data repository Model without side effects Interactor Cache Updated in response to distributed messages from real central model Model No divergence of caches, real model has the real state Like real model it fires events to local observers Write operations require Read operations access local round trip data 33
D ISTRIBUTION /C OLLABORATION A WARENESS IN C LASSES Each interactor is distribution Model and collaboration aware: it Interactor Cache sends messages to central model Model As is model cache, it receives messages form central model 34
Recommend
More recommend