B19 · 壓測與效能 詳細 ROADMAP
計畫文件,不會被 Quartz 渲染。
回主 roadmap → backend/ROADMAP.md
章節目標
這是後端最實戰的章節。壓測不只是「跑 k6 看 RPS」,而是:壓測前寫的 code 跟壓測後寫的 code 有本質差異。本章大量引用 micro-service/ 現有實戰(01–05 壓測平台、06–08 bcrypt、18–19 DB bulk/pool、20 Redis/ES、33–34 cache 等),以及**「壓測前 vs 壓測後」的改造對比**——這是其他教材不會講的真實工程學。
🌱 基本介紹
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 01 | 壓測是什麼 | ⛔️ micro-service/01-why-api-stress-test | 🌿 | 跨系列 |
❓ 為什麼需要
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 02 | 為什麼寫 code 必須有壓測視角 | 02-why-code-with-stress-test-mind | 🌱 | 「能跑」vs「能扛」的差距;N+1 在 dev 看不出來、100 用戶同時才炸 |
| 03 | 為什麼壓測前後的 code 本質不同 | 03-why-code-changes-after-stress-test | 🌱 | 壓測暴露的 pattern 改造;同步 → 非同步;for loop → batch;no cache → cache;實戰對比(引用 commit 對比) |
| 04 | 為什麼本地跑 benchmark 騙自己 | 04-why-local-benchmark-lies | 🌱 | 本地無 network latency、無 DB pool 限制、無真實 concurrency;production-like 環境才準 |
🕰️ 演進
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 05 | 壓測工具演進 | 05-stress-test-tool-evolution | 🌱 | ab(Apache Bench)→ JMeter → wrk / wrk2 → Vegeta → k6(2017+ JS-based)→ Grafana k6 cloud |
🧠 知識型
F19-A 壓測基礎(既有)
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 06 | 為什麼要做 API 壓測 | ⛔️ micro-service/01-why-api-stress-test | 🌿 | 跨系列 |
| 07 | 壓測平台架構 | ⛔️ micro-service/02-stress-test-platform-architecture | 🌿 | 跨系列 |
| 08 | 控制變因 | ⛔️ micro-service/03-controlled-variables | 🌿 | 跨系列 |
| 09 | k6 腳本撰寫 | ⛔️ micro-service/04-k6-scripting | 🌿 | 跨系列 |
| 10 | Grafana Dashboard 設計 | ⛔️ micro-service/05-grafana-dashboard | 🌿 | 跨系列 |
F19-B 壓測 Scenario 設計
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 11 | Load / Stress / Spike / Soak | 11-test-types | 🌱 | 四種壓測類型、各自找什麼問題 |
| 12 | 建模使用者行為 | 12-user-behavior-modeling | 🌱 | think time、ramp-up、scenario group(如:80% 瀏覽 / 15% 下單 / 5% 搜尋) |
| 13 | Auth 壓測 | 13-auth-stress-test | 🌱 | JWT 簽驗效能、bcrypt 瓶頸(⛔️ 見 B10)、proto k6 auth scenario 案例 |
| 14 | Blue-Green 驗證壓測 | 14-blue-green-stress-test | 🌱 | 發布切換期的壓測、proto k6 scenario |
| 15 | Rolling Update 壓測 | 15-rolling-update-stress-test | 🌱 | 部署過程服務不中斷的驗證 |
| 16 | Graceful Shutdown Drain 測試 | 16-graceful-shutdown-test | 🌱 | 壓測過程觸發 SIGTERM 看有無斷線 |
| 17 | HPA 觸發壓測 | 17-hpa-trigger-test | 🌱 | 驗證 autoscaling 真的能擴、擴的速度、scale-down 策略 |
F19-C 效能分析與瓶頸
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 18 | 四大瓶頸:CPU / Memory / Network / Disk | 18-four-bottlenecks | 🌱 | 怎麼判斷哪個是瓶頸、USE method 應用 |
| 19 | 效能剖析與 profiling | 19-profiling | 🌱 | CPU profile(pprof / flamegraph)/ Heap profile / Lock contention;各語言工具 |
| 20 | Percentile 該看什麼 | 20-percentile | 🌱 | P50 / P95 / P99 / P99.9;為什麼平均值騙人;tail latency 真的重要嗎 |
F19-D 壓測前後的 Code 改造(本章獨有)
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 21 | bcrypt 瓶頸案例 | ⛔️ micro-service/06-bcrypt-bottleneck / 07-bcrypt-implementations / 08-bcrypt-vs-argon2 | 🌿 | 跨系列 |
| 22 | DB Bulk 操作改造 | ⛔️ micro-service/18-db-bulk-and-index | 🌿 | 跨系列 |
| 23 | DB Pool 調校 | ⛔️ micro-service/19-db-pool-and-infra | 🌿 | 跨系列 |
| 24 | Redis / ES 導入決策 | ⛔️ micro-service/20-storage-redis-es | 🌿 | 跨系列 |
| 25 | Cache Cold Start 問題 | ⛔️ micro-service/27-queue-redis-coldstart | 🌿 | 跨系列 |
| 26 | Cache 改造對比 | ⛔️ micro-service/33-cache-correct-usage / 34-cache-antipatterns | 🌿 | 跨系列 |
| 27 | Framework 選型對壓測的影響 | ⛔️ micro-service/37、38 | 🌿 | 跨系列 |
| 28 | N+1 → Batch 改造案例 | 28-n-plus-1-to-batch-case | 🌱 | 從 dev 看不到到壓測才爆的歷程;commit diff 對照 |
| 29 | 同步 → 非同步(async / queue)改造 | 29-sync-to-async-refactor | 🌱 | 壓測暴露阻塞點、改 queue / worker;proto 案例 |
| 30 | 壓測驅動的架構演進 | 30-stress-driven-architecture | 🌱 | 從 monolith 到 microservice 的壓測驅動決策(⛔️ 見 B08) |
F19-E Infra 與容量
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 31 | Infra free lunch | ⛔️ micro-service/21-infra-free-lunch | 🌿 | 跨系列 |
| 32 | Infra scaling / K8s 對應 | ⛔️ micro-service/22-infra-scaling-and-k8s | 🌿 | 跨系列 |
| 33 | 跨層 capacity 規劃 | ⛔️ micro-service/23-cross-layer-capacity | 🌿 | 跨系列 |
| 34 | 混合 scenario 壓測總覽 | ⛔️ micro-service/24-mixed-overview | 🌿 | 跨系列 |
F19-F 成本與優化 roadmap
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 34-2 | 成本計算 | ⛔️ micro-service/54-cost-calculation | 🌿 | 跨系列 |
| 34-3 | 成本優化 | ⛔️ micro-service/55-cost-optimization | 🌿 | 跨系列 |
| 34-4 | Optimization Roadmap 總覽 | ⛔️ micro-service/62-optimization-roadmap | 🌿 | 跨系列 |
🔧 小實作注意事項
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 35 | 寫第一個 k6 script | 35-first-k6-script | 🌱 | hello world → 加 scenario → 加 threshold → CI 整合 |
| 36 | 壓測 + Prom 對照看瓶頸 | 36-stress-with-observability | 🌱 | k6 → Prometheus → Grafana 端到端;找出 bottleneck |
| 37 | 改造一個 endpoint(壓測前 vs 壓測後 code diff) | 37-before-after-refactor | 🌱 | 從實際 commit 案例(像 bcrypt bottleneck 的修復 commit)展示 code 改造 |
💣 Anti-pattern
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 38 | 真實案例 anti-patterns | ⛔️ micro-service/29-real-world-antipatterns / 30-lessons-learned | 🌿 | 跨系列 |
| 39 | 壓測 Anti-patterns | 39-stress-test-antipatterns | 🌱 | 只看 RPS 不看 P99、本機跑壓測、無 warm-up 就量、benchmark 只跑一次、壓測結果不存 baseline、壓測沒跟 observability 一起看 |
🧰 對應檢查工具
| # | 主題 | Slug | Stage | 大綱 |
|---|
| 40 | 壓測與效能工具 | 40-stress-testing-tooling | 🌱 | k6 / Vegeta / wrk2 / JMeter / Gatling;profiling(pprof / py-spy / async-profiler / Parca);flame graph |
📎 補充
| # | 主題 | Slug | Stage | 大綱 |
|---|
| S01 | Chaos Engineering 入門 | s01-chaos-engineering | 🌱 | Netflix Chaos Monkey;故意搞事驗證韌性 |
| S02 | Continuous Load Test | s02-continuous-load-test | 🌱 | 把壓測搬進 CI,每次 PR 跑;regression 偵測 |
章節進度統計
- 知識主題:40 + 2 補充 = 42 項
- 🌿 growing:16(跨系列,micro-service 實戰最豐富)
- 🌱 seed:26
跨系列連結
- →
micro-service/ 01–05、06–08、18–24、27、29–30、33–34、37–38、54–55、62(後端壓測實戰素材庫 + 成本優化)
- →
backend/database/ B03(壓測驅動 DB 調校)
- →
backend/cache/ B13(壓測驅動 cache 導入)
- →
backend/queue/ B12(壓測驅動 async 化)
- →
backend/observability/ B17(壓測配觀測看瓶頸)
- →
backend/deployment/ B18(K8s HPA / rolling / blue-green 驗證)
- →
testing/(通用測試系列可能最後把壓測納入)