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: content/en/docs/24.0/reference/features/tablet-balancer.md
+22-6Lines changed: 22 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -28,9 +28,9 @@ each tablet.
28
28
29
29
## Balancer Modes
30
30
31
-
However, in some topologies, a simple affinity algorithm does not effectively balance the load.
32
-
VTGate provides two additional balancer modes to address different topology and traffic patterns:
33
-
**prefer-cell**and **random**.
31
+
However, you may want more control over how traffic gets balanced across tablets.
32
+
VTGate provides three additional balancer modes to address different topology and traffic patterns:
33
+
**prefer-cell**, **random**, and **session**.
34
34
35
35
### When Default Policy is Insufficient
36
36
@@ -116,24 +116,40 @@ guaranteed even load distribution across all tablets, regardless of where traffi
116
116
With the random balancer, you can optionally use `--balancer-vtgate-cells` to restrict the
117
117
tablet pool to specific cells, but it's not required.
118
118
119
+
### Session Balancer
120
+
121
+
The session balancer ensures that a session always reads from the same replica to maintain monotonic consistency. Without this, a connection might read a value from one tablet, then get routed to a different tablet with higher replication lag and read an older value, effectively reading "backwards in time."
122
+
123
+
The session balancer uses rendezvous hashing (also called highest random weight hashing) to route each session to the same tablet throughout its lifetime. Rendezvous hashing ensures minimal connections move when tablets enter or leave the pool. For each session, it computes a hash weight for every available tablet using the tablet's alias and the session's unique identifier. The tablet with the highest weight is selected; as this process is deterministic, the same session always routes to the same tablet.
124
+
125
+
The algorithm prefers tablets in the local cell to minimize latency. If there are no available tablets in the local cell, the balancer will route traffic to external cells as a fallback.
126
+
127
+
Note that there are still cases where the monotonic consistency guarantee can be broken. For example, if a session is currently connected to a specific tablet, and that tablet goes down or goes out of serving, the session balancer will automatically route the session to a new, healthy tablet. If the new tablet is not as up-to-date as the previous tablet, the session may observe an older value for the same read.
128
+
129
+
**When to use session mode:**
130
+
* Your application requires monotonic consistency within a session
131
+
* Session stickiness is more important than absolute load distribution
132
+
* You want to eliminate the possibility of "backwards" reads due to replication lag differences
133
+
119
134
## Configuration
120
135
121
-
VTGate provides three balancer modes, controlled by the `--vtgate-balancer-mode` flag:
136
+
VTGate provides four balancer modes, controlled by the `--vtgate-balancer-mode` flag:
122
137
123
138
### Balancer Mode Selection
124
139
125
140
***`--vtgate-balancer-mode=cell`** (default): Uses local cell affinity random choice (default policy described above)
126
141
***`--vtgate-balancer-mode=prefer-cell`**: Uses the prefer-cell balancer algorithm
127
142
***`--vtgate-balancer-mode=random`**: Uses uniform random selection across all tablets
143
+
***`--vtgate-balancer-mode=session`**: Uses the session balancer algorithm to maintain session stickiness
128
144
129
145
### Configuration Flags
130
146
131
-
***`--vtgate-balancer-mode`**: Specifies which balancer mode to use (cell, prefer-cell, or random). Defaults to `cell`.
147
+
***`--vtgate-balancer-mode`**: Specifies which balancer mode to use (cell, prefer-cell, random, or session). Defaults to `cell`.
132
148
133
149
***`--balancer-vtgate-cells`**: Comma-separated list of cells that contain vtgates.
134
150
***Required** for `prefer-cell` mode
135
151
***Optional** for `random` mode (filters tablets to specified cells if provided)
136
-
* Ignored for `cell`mode
152
+
* Ignored for `cell`and `session` modes
137
153
138
154
***`--balancer-keyspaces`**: Comma-separated list of keyspaces for which to use the configured balancer mode. If empty, applies to all keyspaces. This allows gradual rollout of balancer modes.
Copy file name to clipboardExpand all lines: content/en/docs/24.0/reference/programs/vtgate/_index.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -263,7 +263,7 @@ vtgate \
263
263
-v, --version print binary version
264
264
--vmodule vModuleFlag comma-separated list of pattern=N settings for file-filtered logging
265
265
--vschema-ddl-authorized-users string List of users authorized to execute vschema ddl operations, or '%' to allow all users.
266
-
--vtgate-balancer-mode string Tablet balancer mode (options: cell, prefer-cell, random). Defaults to 'cell' which shuffles tablets in the local cell.
266
+
--vtgate-balancer-mode string Tablet balancer mode (options: cell, prefer-cell, random, session). Defaults to 'cell' which shuffles tablets in the local cell.
267
267
--vtgate-config-terse-errors prevent bind vars from escaping in returned errors
268
268
--warming-reads-concurrency int Number of concurrent warming reads allowed (default 500)
269
269
--warming-reads-percent int Percentage of reads on the primary to forward to replicas. Useful for keeping buffer pools warm
0 commit comments