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: docs/features/global_cache_pooling.md
+86-50Lines changed: 86 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -48,7 +48,8 @@ Ready-to-use example scripts are available in [examples/cache_storage/](../../..
48
48
|--------|----------|-------------|
49
49
|`run.sh`| Multi-Instance | Two standalone instances sharing cache |
50
50
|`run_03b_pd_storage.sh`| PD Disaggregation | P+D instances with global cache pooling |
51
-
|`run_ha.sh`| High Availability | etcd + multi-master leader election, verifies failover after killing the leader |
51
+
|`run_ha.sh`| High Availability (etcd) | etcd + multi-master leader election, verifies failover after killing the leader |
52
+
|`run_ha_redis.sh`| High Availability (redis) | single redis + multi-master leader election, verifies failover after killing the leader |
52
53
53
54
## Prerequisites
54
55
@@ -287,14 +288,19 @@ curl -X POST "http://0.0.0.0:52700/v1/chat/completions" \
287
288
288
289
### Scenario 3: High-Availability (HA) Deployment
289
290
290
-
A single master is a single point of failure; if it crashes, cluster operations pause. For production, use the **etcd + multi-master** mode: multiple `mooncake_master` instances perform leader election through etcd. When the leader fails, a standby is automatically re-elected, transparently to clients.
291
+
A single master is a single point of failure; if it crashes, cluster operations pause. For production, run multiple `mooncake_master` instances that perform leader election through a coordination backend. When the leader fails, a standby is automatically re-elected, transparently to clients.
292
+
293
+
Two coordination backends are supported:
294
+
295
+
-**etcd** (`run_ha.sh`): a 3-node etcd cluster does election and metadata storage.
296
+
-**redis** (`run_ha_redis.sh`): a single redis instance does lease-based election. Use this to avoid introducing etcd as an extra component.
291
297
292
298
**Architecture:**
293
299
294
300
```
295
301
┌──────────────────────────────────────┐
296
-
│ etcd cluster (3 nodes) │
297
-
│ leader election / metadata store │
302
+
│ coordination backend (etcd / redis) │
303
+
│ leader election (master_view) │
298
304
└───────────────────┬──────────────────┘
299
305
│ election (master_view)
300
306
┌─────────────────────┼─────────────────────┐
@@ -304,47 +310,30 @@ A single master is a single point of failure; if it crashes, cluster operations
304
310
│ rpc:8081 │ │ rpc:8082 │ │ rpc:8083 │
305
311
│ (leader) │ │ (standby) │ │ (standby) │
306
312
└──────┬──────┘ └─────────────┘ └─────────────┘
307
-
│ FastDeploy clients discover the current leader via etcd
313
+
│ FastDeploy clients discover the current leader via the backend
308
314
┌──────┴───────┐
309
315
▼ ▼
310
316
server_0 server_1
311
317
```
312
318
313
-
#### Prerequisites
314
-
315
-
**1. Install etcd**
316
-
317
-
Download and extract etcd (v3.5.30 in this example), then add `etcd` / `etcdctl` to `PATH`:
In HA mode, both `metadata_server` and `master_server_addr` use the `etcd://` prefix pointing to the etcd cluster; clients discover the current leader through etcd (`ha_mooncake_config.json`):
367
+
Both `metadata_server` and `master_server_addr` use the `etcd://` prefix; clients discover the current leader through etcd:
364
368
365
369
```json
366
370
{
@@ -373,45 +377,77 @@ In HA mode, both `metadata_server` and `master_server_addr` use the `etcd://` pr
373
377
}
374
378
```
375
379
376
-
#### One-Command Launch & Failover Verification
380
+
**3. Run**
381
+
382
+
```bash
383
+
cd examples/cache_storage
384
+
bash run_ha.sh
385
+
```
377
386
378
-
A single self-contained script `examples/cache_storage/run_ha.sh` handles the whole flow — it starts the etcd cluster and the HA master cluster inline (each via a 3-iteration loop), so no separate `start_*.sh` is needed.
387
+
The script starts a 3-node etcd cluster (client ports 12379/22379/32379), 3 HA masters (rpc 8081/8082/8083), and 2 FastDeploy instances; the leader address is written to the etcd key `mooncake-store/mooncake_cluster/master_view`.
Both `metadata_server` and `master_server_addr` use the `redis://` prefix pointing to the single redis instance:
401
+
402
+
```json
403
+
{
404
+
"metadata_server": "redis://127.0.0.1:6399",
405
+
"global_segment_size": 1000000000,
406
+
"local_buffer_size": 134217728,
407
+
"protocol": "rdma",
408
+
"rdma_devices": "",
409
+
"master_server_addr": "redis://127.0.0.1:6399"
410
+
}
411
+
```
412
+
413
+
**2. Run**
381
414
382
415
```bash
383
416
cd examples/cache_storage
384
-
bash run_ha.sh
417
+
bash run_ha_redis.sh
385
418
```
386
419
387
-
What `run_ha.sh` does:
420
+
The script starts a single redis instance (port 6399), 3 HA masters (rpc 8081/8082/8083) launched with `--ha_backend_type redis --ha_backend_connstring redis://127.0.0.1:6399`, and 2 FastDeploy instances. The master_view is a redis HASH at `mooncake-store/{mooncake_cluster}/master_view`.
Both scripts run the same flow and verify failover:
388
431
389
-
1.**Start the etcd cluster**: a loop launches 3 etcd nodes (client ports 12379/22379/32379) forming a raft cluster, after a port check.
390
-
2.**Start 3 HA masters**: a loop launches 3 `mooncake_master` (rpc 8081/8082/8083, metrics 9091/9092/9093), each with `--enable_ha --etcd_endpoints ... --rpc_port ...`, electing one leader via etcd. The leader address is written to the etcd key `mooncake-store/mooncake_cluster/master_view`.
391
-
3.**Start 2 FastDeploy instances**, both joining the same cache pool with `--kvcache-storage-backend mooncake`.
392
-
4.**Verify pooling (before failover)**: warm up prompt **A** on `server_0`, then send the same prompt to `server_1`, which should hit the global cache.
393
-
5.**Kill the leader**: the script reads the current leader's `rpc_port` from etcd, `kill -9`s that process, triggering re-election.
394
-
6.**Verify pooling (after failover)**: once etcd's `master_view`is updated to the new leader, warm up a **brand-new** prompt **B**(never sent before) on `server_0`, then reuse it on `server_1`. Using a fresh prompt ensures the hit on `server_1`can only come from the new leader's global pool, rather than stale local cache from step 4.
432
+
1. Start the coordination backend (etcd cluster / single redis).
433
+
2. Start 3 HA masters; one is elected leader and published to `master_view`.
434
+
3. Start 2 FastDeploy instances, both joining the same cache pool with `--kvcache-storage-backend mooncake`.
435
+
4.**Before failover**: warm up prompt **A** on `server_0`, then send the same prompt to `server_1`, which should hit the global cache.
436
+
5.**Kill the leader**: read the current leader's `rpc_port` from the backend and `kill -9` it, triggering re-election.
437
+
6.**After failover**: once `master_view`updates to the new leader, warm up a **brand-new** prompt **B** on `server_0`, then reuse it on `server_1`. Using a fresh prompt ensures the hit can only come from the new leader's global pool, not stale local cache from step 4.
0 commit comments