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: tiproxy/tiproxy-configuration.md
+7Lines changed: 7 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -112,6 +112,13 @@ Configurations for HTTP gateway.
112
112
113
113
Configurations for the load balancing policy of TiProxy.
114
114
115
+
#### `label-name`
116
+
117
+
+ Default value: `""`
118
+
+ Support hot-reload: yes
119
+
+ Specifies the label name used for [label-based load balancing](/tiproxy/tiproxy-load-balance.md#label-based-load-balancing). TiProxy matches the label values of TiDB servers based on this label name and prioritizes routing requests to TiDB servers with the same label value as itself.
120
+
+ The default value of `label-name` is an empty string, indicating that label-based load balancing is not used. To enable this load balancing policy, you need to set this configuration item to a non-empty string and configure both [`labels`](#labels) in TiProxy and [`labels`](/tidb-configuration-file.md#labels) in TiDB. For more information, see [Label-based load balancing](/tiproxy/tiproxy-load-balance.md#label-based-load-balancing).
Copy file name to clipboardExpand all lines: tiproxy/tiproxy-load-balance.md
+77-13Lines changed: 77 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,23 +5,86 @@ summary: Introduce the load balancing policies in TiProxy and their applicable s
5
5
6
6
# TiProxy Load Balancing Policies
7
7
8
-
TiProxy v1.0.0 only supports status-based and connection count-based load balancing policies for TiDB servers. Starting from v1.1.0, TiProxy introduces four additional load balancing policies that can be configured independently: health-based, memory-based, CPU-based, and location-based.
8
+
TiProxy v1.0.0 only supports status-based and connection count-based load balancing policies for TiDB servers. Starting from v1.1.0, TiProxy introduces five additional load balancing policies: label-based, health-based, memory-based, CPU-based, and location-based.
9
9
10
-
By default, TiProxy enables all policies with the following priorities:
10
+
By default, TiProxy applies these policies with the following priorities:
11
11
12
12
1. Status-based load balancing: when a TiDB server is shutting down, TiProxy migrates connections from that TiDB server to an online TiDB server.
13
-
2. Health-based load balancing: when the health of a TiDB server is abnormal, TiProxy migrates connections from that TiDB server to a healthy TiDB server.
14
-
3. Memory-based load balancing: when a TiDB server is at risk of running out of memory (OOM), TiProxy migrates connections from that TiDB server to a TiDB server with lower memory usage.
15
-
4. CPU-based load balancing: when the CPU usage of a TiDB server is much higher than that of other TiDB servers, TiProxy migrates connections from that TiDB server to a TiDB server with lower CPU usage.
16
-
5. Location-based load balancing: TiProxy prioritizes routing requests to the TiDB server geographically closest to TiProxy.
17
-
6. Connection count-based load balancing: when the connection count of a TiDB server is much higher than that of other TiDB servers, TiProxy migrates connections from that TiDB server to a TiDB server with fewer connections.
13
+
2. Label-based load balancing: TiProxy prioritizes routing requests to TiDB servers that share the same label as the TiProxy instance, enabling resource isolation at the computing layer.
14
+
3. Health-based load balancing: when the health of a TiDB server is abnormal, TiProxy migrates connections from that TiDB server to a healthy TiDB server.
15
+
4. Memory-based load balancing: when a TiDB server is at risk of running out of memory (OOM), TiProxy migrates connections from that TiDB server to a TiDB server with lower memory usage.
16
+
5. CPU-based load balancing: when the CPU usage of a TiDB server is much higher than that of other TiDB servers, TiProxy migrates connections from that TiDB server to a TiDB server with lower CPU usage.
17
+
6. Location-based load balancing: TiProxy prioritizes routing requests to the TiDB server geographically closest to TiProxy.
18
+
7. Connection count-based load balancing: when the connection count of a TiDB server is much higher than that of other TiDB servers, TiProxy migrates connections from that TiDB server to a TiDB server with fewer connections.
18
19
19
20
To adjust the priorities of load balancing policies, see [Configure load balancing policies](#configure-load-balancing-policies).
20
21
21
22
## Status-based load balancing
22
23
23
24
TiProxy periodically checks whether a TiDB server is offline or shutting down using the SQL port and status port.
24
25
26
+
## Label-based load balancing
27
+
28
+
Label-based load balancing prioritizes routing connections to TiDB servers that share the same label as TiProxy, enabling resource isolation at the computing layer. This policy is disabled by default and should only be enabled when your workload requires computing resource isolation.
29
+
30
+
To enable label-based load balancing, you need to:
31
+
32
+
- Specify the matching label name through [`balance.label-name`](/tiproxy/tiproxy-configuration.md#label-name).
33
+
- Configure the [`labels`](/tiproxy/tiproxy-configuration.md#labels) configuration item in TiProxy.
34
+
- Configure the [`labels`](/tidb-configuration-file.md#labels) configuration item in TiDB servers.
35
+
36
+
After configuration, TiProxy uses the label name specified in `balance.label-name` to route connections to TiDB servers with matching label values.
37
+
38
+
Consider an application that handles both transaction and BI workloads. To prevent these workloads from interfering with each other, configure your cluster as follows:
39
+
40
+
1. Set [`balance.label-name`](/tiproxy/tiproxy-configuration.md#label-name) to `"app"` in TiProxy, indicating that TiDB servers will be matched by the label name `"app"`, and connections will be routed to TiDB servers with matching label values.
41
+
2. Configure two TiProxy instances, adding `"app"="Order"` and `"app"="BI"` to their respective [`labels`](/tiproxy/tiproxy-configuration.md#labels) configuration items.
42
+
3. Divide TiDB instances into two groups, adding `"app"="Order"` and `"app"="BI"` to their respective [`labels`](/tidb-configuration-file.md#labels) configuration items.
43
+
4. Optional: For storage layer isolation, configure [Placement Rules](/configure-placement-rules.md) or [Resource Control](/tidb-resource-control.md).
44
+
5. Direct transaction and BI clients to connect to their respective TiProxy instance addresses.
TiProxy determines the health of a TiDB server by querying its error count. When the health of a TiDB server is abnormal while others are normal, TiProxy migrates connections from that server to a healthy TiDB server, achieving automatic failover.
@@ -99,11 +162,12 @@ tidb_servers:
99
162
zone: west
100
163
tikv_servers:
101
164
- host: tikv-host-1
102
-
port: 20160
103
165
- host: tikv-host-2
104
-
port: 20160
105
166
- host: tikv-host-3
106
-
port: 20160
167
+
pd_servers:
168
+
- host: pd-host-1
169
+
- host: pd-host-2
170
+
- host: pd-host-3
107
171
```
108
172
109
173
In the preceding configuration, the TiProxy instance on `tiproxy-host-1` prioritizes routing requests to the TiDB server on `tidb-host-1` because `tiproxy-host-1` has the same `zone` configuration as `tidb-host-1`. Similarly, the TiProxy instance on `tiproxy-host-2` prioritizes routing requests to the TiDB server on `tidb-host-2`.
@@ -121,9 +185,9 @@ Typically, TiProxy identifies the load on TiDB servers based on CPU usage. This
121
185
122
186
TiProxy lets you configure the combination and priority of load balancing policies through the [`policy`](/tiproxy/tiproxy-configuration.md#policy) configuration item.
123
187
124
-
- `resource`: the resource priority policy performs load balancing based on the following priority order: status, health, memory, CPU, location, and connection count.
125
-
- `location`: the location priority policy performs load balancing based on the following priority order: status, location, health, memory, CPU, and connection count.
126
-
- `connection`: the minimum connection count policy performs load balancing based on the following priority order: status and connection count.
188
+
- `resource`: the resource priority policy performs load balancing based on the following priority order: status, label, health, memory, CPU, location, and connection count.
189
+
- `location`: the location priority policy performs load balancing based on the following priority order: status, label, location, health, memory, CPU, and connection count.
190
+
- `connection`: the minimum connection count policy performs load balancing based on the following priority order: status, label, and connection count.
0 commit comments