跳到正文
cccskills
免费在 GitHub 公开

k6-load-testing

Authors k6 JavaScript load-test scripts (VU loops + checks + sleeps), configures the `options` block with `stages` (ramp-up patterns) and `thresholds` (p(95) latency, error rate), runs via `k6 run script.js` or `--vus / --duration` ad-hoc flags, and uses thresholds as the CI pass/fail signal. Includes a latency-percentile interpretation reference: tail ratio (p99/p50), bimodal-distribution detection, coordinated omission and why naive p99 is optimistic, and constant-vus vs constant-arrival-rate executors. Use when the project ships HTTP / WebSocket / gRPC load tests and the team wants developer-friendly JavaScript authoring, or when a k6 threshold passes but the system still feels slow.

中文简介正在准备中。当前显示原文说明。

testland/qa星标 13(GitHub 13 + cccskills 0)

实测评分 未实测

查看安装方法

包含的文件(14)

  • SKILL.md10.2 KB
  • .tessl-plugin/plugin.json826 B
  • evals/capacity-claim-for-a-customer-contract/criteria.json6.6 KB
  • evals/capacity-claim-for-a-customer-contract/task.md9.9 KB
  • evals/laptop-run-about-to-block-the-release/criteria.json6.7 KB
  • evals/laptop-run-about-to-block-the-release/task.md10.1 KB
  • evals/manager-wants-the-soak-on-every-pr/criteria.json6.1 KB
  • evals/manager-wants-the-soak-on-every-pr/task.md6.3 KB
  • evals/nightly-gate-green-while-checkout-complaints-climb/criteria.json7.0 KB
  • evals/nightly-gate-green-while-checkout-complaints-climb/task.md10.2 KB
  • evals/six-months-green-then-a-peak-hour-outage/criteria.json7.6 KB
  • evals/six-months-green-then-a-peak-hour-outage/task.md11.2 KB
  • references/ci-integration.md1.6 KB
  • references/latency-percentiles.md12.4 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

k6-load-testing

k6 tests are .js files with a default-exported function that runs once per virtual user (VU) per iteration (per k6-running). This skill covers the load-testing workflow; k6's browser, synthetic monitoring, and chaos modes share the same script structure but are out of scope here.

When to use

  • The project ships HTTP, WebSocket, or gRPC services that need performance testing.
  • The team prefers JavaScript authoring (vs. JMeter's XML, Gatling's Scala/Java, or Locust's Python).
  • A CI gate is needed on p(95) latency + error rate - k6's thresholds are designed for this.
  • The team is on Grafana Cloud (k6 integrates natively) or wants a self-hosted CLI-only flow.

If the team is already deep in JMeter, the migration cost is non- trivial - evaluate jmeter-load-testing in place. For Python / Locust shops and JVM / Gatling teams, see the Gatling and Locust references in load-testing-overview.

Install

Install via k6 installation (brew, apt/yum, choco, Docker). Pin a specific k6 version in CI rather than "latest".

Authoring

Minimal script

import http from 'k6/http';
import { check, sleep } from 'k6';

export default function () {
  const res = http.get('https://quickpizza.grafana.com/');
  check(res, { 'status was 200': (r) => r.status == 200 });
  sleep(1);
}

(Per k6-running.)

The default-exported function runs once per virtual-user iteration. check() is a non-failing assertion that contributes to the checks metric; sleep() simulates think-time between requests.

Options block - stages

Per k6-running, the options export controls the run:

export const options = {
  stages: [
    { duration: '30s',    target: 20 },   // ramp up to 20 VUs over 30s
    { duration: '1m30s',  target: 10 },   // hold ~10 VUs for 90s (gradual scale-down)
    { duration: '20s',    target: 0 },    // ramp down to 0
  ],
};

Three canonical shape patterns:

PatternStages
Smoke testOne stage, { duration: '1m', target: 1 } - sanity check.
Average load testRamp up → plateau → ramp down (the example above).
Stress testRamp past expected peak; observe where the system breaks.
Spike testSudden ramp to high VU; back to normal; verify recovery.
Soak testLong plateau (hours); verify no resource leaks over time.

Options block - thresholds

Per k6-thresholds, thresholds are "the pass/fail criteria that you define for your test metrics" - the canonical CI gate:

export const options = {
  thresholds: {
    http_req_duration: ['p(95)<500'],   // 95% of requests under 500ms
    http_req_failed:   ['rate<0.01'],   // <1% errors
    checks:            ['rate>0.99'],   // >99% of checks pass
  },
};

(Per k6-thresholds.)

The threshold expression syntax is <aggregation_method> <operator> <value>. Available aggregation methods per metric type:

Metric typeMethods
Trendavg, min, max, med, p(N) (percentile, ms)
Countercount, rate
Raterate
Gaugevalue

A test that fails any threshold exits non-zero - the canonical CI gate signal.

abortOnFail

For long-running stress / soak tests, abort early if a threshold is already violated (k6-thresholds):

thresholds: {
  http_req_duration: [
    { threshold: 'p(95)<500', abortOnFail: true, delayAbortEval: '10s' },
  ],
},

delayAbortEval postpones the abort decision to let metrics accumulate before evaluating; without it, a 1-second test could abort on a single slow request.

Running

Ad-hoc (no options block needed)

k6 run --vus 10 --duration 30s script.js

(Per k6-running.)

--vus overrides the script's options; --duration runs for a fixed time without ramps.

Standard run

k6 run script.js

options block in the script controls everything; the CLI is hands-off. Preferred for CI.

Useful flags

FlagPurpose
--out json=<file>Stream raw metrics to a JSON file.
--summary-export=<file>Write the end-of-test summary to JSON.
--quietSilence the live progress UI (CI noise).
--http-debug=fullVerbose HTTP debug for triage runs.
--env KEY=VALInject env vars accessible via __ENV.KEY.
--config <file>Externalize the options block to a JSON file.

Parsing results

The end-of-run summary prints to stdout; --summary-export writes the same data as JSON for downstream consumption:

{
  "metrics": {
    "http_req_duration": {
      "values": { "p(95)": 432.1, "avg": 198.3, ... },
      "thresholds": { "p(95)<500": { "ok": true } }
    },
    "http_req_failed": {
      "values": { "rate": 0.004, "passes": 996, "fails": 4 },
      "thresholds": { "rate<0.01": { "ok": true } }
    }
  }
}

Pipe to jq for a quick gate report:

jq -r '
  .metrics
  | to_entries[]
  | select(.value.thresholds)
  | .key + ": " + (.value.thresholds | to_entries | map("\(.key) → \(if .value.ok then "PASS" else "FAIL" end)") | join(", "))
' summary.json

CI integration

Full GitHub Actions workflow - apt install, PR + nightly triggers, summary upload via if: always() - in references/ci-integration.md. A failing threshold causes k6 run to exit non-zero, failing the job.

Interpreting latency distributions

Passing a p95 threshold is necessary but not sufficient. The full interpretation workflow - expanding summaryTrendStats to p99/p99.9, the tail ratio (p99/p50) as a spread signal, bimodal-distribution heuristics, sub-metric cross-checks (http_req_waiting / http_req_blocked), coordinated omission and HdrHistogram correction, and constant-vus vs constant-arrival-rate executor semantics - is in references/latency-percentiles.md.

Anti-patterns

Anti-patternWhy it failsFix
Hard-coded URLs / tokens in scriptScripts bind to one environment; secrets leak.Read from __ENV.API_BASE_URL, __ENV.API_TOKEN.
--vus 1000 --duration 1h from a developer laptopLaptop resource contention; client-side bottlenecks corrupt metrics.Run from a CI runner / dedicated load generator; never from a dev box for serious numbers.
Threshold p(95)<10000Practically meaningless - passes any sane API. Hides regressions.Set thresholds at meaningful budgets (500ms, 1s) tied to NFRs from the non-functional-requirement-extractor.
Soak tests in PR CIMulti-hour PR CI; team disables.Soak tests are scheduled-only; PRs run smoke / average load.
Missing sleep() between requestsHammering at full VU rate generates synthetic numbers; doesn't model real users.Include sleep(1) or randomized think-time after each iteration.
Asserting only http_req_failed rateA 30-second response that succeeds passes the rate gate but breaks UX.Always pair with http_req_duration percentile thresholds.

Limitations

  • Single-machine VU limits. A single k6 instance saturates one machine's outbound CPU / network - typically 20-50k concurrent VUs for HTTP. For higher loads, distribute via Grafana Cloud or k6 Operator on Kubernetes.
  • No native browser execution. The k6/browser module covers it but adds Chromium overhead; for browser-driven perf testing, consider lighthouse-perf instead.
  • JS sandbox limits. k6 uses goja (Go-based ES5+/some-ES6), not Node.js. npm packages with native deps don't work; pure-JS packages do. Use k6 archive to bundle.

References

  • k6-overview - main docs landing page.
  • k6-running - basic script + options + stages + ad-hoc flags.
  • k6-thresholds - threshold syntax, aggregation methods, abortOnFail / delayAbortEval.
  • jmeter-load-testing and the Gatling / Locust references in load-testing-overview - alternatives by language stack.
  • references/latency-percentiles.md - interpreting the latency distributions this skill's runs produce.
  • perf-budget-gate - downstream gate that aggregates k6 / lighthouse / load-runner verdicts.

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

Builds a CI gate that fails the build on **new** WCAG / a11y violations introduced by a PR while grandfathering pre-existing violations on a per-rule / per-page baseline. Aggregates verdicts from axe-core / pa11y / Lighthouse a11y / WAVE / IBM Equal Access scans. Use when a project has accumulated a11y debt and a strict "zero violations" gate would block every PR - the ratchet pattern lets the team ship while preventing regressions.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Workflow skill that builds an A/B-test validity checklist from an experiment proposal, walking the canonical design-correctness gates - pre-registered OEC/power/guardrails, randomization unit + SRM check, assignment integrity, telemetry, peeking discipline, novelty/primacy, post-experiment SRM re-check - into a per-experiment checklist + sign-off form. Use when launching, auditing, or governing an experiment. For pitfall mechanics (guardrails, peeking) see experiment-results-interpreter's references; to read an already-valid result use experiment-results-interpreter; for per-SDK harness tests use experiment-sdk-testing - this gates DESIGN, not SDK code.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

The single install-flow skill: the reference contract for the PWA install flow (installability gate fields, `beforeinstallprompt` handshake, per-platform paths - Android WebAPK / iOS Share menu / Firefox no-op - and the `display-mode` post-install signal, in references/install-flow-reference.md) plus the build-an-X workflow that emits the Add-to-Home-Screen suite. Walks the four-stage timeline, emitting one test per gate cell per [web.dev/articles/install-criteria][install-criteria], the deferred-prompt → `prompt()` → `userChoice` chain per [web.dev/articles/customize-install][customize-install], the iOS Safari manual-metadata branch (`apple-touch-icon`) per [web.dev/learn/pwa/installation][learn-pwa], and the post-install `(display-mode: standalone)` MQ assertion. Output: a Playwright spec with per-stage cells plus a coverage matrix. Use when a PWA's manifest, icons, or install handler change, when install conversion drops at an unknown stage, or when triaging a flaky install assertion.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Build-an-X workflow that uses an LLM to map existing tests to spec sections - given a spec doc + the test suite, the LLM identifies which tests cover which sections, surfaces uncovered sections (gap), and recommends specific tests to add. Output is a coverage matrix per spec ID. Scope is mapping tests that already exist and naming the gaps, not authoring tests for new acceptance criteria. Use when a spec doc and a test suite both exist but nobody can say which requirements are actually covered - before a release sign-off, an audit, or a decision about where to spend the next round of test effort.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Generates tests from natural-language specs (acceptance criteria, user stories, requirements) using an LLM, with confidence scoring per test case (LLM self-assessment plus heuristics: assertion quality, naming, completeness), batching uncertain cases for human review, and integration with the team's existing test framework. Use when the user asks to generate unit tests from acceptance criteria, convert user stories to test cases, automate test creation from requirements, or augment a spec-driven test suite with AI-generated stubs that are then curated before merge.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

Configures Allure Report (test-runner adapter install, `allure-results` directory wiring, `categories.json` for failure classification, `history-trend.json` retention via the copy-history-between-runs pattern), runs the Allure CLI to convert `allure-results` to a static HTML site, and uploads the report as a CI artifact. Use when the team needs richer test reporting than JUnit XML - step-level attachments, per-test history, retry tracking, and severity / epic / feature labeling across framework-agnostic adapters (pytest, Jest, JUnit, TestNG, NUnit, Mocha). As a rich static HTML report generator, it is the open-source alternative to the sunset ExtentReports (JVM/.NET per-test HTML narrative); for hosted cross-run flakiness analytics rather than a static per-run report use currents-integration.

中文简介正在准备中。当前显示原文说明。

testland/qa132026年10月20日 更新

查看 testland 的全部技能

报告此技能的问题