testing-perf について
テストエンジニアや開発者向けの性能・負荷テストガイドで、k6、Locust、pytest の実行最適化を扱います。テスト種別、並列実行、データベース分離、チェックリストのパターンを提供します。
主な機能
- 01k6 のしきい値、ステージ、カスタム指標
- 02Locust による負荷テストパターン
- 03負荷・ストレス・スパイク・ソークテストの種別
- 04pytest-xdist の並列実行とマーカー
- 05並列テスト用のワーカー別データベース分離
- 06性能テストと pytest のチェックリスト
活用シーン
- 01API の段階的な負荷テストを設定する
- 02想定トラフィックに応じたテスト種別を選ぶ
- 03pytest-xdist でテストスイートを高速化する
- 04並列テストのワーカー間でデータベースを分離する
インストール
コマンドをコピーしてターミナルで実行します。
$
npx skills add https:/ / github.com/ yonatangross/ orchestkit --skill testing-perfインストール後、Claude Code で/testing-perfを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
test-cases.jsonchecklists/performance-checklist.mdpytest-production-checklist.mdreferences/custom-plugins.mdk6-patterns.mdxdist-parallel.mdrules/_sections.mdexecution.mdperf-k6.mdperf-locust.mdperf-types.mdpytest-execution.mdpytest-plugins.mdscripts/test-case-template.md詳細
パフォーマンス/負荷テストのパターン
パフォーマンステスト、負荷テスト、pytest の実行最適化に特化したスキルです。k6、Locust、pytest-xdist による並列実行、カスタムプラグイン、テスト種別の分類を扱います。
クイックリファレンス
| 分野 | ファイル | 目的 |
|---|---|---|
| k6 負荷テスト | rules/perf-k6.md | しきい値、ステージ、カスタムメトリクス、CI 連携 |
| Locust テスト | rules/perf-locust.md | Python の負荷テスト、タスクの重み付け、認証フロー |
| テスト種別 | rules/perf-types.md | 負荷、ストレス、スパイク、ソークテストのパターン |
| 実行 | rules/execution.md | カバレッジレポート、並列実行、失敗分析 |
| Pytest マーカー | rules/pytest-execution.md | カスタムマーカー、xdist 並列実行、ワーカーの分離 |
| Pytest プラグイン | rules/pytest-plugins.md | ファクトリーフィクスチャ、プラグインフック、アンチパターン |
| k6 のパターン | references/k6-patterns.md | 段階的な負荷増加、認証済みリクエスト、テスト種別 |
| xdist 並列実行 | references/xdist-parallel.md | 分散モード、ワーカーの分離、CI 設定 |
| カスタムプラグイン | references/custom-plugins.md | conftest プラグイン、インストール可能なプラグイン、フックのリファレンス |
| パフォーマンスチェックリスト | checklists/performance-checklist.md | 計画、セットアップ、メトリクス、負荷パターン、分析 |
| Pytest チェックリスト | checklists/pytest-production-checklist.md | 設定、マーカー、並列実行、フィクスチャ、CI/CD |
| テストテンプレート | scripts/test-case-template.md | テストケースのドキュメント全体のテンプレート |
k6 クイックスタート
しきい値と段階的な負荷増加を設定して、負荷テストを準備します。
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '30s', target: 20 }, // Ramp up
{ duration: '1m', target: 20 }, // Steady state
{ duration: '30s', target: 0 }, // Ramp down
],
thresholds: {
http_req_duration: ['p(95)<500'], // 95th percentile under 500ms
http_req_failed: ['rate<0.01'], // Less than 1% error rate
},
};
export default function () {
const res = http.get('http://localhost:8000/api/health');
check(res, {
'status is 200': (r) => r.status === 200,
'response time < 200ms': (r) => r.timings.duration < 200,
});
sleep(1);
}
実行:k6 run --out json=results.json tests/load/api.js
k6 v1.0 以降(2025 年 5 月)— 変更点
- TypeScript ネイティブ対応:
k6 run tests/load/api.ts— コンパイルの手順は不要です。 - 拡張機能の自動プロビジョニング:
k6 runが必要な拡張機能を自動的に取得します。ほとんどのワークフローで、手動のxk6 buildは不要になりました。 - ブラウザーモジュールのインポート:
import browser from 'k6/browser'— 以前のk6/experimental/browserパスは v0.52 以降で削除されました。/experimental/を使用する生成コードは失敗します。 - OTLP 出力を標準搭載:
k6 run --out experimental-opentelemetry=...— 結果をトレースバックエンドに直接ストリーミングします。
import http from 'k6/http'
import browser from 'k6/browser'
import { check } from 'k6'
export const options = { vus: 5, duration: '30s' }
export default async function () {
const page = await browser.newPage()
await page.goto('https://example.com')
check(page, { 'title present': async p => (await p.title()).length > 0 })
await page.close()
}
パフォーマンステストの種別
| 種別 | 時間 | VU 数 | 目的 | 使用タイミング |
|---|---|---|---|---|
| 負荷 | 5~10 分 | 想定トラフィック | 通常条件を検証する | リリースごと |
| ストレス | 10~20 分 | 想定の 2~3 倍 | 限界点を見つける | リリース前 |
| スパイク | 5 分 | 突発的な 10 倍の急増 | オートスケーリングをテストする | イベント前 |
| ソーク | 4~12 時間 | 通常負荷 | メモリリークを検出する | 毎週/毎晩 |
pytest の並列実行
pytest-xdist でテストスイートを高速化します。
# pyproject.toml
[tool.pytest.ini_options]
addopts = ["-n", "auto", "--dist", "loadscope"]
markers = [
"slow: marks tests as slow",
"smoke: critical path tests for CI/CD",
]
# Run with parallel workers and coverage
pytest -n auto --dist loadscope --cov=app --cov-report=term-missing --maxfail=3
# CI fast path — skip slow tests
pytest -m "not slow" -n auto
# Debug mode — single worker
pytest -n 0 -x --tb=long
ワーカーデータベースの分離
データベースを使うテストを並列実行する場合は、ワーカーごとに分離します。
@pytest.fixture(scope="session")
def db_engine(worker_id):
db_name = f"test_db_{worker_id}" if worker_id != "master" else "test_db"
engine = create_engine(f"postgresql://localhost/{db_name}")
yield engine
engine.dispose()
主な目標値
| メトリクス | 目標 | ツール |
|---|---|---|
| p95 応答時間 | < 500ms | k6 |
| p99 応答時間 | < 1000ms | k6 |
| エラー率 | < 1% | k6 / Locust |
| ビジネスロジックのカバレッジ | 90% | pytest-cov |
| クリティカルパスのカバレッジ | 100% | pytest-cov |
選択ガイド
| シナリオ | 推奨 |
|---|---|
| JavaScript/TypeScript チーム | 負荷テストには k6 |
| Python チーム | 負荷テストには Locust |
| CI のしきい値が必要 | k6(しきい値のサポートを標準搭載) |
| 分散テストが必要 | Locust(分散モードを標準搭載) |
| テストスイートの実行が遅い | pytest-xdist と -n auto |
| 並列実行でテストが不安定 | フィクスチャをグループ化する --dist loadscope |
| DB 負荷の高いテスト | worker_id を使ってワーカーごとに分離したデータベース |
関連スキル
ork:testing-unit— 単体テストのパターン、pytest フィクスチャork:testing-e2e— Playwright によるエンドツーエンドのパフォーマンステストork:performance— Core Web Vitals と最適化のパターン
コメント
Markdown 対応