Awesome K6
K6 是現代化的負載測試工具,使用 JavaScript 編寫測試腳本,專為開發者和 DevOps 團隊設計。
官方資源
核心文件
- k6 Documentation - 官方文件
- k6 GitHub Repository - 開源儲存庫
- Grafana k6 Cloud - 雲端服務
安裝與入門
API 參考
核心 API
- JavaScript API: open - 檔案讀取
- fail([err]) - 強制停止測試
- sleep(t) - 等待指定時間
HTTP 模組
- http.get() - GET 請求
- http.post() - POST 請求
- http.batch() - 批次請求
測試生命週期
- Test lifecycle - 測試執行流程
- Execution context variables - 執行環境變數
快速入門
基本範例
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
vus: 10, // 10 個虛擬使用者
duration: '30s', // 執行 30 秒
};
export default function () {
http.get('https://test.k6.io');
sleep(1);
}
執行測試
# 安裝 k6
brew install k6 # macOS
# 或 sudo apt install k6 # Ubuntu
# 執行測試
k6 run script.js
# 輸出結果到檔案
k6 run --out json=results.json script.js
擴充套件
報告工具
- k6-reporter - HTML 報告生成器
- k6-html-reporter - 另一個 HTML 報告工具
輸出格式
- JSON - 結構化數據輸出
- InfluxDB - 時間序列資料庫
- Grafana - 視覺化儀表板
- Prometheus - 監控系統整合
中文教學資源
部落格文章
進階主題
效能測試概念
國外教學
- API Performance Testing using k6. Write your first tests in Grafana k6 | by Updesh Kumar Singh | Medium
- Performance Testing with k6
- Performance and load testing with K6: manual, metrics and reports | PFLB
官方部落格
- Ways to visualize k6 results
- k6 Blog - 官方部落格
See Also
- Awesome Tech Stack - 技術棧資源整理
- JMeter - 另一個負載測試工具
- Artillery - 現代負載測試工具
- Locust - Python 負載測試框架