分阶段扩展:先用 read replica + 缓存扩展读,然后用分片(Vitess)扩展写——并且在做任何事之前先加入连接池(connection pooling),因为它是最便宜的 10 倍提升。读和写的扩展方式不同,所以别在第一天就求助于分片。
┌─▶ Cache (Redis) ── hit ──▶ return
App ─▶ Pool(PgBouncer/ProxySQL) miss ▼
│ ┌─▶ Read replica 1 ┐
├──── reads ─────────┼─▶ Read replica 2 ┼─ (async replication)
│ └─▶ Read replica N ┘
└──── writes ──▶ Primary ──▶ (later) Vitess shards ─▶ Primary A / Primary B
第 0 步:连接池
每个 MySQL 连接都消耗内存和一个线程。在 100 倍流量下,你会在耗尽 CPU 之前很久就先耗尽 。像 或 这样的连接池,把数千个应用连接复用到几百个 DB 连接上。这是一次配置变更,而非重构——先做它。
