-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathascii_diagram.txt
69 lines (68 loc) · 6.24 KB
/
ascii_diagram.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Multithreading in a Coffee Shop vs. Computer Processing (3 customers)
1. Synchronize processing (Single-threaded processing)
1.1. Sequential Processing without cache (One lazy barista, one machine - Single CPU) (serve all 90 minutes)
Customer 1 [Take order][Brew coffee][Serve] Total time: 30 min
Customer 2 ───────────────────────→[Take order][Brew coffee][Serve] Total time: 60 min
Customer 3 ──────────────────────────────────────────→[Take order][Brew coffee][Serve] Total time: 90 min
|-------|-------|-------|-------|-------|-------|-------|-------|
10 20 30 40 50 60 70 80 90 min
1.2. Caching (One lazy barista, one machine, but drinks pre-prepared - CPU with Fast Access to Stored Results) (serve all 40 minutes)
Customer 1 [Take order][Brew new][Serve][Cache] Total time: 30 min
Customer 2 ───────────────────────→[Take order][Serve from Cache] Total time: 35 min
Customer 3 ─────────────────────────────→[Take order][Serve from Cache] Total time: 40 min
|-------|-------|-------|
10 20 30 40 min
2. Asynchronize Processing
2.1 Concurrent Processing (One multi-tasking barista, single machine - Single CPU with Context Switching)
2.1.1 One multitasking barista - Time slicing (Single CPU with Rapid Task Switching) (serve all 60 minutes)
Customer 1 [Take order][Start brewing]───[Wait]───[Serve] Total time: 40 min
Customer 2 ─→[Wait]→[Take order][Start brewing]───[Wait]───[Serve] Total time: 50 min
Customer 3 ───→[Wait]→[Take order][Start brewing]───[Wait]───[Serve] Total time: 60 min
|-------|-------|-------|-------|-------|
10 20 30 40 50 60 min
2.1.2 Multi-Threading (Multiple baristas, single machine - Single CPU with Multiple Execution Threads) (serve all 45 minutes)
Barista 1 [Take order 1][Wait for machine][Brew 1][Serve 1] Total time: 15 min
Barista 2 [Take order 2][Wait]───[Use machine][Brew 2][Serve 2] Total time: 30 min
Barista 3 [Take order 3][Wait]──────────[Use machine][Brew 3][Serve 3] Total time: 45 min
|-------|-------|-------|-------|
10 20 30 40 50 min
2.1.3 Producer-Consumer (Separate order taker and barista - Single CPU with Input Queue and Processor) (serve all 45 minutes)
Order Taker [Take order 1][Take order 2][Take order 3]
Barista ────[Brew coffee 1][Brew coffee 2][Brew coffee 3]
Serving ────────────────────[Serve 1][Serve 2][Serve 3]
Customer 1 [Order]───[Wait]───────────[Receive] Total time: 35 min
Customer 2 ─→[Wait]→[Order]───[Wait]───────────[Receive] Total time: 40 min
Customer 3 ───→[Wait]→[Order]───[Wait]───────────[Receive] Total time: 45 min
|-------|-------|-------|-------|
10 20 30 40 50 min
2.2 Parallel Processing (Multiple baristas, multiple machines - Multiple CPUs) (serve all 30 minutes)
Barista 1 [Take order][Brew coffee at Espresso Machine][Serve Customer 1] Total time: 30 min
Barista 2 [Take order][Brew coffee at Drip Coffee Maker][Serve Customer 2] Total time: 30 min
Barista 3 [Take order][Brew coffee at Tea Maker Machine][Serve Customer 3] Total time: 30 min
|-------|-------|
10 20 30 min
2.3 Microservices (Specialized coffee stations - Distributed CPUs with Specialized Services) (serve all 35 minutes)
Order Station [Take order 1][Take order 2][Take order 3]
Payment Station [Process payment 1][Process payment 2][Process payment 3]
Espresso Machine ────[Brew Espresso 1]
Drip Coffee Maker ────────[Brew drip coffee 2]
Tea Station ────────────[Brew tea 3]
Serving Station ────────────────[Serve 1][Serve 2][Serve 3]
Customer 1 [Order][Pay][Wait Espresso][Receive] Total time: 25 min
Customer 2 ─→[Wait]→[Order][Pay][Wait drip coffee][Receive] Total time: 30 min
Customer 3 ───→[Wait]→[Order][Pay][Wait tea][Receive] Total time: 35 min
|-------|-------|-------|
10 20 30 40 min
2.4 Distributed Processing (Multiple coffee shops - Multiple CPUs in Different Locations) (serve all 30 minutes)
Shop 1 [Take order][Brew coffee][Serve Customer 1] Total time: 30 min
Shop 2 [Take order][Brew coffee][Serve Customer 2] Total time: 30 min
Shop 3 [Take order][Brew coffee][Serve Customer 3] Total time: 30 min
|-------|-------|
10 20 30 min
2.5 Load Balancing (Efficient customer assignment - Multiple CPUs with Task Distribution) (serve all 35 minutes)
Load Balancer [Assign C1][Assign C2][Assign C3] Total time: 5 min
Barista 1 ──[Take order][Brew coffee][Serve] Total time: 30 min
Barista 2 ──[Take order][Brew coffee][Serve] Total time: 30 min
Barista 3 ──[Take order][Brew coffee][Serve] Total time: 30 min
|-------|-------|
10 20 30 min