simulation, orchestration and logical clocks · real time and virtual time logical timers coding...
TRANSCRIPT
![Page 1: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/1.jpg)
Real time and Virtual time Logical timers Coding simulations
Simulation, Orchestration and Logical Clocks
David Kitchin, Evan Powell, Jayadev Misra
Department of Computer ScienceUniversity of Texas at Austin
WG2.3, Cambridge, 2008
![Page 2: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/2.jpg)
Real time and Virtual time Logical timers Coding simulations
Outline
Real time and Virtual timeDesigning Time-based AlgorithmsOverview of OrcExamples
Logical timersA motivating Example: Shortest pathUsing Logical timers
Coding simulationsSimulation: BankSimulation: Fast Food RestaurantCollecting Statistics
![Page 3: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/3.jpg)
Real time and Virtual time Logical timers Coding simulations
Designing Time-based Algorithms
... the strong assumption of global time is first assumed, andthenrelaxed to the weaker logical time –could help us to design newalgorithms
Global And Logical Time In Distributed AlgorithmsCarroll Morgan, 1985
![Page 4: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/4.jpg)
Real time and Virtual time Logical timers Coding simulations
Designing Time-based Algorithms
• Morgan’s algorithms use time only for comparison.
• The clock value is never used.
• Simple conversion from real time to logical time.
We propose algorithms that use the clock value.
![Page 5: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/5.jpg)
Real time and Virtual time Logical timers Coding simulations
Overview of Orc
• Orc program has• aGoalexpression,• a set of definitions.
• A Program execution evaluates the goal. It
• callssites, to invoke services,• publishesvalues.
• Orc is simple• Language has only 3 combinators to form expressions.• Can handle time-outs, priorities, failures, synchronizations, · · ·• Combinators are (monotonic and) continuous.
![Page 6: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/6.jpg)
Real time and Virtual time Logical timers Coding simulations
Structure of Orc Expression
• Simple: just a site call,CNN(d)Publishes the value returned by the site.
• compositionof two Orc expressions:
do f andg in parallel f | g Symmetric compositionfor all x from f do g f >x> g Sequential compositionfor somex from g do f f <x< g Asymmetric composition
![Page 7: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/7.jpg)
Real time and Virtual time Logical timers Coding simulations
Structure of Orc Expression
• Simple: just a site call,CNN(d)Publishes the value returned by the site.
• compositionof two Orc expressions:
do f andg in parallel f | g Symmetric compositionfor all x from f do g f >x> g Sequential compositionfor somex from g do f f <x< g Asymmetric composition
![Page 8: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/8.jpg)
Real time and Virtual time Logical timers Coding simulations
Structure of Orc Expression
• Simple: just a site call,CNN(d)Publishes the value returned by the site.
• compositionof two Orc expressions:
do f andg in parallel f | g Symmetric compositionfor all x from f do g f >x> g Sequential compositionfor somex from g do f f <x< g Asymmetric composition
![Page 9: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/9.jpg)
Real time and Virtual time Logical timers Coding simulations
Structure of Orc Expression
• Simple: just a site call,CNN(d)Publishes the value returned by the site.
• compositionof two Orc expressions:
do f andg in parallel f | g Symmetric compositionfor all x from f do g f >x> g Sequential compositionfor somex from g do f f <x< g Asymmetric composition
![Page 10: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/10.jpg)
Real time and Virtual time Logical timers Coding simulations
Symmetric composition:f | g
• Evaluate f and g independently.
• Publish all values from both.
• No direct communication or interaction betweenf and g.They may communicate only through sites.
CNN(d) | BBC(d): callsboth CNN and BBC simultaneously.Publishes values returned by both sites. (0, 1 or 2 values)
![Page 11: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/11.jpg)
Real time and Virtual time Logical timers Coding simulations
Sequential composition:f >x> g
For all values published byf do g.Publish only the values fromg.
• CNN(d) >x> Email(address, x)
• Call CNN(d).• Bind result (if any) tox.• Call Email(address, x).• Publish the value, if any, returned byEmail.
• (CNN(d) | BBC(d)) >x> Email(address, x)
• May call Email twice.• Publishes up to two values fromEmail.
![Page 12: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/12.jpg)
Real time and Virtual time Logical timers Coding simulations
Schematic of Sequential composition
f
g1g0 g2
Figure:Schematic off >x> g
![Page 13: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/13.jpg)
Real time and Virtual time Logical timers Coding simulations
Notation
f ≫ g for f >x> g,if x unused ing.
Precedence:f >x> g | h >y> u for(f >x> g) | (h >y> u)
![Page 14: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/14.jpg)
Real time and Virtual time Logical timers Coding simulations
Asymmetric composition:(f <x< g)
For some value published byg do f .Publish only the values fromf .
• Evaluate f and g in parallel.
• Site calls that needx are suspended.• Other site calls proceed.• see (M() | N(x)) <x< g
• When g returns a value:
• Assign it to x.• Terminateg.• Resume suspended calls.
• Values published byf are the values of(f <x< g).
![Page 15: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/15.jpg)
Real time and Virtual time Logical timers Coding simulations
Example of Asymmetric composition
Email(address, x) <x< (CNN(d) | BBC(d))
Binds x to the first value fromCNN(d) | BBC(d).Sends at most one email.
![Page 16: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/16.jpg)
Real time and Virtual time Logical timers Coding simulations
Some Fundamental Sites
• if (b): booleanb,returns asignalif b is true; remainssilent if b is false.
• Null: never responds. Same asif (false).
• Signal() returns a signal immediately. Same asif (true).
• Rtimer(t): integer t, t ≥ 0, returns a signalt time units later.
![Page 17: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/17.jpg)
Real time and Virtual time Logical timers Coding simulations
Centralized Execution Model
• An expression is evaluated on a single machine (client).
• Client communicates with sites by messages.
• All fundamental sites are local to the client.All except Rtimer respond immediately.
• Round-based Execution.
![Page 18: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/18.jpg)
Real time and Virtual time Logical timers Coding simulations
Expression Definition
MailOnce(a) ∆Email(a, m) <m< (CNN(d) | BBC(d))
MailLoop(a, d) ∆MailOnce(a) ≫ Rtimer(d) ≫ MailLoop(a, d)
• Expression is called like a procedure.It may publish many values.MailLoop does not publish.
• Site calls are strict; expression calls non-strict.
![Page 19: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/19.jpg)
Real time and Virtual time Logical timers Coding simulations
Metronome
Publish a signal at every time unit.
Metronome() ∆ Signal() | (Rtimer(1) ≫ Metronome())
S R
S R
![Page 20: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/20.jpg)
Real time and Virtual time Logical timers Coding simulations
Example of Expression call
• Site Query() returns a value (different ones at different times).
• Site Accept(x) returns x if x is acceptable;it is silent otherwise.
• Publish all acceptable values by callingQuery at unit intervalsforever.
Metronome() ≫ Query() >x> Accept(x)
![Page 21: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/21.jpg)
Real time and Virtual time Logical timers Coding simulations
Time-out
Publish M’s response if it arrives before timet,Otherwise, publish0.
z <z< (M() | (Rtimer(t) ≫ 0))
![Page 22: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/22.jpg)
Real time and Virtual time Logical timers Coding simulations
Fork-join parallelism
Call M and N in parallel.Return their values as a tuple after both respond.
((u, v)<u< M())
<v< N()
Notational Convention: <u< is left-associative.
(u, v) <u< M() <v< N(), or(u, v)
<u< M()<v< N()
![Page 23: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/23.jpg)
Real time and Virtual time Logical timers Coding simulations
Recursive definition with time-out
Call a list of sites.Count the number of responses received within 10 time units.
tally([ ]) ∆ 0tally(M : MS) ∆ u + v
<u< (M() ≫ 1) | (Rtimer(10) ≫ 0)<v< tally(MS)
![Page 24: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/24.jpg)
Real time and Virtual time Logical timers Coding simulations
Barrier Synchronization inM ≫ f | N ≫ g
f and g start only afterboth M and N complete.Rendezvous of CSP or CCS;M and N are complementary actions.
((u, v)<u< M()<v< N())
≫ (f | g)
![Page 25: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/25.jpg)
Real time and Virtual time Logical timers Coding simulations
Priority
• Publish N’s response asap, but no earlier than 1 unit from now.Apply fork-join betweenRtimer(1) and N.
Delay() ∆ (Rtimer(1) ≫ u) <u< N()
• Call M, N together.If M responds within one unit, publish its response.Else, publish the first response.
x <x< (M() | Delay())
![Page 26: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/26.jpg)
Real time and Virtual time Logical timers Coding simulations
Interrupt f
Evaluation of f can not be directly interrupted.Introduce two sites:
• Interrupt.set: to interrupt f
• Interrupt.get: responds afterInterrupt.set has been called.
Instead of f , evaluate
z <z< (f | Interrupt.get())
![Page 27: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/27.jpg)
Real time and Virtual time Logical timers Coding simulations
Parallel or
Sites M and N return booleans. Compute theirparallel or.
if (x) ≫ true | if (y) ≫ true | or(x, y)<x< M()<y< N()
To return just one value:
z<z< if (x) ≫ true | if (y) ≫ true | or(x, y)<x< M()<y< N()
![Page 28: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/28.jpg)
Real time and Virtual time Logical timers Coding simulations
Shortest path problem
• Directed graph; non-negative weights on edges.
• Find shortest path from source to sink.
We calculate just the length of the shortest path.
![Page 29: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/29.jpg)
Real time and Virtual time Logical timers Coding simulations
Algorithm with Lights and Mirrors
• Source node sends rays of light to each neighbor.
• Edge weight is the time for the ray to traverse the edge.
• When a node receives its first ray, sends rays to all neighbors.Ignores subsequent rays.
• Shortest path length= time for sink to receive its first ray.
![Page 30: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/30.jpg)
Real time and Virtual time Logical timers Coding simulations
Expressions and Sites needed for Shortest path
succ(u): Publish all(v, d), where edge(u, v) has weightd.
write(u, t): Write value t for nodeu. If already written, block.
read(u): Return value for nodeu. If unwritten, block.
![Page 31: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/31.jpg)
Real time and Virtual time Logical timers Coding simulations
First Algorithm
eval1(u, t) ∆ write(u, t) ≫
Succ(u) >(v, d)>Rtimer(d) ≫
eval1(v, t + d)
Goal : eval1(source, 0) | read(sink)
First call to eval1(u, t):
• The relative time in the evaluation ist.
• Length of the shortest path from source tou is t.
• eval1 does not publish.
![Page 32: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/32.jpg)
Real time and Virtual time Logical timers Coding simulations
Second Algorithm
Use timer rt. Initial value 0.Retrieve its value by callingrt.C().
eval2(u, rt) ∆ rt.C() >t> write(u, t) ≫
Succ(u) >(v, d)>Rtimer(d) ≫
eval2(v, rt)
Goal : RealTimer >rt>(eval2(source, rt) | read(sink))
![Page 33: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/33.jpg)
Real time and Virtual time Logical timers Coding simulations
Third Algorithm
• Simplymarkintermediate nodes. No values are written.
• Marking showsu has been reached. Subsequent markings block.
• scanresponds only ifu has been marked. Else blocks.
eval3(u) ∆ mark(u) ≫
Succ(u) >(v, d)>Rtimer(d) ≫
eval3(v)
Goal : RealTimer >rt>(eval3(source) | scan(sink) ≫ rt.C())
![Page 34: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/34.jpg)
Real time and Virtual time Logical timers Coding simulations
Drawbacks of these algorithms
• Running time proportional to shortest path length.
• Executions ofSucc, read and write should take no time.
![Page 35: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/35.jpg)
Real time and Virtual time Logical timers Coding simulations
Properties of Real-time Timers
1. (Monotonicity) Successive calls tort.C() return non-decreasingvalues.
2. (Relativity)
{rt.C()= n} rt.R(t) {rt.C()= n + t}
provided rt.R(t) responds. (rt.R(t)=Rtimer(t))
![Page 36: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/36.jpg)
Real time and Virtual time Logical timers Coding simulations
Logical/Virtual Timer
Logical Timer lt: Methods lt.C() and lt.R(t).
• Many logical timers may coexist independently.
• Monotonicity holds for all: Successive calls tolt.C() returnnon-decreasing values.
• Relativity holds for all:
{lt.C()= n} lt.R(t) {lt.C()= n + t}
provided lt.R(t) responds.
• Difference from Real-time Timer:Sites other thanlt.R(.) take 0 logical time.
![Page 37: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/37.jpg)
Real time and Virtual time Logical timers Coding simulations
Shortest Path Algorithm using logical timer
eval4(u, lt) ∆ mark(u) ≫
Succ(u) >(v, d)>lt.R(d) ≫
eval4(v, lt)
Goal : VirtTimer() >lt>(eval4(source, lt) | scan(sink) ≫ lt.C())
lt has to be passed as a parameter, to performlt.R(d).For real-time timerrt, rt.R(d) = Rtimer(d).
![Page 38: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/38.jpg)
Real time and Virtual time Logical timers Coding simulations
Implementing logical timer
lt is a logical timer.n is the timer value. Initially0.
• lt.C() responds withn.
• lt.R(t) is assigned rankn + t and queued.
• At the time of removal, the removed item has the lowest rank,r.n := r.
![Page 39: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/39.jpg)
Real time and Virtual time Logical timers Coding simulations
Implementing logical timer; contd.
• Monotonicity and Relativity hold.
• Progress: If there is no other outstanding site call, some item isremoved from a non-empty queue.
• Generalize to multiple logical timers: They are causallyunrelated.
![Page 40: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/40.jpg)
Real time and Virtual time Logical timers Coding simulations
Simulation: Bank
• Bank with two tellers and one queue for customers.
• Customers generated by asource process.
• When free, a teller serves the first customer in the queue.
• Service times vary for customers.
• Determine
• Average wait time for a customer.• Queue length distribution.• Average idle time for a teller.
![Page 41: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/41.jpg)
Real time and Virtual time Logical timers Coding simulations
Goal Expression for Bank Simulation
Run the simulation forsimtime.
VirtTimer() >lt>
(z <z< Bank(lt) | lt.R(simtime)) ≫
Stats()
![Page 42: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/42.jpg)
Real time and Virtual time Logical timers Coding simulations
Description of Bank
Bank(lt) ∆ (Customers() | Teller(lt) | Teller(lt)) ≫ NullCustomers() ∆ Source() >c> enter(c)
Teller(lt) ∆ next() >c>lt.R(c.ServTime) ≫
Teller(lt)enter(c) ∆ q.put(c)
next() ∆ q.get()
![Page 43: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/43.jpg)
Real time and Virtual time Logical timers Coding simulations
Fast Food Restaurant
• Restaurant with one cashier, two cooking stations and one queuefor customers.
• Customers generated by asource process.
• When free, cashier serves the first customer in the queue.
• Cashier service times vary for customers.
• Cashier places the order in another queue for the cookingstations.
• Each order has 3 parts: main entree, side dish, drink
• A cooking station processes parts of an order in parallel.
![Page 44: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/44.jpg)
Real time and Virtual time Logical timers Coding simulations
Goal Expression for Restaurant Simulation
VirtTimer() >lt>
(z <z< Restaurant(lt) | lt.R(simtime)) ≫
Stats()
![Page 45: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/45.jpg)
Real time and Virtual time Logical timers Coding simulations
Description of Restaurant
Restaurant(lt) ∆ (Customers() | Cashier(lt) | Cook(lt) | Cook(lt)) ≫ NullCustomers() ∆ Source() >c> enter(c)Cashier(lt) ∆ next() >c>
lt.R(c.ringupTime) ≫
orders.put(c.order) ≫
Cashier(lt)Cook(lt) ∆ orders.get() >order>
((e, s, d)
<e< prepTime(order.entree) >t> lt.R(t)<s< prepTime(order.side) >t> lt.R(t)<d< prepTime(order.drink) >t> lt.R(t)
) ≫
Cook(lt)enter(c) ∆ q.put(c)
next() ∆ q.get()
![Page 46: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/46.jpg)
Real time and Virtual time Logical timers Coding simulations
Collecting Statistics: waiting time
Change
enter(c) ∆ q.put(c)next() ∆ q.get()
to
enter(c) ∆ lt.C >s> q.put(c, s)next() ∆ q.get() >(c, t)>
lt.C >s>reportWait(s − t) ≫
c
![Page 47: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/47.jpg)
Real time and Virtual time Logical timers Coding simulations
Stopwatch
A stopwatchis aligned with some timer, real or virtual.Supports 4 methods:
• reset
• read
• start
• stop
![Page 48: Simulation, Orchestration and Logical Clocks · Real time and Virtual time Logical timers Coding simulations Algorithm with Lights and Mirrors • Source node sends rays of light](https://reader033.vdocuments.net/reader033/viewer/2022050117/5f4e193d51abe6409d6f1203/html5/thumbnails/48.jpg)
Real time and Virtual time Logical timers Coding simulations
Histogram: Queue length
• CreateN + 1 stopwatches,sw[0..N], at the beginning ofsimulation.
• Final value of sw[i], 0 ≤ i < N, is the duration for which thequeue length has beeni.
• sw[N] is the duration for which the queue length is at leastN.
• On adding an item to queue of lengthi, 0 ≤ i < N, do
sw[i].stop | sw[i + 1].start
• After removing an item if the queue length isi, 0 ≤ i < N, do
sw[i].start | sw[i + 1].stop