Skip to content

Commit

Permalink
first
Browse files Browse the repository at this point in the history
  • Loading branch information
chungminhtu committed Aug 18, 2024
0 parents commit 4855e93
Show file tree
Hide file tree
Showing 11 changed files with 635 additions and 0 deletions.
69 changes: 69 additions & 0 deletions ascii_diagram.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,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
Binary file added assets/1.1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/1.2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.1.1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.1.2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.1.3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.2.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.3.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.4.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/2.5.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4855e93

Please sign in to comment.