mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-17 14:59:37 +00:00
docs: update master-worker
This commit is contained in:
+9
-11
@@ -19,15 +19,15 @@ The Master-Worker pattern is designed to perform parallel computations through t
|
||||
|
||||
## Explanation
|
||||
|
||||
Real World Example
|
||||
Real-world example
|
||||
|
||||
> Imagine a large restaurant kitchen where the head chef acts as the "master" and the line cooks serve as "workers." The head chef receives the orders from the dining area and breaks down each order into specific tasks, such as grilling meat, preparing salads, and cooking desserts. Each task is assigned to a different line cook based on their expertise and current workload. The line cooks work in parallel to prepare their portion of the order, while the head chef oversees the process, ensuring everything is prepared correctly and timely. Once each component of the order is ready, the head chef gathers all parts, gives them a final check, and then plates the dishes for service. This kitchen operation mimics the Master-Worker pattern by distributing and managing tasks to optimize efficiency and output.
|
||||
|
||||
In Plain Words
|
||||
In plain words
|
||||
|
||||
> The Master-Worker pattern involves a master process delegating tasks to multiple worker processes, which execute them concurrently and report back, optimizing parallel task processing and throughput.
|
||||
|
||||
Wikipedia Says
|
||||
Wikipedia says
|
||||
|
||||
> Master–slave is a model of asymmetric communication or control where one device or process (the master) controls one or more other devices or processes (the slaves) and serves as their communication hub. In some systems, a master is selected from a group of eligible devices, with the other devices acting in the role of slaves.
|
||||
|
||||
@@ -105,16 +105,16 @@ public abstract class Result<T> {
|
||||
|
||||
The `Input` class has a `divideData` method that is used to divide the input data into subtasks. The `Result` class simply encapsulates the result data.
|
||||
|
||||
## Class diagram
|
||||
|
||||

|
||||
|
||||
## Applicability
|
||||
|
||||
* Suitable for scenarios where a task can be decomposed into smaller, independent tasks.
|
||||
* Useful in applications requiring concurrent execution to enhance performance.
|
||||
* Applicable in distributed computing where tasks need to be processed by multiple processors or machines.
|
||||
|
||||
## Tutorials
|
||||
|
||||
* [Master-Worker Pattern (Gigaspaces)](https://docs.gigaspaces.com/sbp/master-worker-pattern.html)
|
||||
|
||||
## Known Uses
|
||||
|
||||
* Implemented in distributed systems to manage tasks across different computing resources.
|
||||
@@ -137,13 +137,11 @@ Trade-offs:
|
||||
## Related Patterns
|
||||
|
||||
* Task Parallelism and Data Parallelism: Master-Worker utilizes these patterns to divide work into tasks or data segments.
|
||||
* Producer-Consumer: Similar in structure but focuses on balancing production and consumption rates; Master-Worker is more about task distribution and aggregation.
|
||||
* Pipeline: Both organize processing steps but Pipeline arranges them linearly whereas Master-Worker may not impose such a sequence.
|
||||
* [Producer-Consumer](https://java-design-patterns.com/patterns/producer-consumer/): Similar in structure but focuses on balancing production and consumption rates; Master-Worker is more about task distribution and aggregation.
|
||||
* [Pipeline](https://java-design-patterns.com/patterns/pipeline/): Both organize processing steps but Pipeline arranges them linearly whereas Master-Worker may not impose such a sequence.
|
||||
|
||||
## Credits
|
||||
|
||||
* [Distributed Systems: Principles and Paradigms](https://amzn.to/3UN2vbH)
|
||||
* [Java Concurrency in Practice](https://amzn.to/4aRMruW)
|
||||
* [Pattern-Oriented Software Architecture Volume 2: Patterns for Concurrent and Networked Objects](https://amzn.to/3UgC24V)
|
||||
* [Master-Worker Pattern](https://docs.gigaspaces.com/sbp/master-worker-pattern.html)
|
||||
* [The Master-Slave Design Pattern](https://www.cs.sjsu.edu/~pearce/oom/patterns/behavioral/masterslave.htm)
|
||||
|
||||
Reference in New Issue
Block a user