You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: quickwit/quickwit-control-plane/src/indexing_scheduler/scheduling/README.md
+21-16Lines changed: 21 additions & 16 deletions
Original file line number
Diff line number
Diff line change
@@ -3,13 +3,10 @@
3
3
Quickwit needs to assign indexing tasks to a set of indexers nodes.
4
4
We call the result of this decision the indexing physical plan.
5
5
6
-
This needs to be done under the constraints of:
7
-
- not exceeding the maximum load of each node. (O)
8
-
9
6
We also want to observe some interesting properties such as:
10
7
- (A) we want to avoid moving indexing tasks from one indexer to another one needlessly.
11
8
- (B) we want a source to be spread amongst as few nodes as possible
12
-
- (C) we prefer to respect some margin on the capacity of all nodes.
9
+
- (C) we want to balance the load between nodes as soon as the load is significative (>30%)
13
10
- (D) when we are working with the Ingest API source, we prefer to colocate indexers on
14
11
the ingesters holding the data.
15
12
@@ -50,24 +47,29 @@ And indexer has:
50
47
- a maximum total load (that we will need to measure or configure).
51
48
52
49
The problem is now greatly simplified.
53
-
A solution is a sparse matrix of `(num_indexers, num_sources)` that holds a number of shards to be run.
50
+
A solution is a sparse matrix of `(num_indexers, num_sources)` that holds a number of shards to be indexed.
54
51
The different constraint and wanted properties can all be re-expressed. For instance:
55
-
- We want the dot product of the load per shard vector with each row, to be lower than the maximum load
56
-
of each node. (O)
52
+
- We want the dot product of the load per shard vector with each row, to be close to the average load of each node (C)
57
53
- We do not want a large distance between the two solution matrixes (A)
58
-
- We want that matrix as sparse as possible (B).
54
+
- We want that matrix as sparse as possible (B)
55
+
56
+
Note that the constraint (C) is enforced differently depending on the load:
57
+
- shards can be placed freely on nodes up to 30% of their capacity
58
+
- above this threshold, we try to assign shards to indexers so that the total load on each indexer is close to the average load
59
+
60
+
To express the affinity constraint (D) we could similarly define a matrix of `(num_indexers, num_sources)` with affinity scores and compute a distance with the solution matrix.
59
61
60
-
The actual cost function we would craft is however not linear. For instance, the benefit of keeping
61
-
some free capacity for a given node is clearly not a linear function. In fact, keeping some imbalance
62
-
could be a good thing.
62
+
The actual cost function we would craft is however not linear, it is the combination of multiple distances like those discribed above.
63
63
64
64
# The heuristic
65
65
66
66
We use the following heuristic.
67
67
68
+
While assigning shards to node, we try to ensure that workloads are balanced (except for very small cluster loads). This is achieved by calculating a virtual capacity for each indexer. We calculate 120% of the total load on the entire cluster then divide it up proportionally between indexers according to their capacity. By respecting this virtual capacity when assigning shards to indexers, we make sure that all indexers have a load close to the average load.
69
+
68
70
## Phase 1: Remove extraneous shards
69
71
70
-
Starting from the existing solution, we first reduce it to make sure we do not have too many shards assigned.
72
+
Starting from the existing solution, we first reduce it to make sure we do not have too many shards assigned. This happens when a source was scaled down or deleted.
71
73
This is done by reducing the number of shard wherever needed, picking in priority nodes with few shards.
72
74
73
75
We call the resulting solution "reduced solution". The reduced solution is usually not a valid solution as some shard
@@ -78,18 +80,21 @@ previous solution.
78
80
79
81
## Phase 2: Enforce nodes maximum load
80
82
81
-
We then remove entire sources, in order to match the constraint (O).
83
+
We then remove entire sources from nodes where the load is higher than the capcity (load <30%) or virtual capacity (load >30%).
82
84
For every given node, we remove in priority sources that have an overall small load on the node.
83
85
84
86
Matrix-wise, note that phase 1 and phase 2 creates a matrix lower or equal to the previous solution.
85
87
86
88
## Phase 3: Greedy assignment
87
89
88
-
At this point we have reach a solution that fits on the cluster, but we possibly have several missing shards.
90
+
At this point we have reached a solution that fits on the cluster, but we possibly has several missing shards.
89
91
We therefore use a greedy algorithm to allocate these shard. We assign the shards source by source, in the order of decreasing total load.
90
-
We assign the source to the node with largest remaining load capacity.
91
92
92
-
If this phase fails, it is ok to log an error, and stop assigning sources.
93
+
We try assigning shards to indexers while trying to respect their virtual capacity. Because of the uneven size of shards and the greedy approach, this problem might not have a solution. In that case we iteratively grow the virtual capacity by 20% until the solution fits.
94
+
95
+
Shards for each source are placed in two steps:
96
+
- in a first iteration we assign shards that have affinity scores (D)
97
+
- in a second iteration we assign the rest of the shards starting with the node having the highest capacity
0 commit comments