-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 4855e93
Showing
11 changed files
with
635 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.