|
1 | | -# Load Balance |
| 1 | +# Load Balancing |
2 | 2 |
|
3 | | -Load balancing refers to the reasonable allocation of server pressure through routing algorithms (usually in cluster environments) to achieve the maximum optimization of server performance. |
| 3 | +Load balancing distributes server pressure reasonably through routing algorithms (typically in cluster environments) to optimize server performance to the maximum extent. |
4 | 4 |
|
5 | 5 | ## DolphinScheduler-Worker Load Balancing Algorithms |
6 | 6 |
|
7 | | -DolphinScheduler-Master allocates tasks to workers, and by default provides three algorithms: |
| 7 | +DolphinScheduler-Master provides four load balancing algorithms for distributing tasks to workers: |
8 | 8 |
|
9 | | -- Weighted random (random) |
| 9 | +- **Random** (RANDOM) |
| 10 | +- **Round Robin** (ROUND_ROBIN) |
| 11 | +- **Smooth Round Robin** (FIXED_WEIGHTED_ROUND_ROBIN) |
| 12 | +- **Dynamic Smooth Round Robin** (DYNAMIC_WEIGHTED_ROUND_ROBIN) - Default algorithm |
10 | 13 |
|
11 | | -- Smoothing polling (round-robin) |
| 14 | +## Load Balancing Configuration |
12 | 15 |
|
13 | | -- Linear load (lower weight) |
| 16 | +Configure the load balancing algorithm in the configuration file: |
14 | 17 |
|
15 | | -The default configuration is the linear load. |
| 18 | +Location: `master-server/conf/application.yaml` |
16 | 19 |
|
17 | | -As the routing sets on the client side, the master service, you can change master.host.selector in master.properties to configure the algorithm. |
| 20 | +```yaml |
| 21 | +worker-load-balancer-configuration-properties: |
| 22 | + # types: RANDOM, ROUND_ROBIN, FIXED_WEIGHTED_ROUND_ROBIN, DYNAMIC_WEIGHTED_ROUND_ROBIN |
| 23 | + type: DYNAMIC_WEIGHTED_ROUND_ROBIN |
| 24 | +``` |
18 | 25 |
|
19 | | -e.g. master.host.selector=random (case-insensitive) |
| 26 | +## Worker Weight Configuration |
20 | 27 |
|
21 | | -## Worker Load Balancing Configuration |
| 28 | +### Smooth Round Robin Configuration (FIXED_WEIGHTED_ROUND_ROBIN) |
22 | 29 |
|
23 | | -The configuration file is worker.properties |
| 30 | +For the `FIXED_WEIGHTED_ROUND_ROBIN` algorithm, you can modify the fixed weight in each worker's configuration file: |
24 | 31 |
|
25 | | -### Weight |
| 32 | +Location: `worker-server/conf/application.yaml` |
26 | 33 |
|
27 | | -All the load algorithms above are weighted based on weights, which affect the routing outcome. You can set different weights for different machines by modifying the `worker.weight` value. |
| 34 | +```yaml |
| 35 | +worker: |
| 36 | + host-weight: 100 #default value is 100 |
| 37 | +``` |
28 | 38 |
|
29 | | -### Preheating |
| 39 | +### Dynamic Smooth Round Robin Configuration (DYNAMIC_WEIGHTED_ROUND_ROBIN) |
30 | 40 |
|
31 | | -Consider JIT optimization, worker runs at low power for a period of time after startup, so that it can gradually reach its optimal state, a process we call preheating. If you are interested, you can read some articles about JIT. |
| 41 | +When using the `DYNAMIC_WEIGHTED_ROUND_ROBIN` algorithm, you can configure the weights for various metrics: |
32 | 42 |
|
33 | | -So the worker gradually reaches its maximum weight with time after starts up ( by default ten minutes, there is no configuration about the pre-heating duration, it's recommend to submit a PR if have needs to change the duration). |
| 43 | +```yaml |
| 44 | +master: |
| 45 | + worker-load-balancer-configuration-properties: |
| 46 | + type: DYNAMIC_WEIGHTED_ROUND_ROBIN |
| 47 | + # Dynamic weight configuration, only used for DYNAMIC_WEIGHTED_ROUND_ROBIN algorithm |
| 48 | + # The sum of memory-usage, cpu-usage, task-thread-pool-usage weights must be 100 |
| 49 | + dynamic-weight-config-properties: |
| 50 | + memory-usage-weight: 30 # Memory usage weight |
| 51 | + cpu-usage-weight: 30 # CPU usage weight |
| 52 | + task-thread-pool-usage-weight: 40 # Task thread pool usage weight |
| 53 | +``` |
34 | 54 |
|
35 | | -## Load Balancing Algorithm in Details |
| 55 | +## Load Balancing Algorithm Details |
36 | 56 |
|
37 | | -### Random (Weighted) |
| 57 | +### Random (RANDOM) |
38 | 58 |
|
39 | | -This algorithm is relatively simple, select a worker by random (the weight affects its weighting). |
| 59 | +Randomly selects one available worker node to execute tasks. |
40 | 60 |
|
41 | | -### Smoothed Polling (Weighted) |
| 61 | +### Round Robin (ROUND_ROBIN) |
42 | 62 |
|
43 | | -An obvious drawback of the weighted polling algorithm, which is under special weights circumstance, weighted polling scheduling generates an imbalanced sequence of instances, and this unsmooth load may cause some instances to experience transient high loads, leading to a risk of system crash. To address this scheduling flaw, we provide a smooth weighted polling algorithm. |
| 63 | +Selects worker nodes in a fixed order to ensure each worker receives tasks evenly. |
44 | 64 |
|
45 | | -Each worker has two weights parameters, weight (which remains constant after warm-up is complete) and current_weight (which changes dynamically). For every route, calculate the current_weight + weight and is iterated over all the workers, the weight of all the workers sum up and count as total_weight, then the worker with the largest current_weight is selected as the worker for this task. By meantime, set worker's current_weight-total_weight. |
| 65 | +### Smooth Round Robin (FIXED_WEIGHTED_ROUND_ROBIN) |
46 | 66 |
|
47 | | -### Linear Weighting (Default Algorithm) |
| 67 | +Each worker has two weights: weight (remains constant after warm-up) and current_weight (dynamically changes). During each routing, all workers are traversed, and their current_weight is increased by their weight. The total weight of all workers is accumulated as total_weight. The worker with the highest current_weight is selected to execute the task, and then that worker's current_weight is decreased by total_weight. |
48 | 68 |
|
49 | | -This algorithm reports its own load information to the registry at regular intervals. We mainly judge by CPU usage, memory usage and worker slot usage. |
| 69 | +- Example: For instance, with 3 workers (A, B, C) having weights of 1, 2, and 3 respectively |
| 70 | +- Worker selection order will be: C B C A B C C B C A B C C B C A B C C B C A B C C B C A B C ... (In this 30-round scheduling example, the number of tasks allocated to each worker is: C:15, B:10, A:5, exactly matching the weight ratio) |
50 | 71 |
|
51 | | -If either of these is lower than the configured item, then this worker will not participate in the load. (no traffic will be allocated) |
| 72 | +### Dynamic Smooth Round Robin (DYNAMIC_WEIGHTED_ROUND_ROBIN) - Default Algorithm |
52 | 73 |
|
| 74 | +This algorithm reports its own load information to the registry at regular intervals. We primarily evaluate based on CPU usage, memory usage, and worker thread pool usage, with specific weight configurations as follows: |
| 75 | +- **Memory Usage** (Default weight: 30%) |
| 76 | +- **CPU Usage** (Default weight: 30%) |
| 77 | +- **Task Thread Pool Usage** (Default weight: 40%) |
| 78 | + |
| 79 | +**Weight Calculation Principle:** |
| 80 | +The dynamic weight of each worker is calculated using the following formula: |
| 81 | + |
| 82 | +``` |
| 83 | +Weight = 100 - (CPU Weight × CPU Usage + Memory Weight × Memory Usage + Thread Pool Weight × Thread Pool Usage) ÷ 3 |
| 84 | +``` |
| 85 | + |
| 86 | +Therefore, when a worker's load is lower, its weight will be higher, and the system will prioritize selecting worker nodes with lower loads to execute tasks. |
| 87 | + |
| 88 | +In the final worker node selection process, the workflow is consistent with smooth round robin, with the only difference being that in this algorithm, worker weights change dynamically. |
| 89 | +Through this dynamic smooth round robin algorithm, DolphinScheduler can intelligently distribute tasks to workers with the lowest loads, achieving true dynamic load balancing. |
0 commit comments