locust
Installation
Review the source and dependencies with a prompt. A package is available to download.
Install with an AI assistant
Copy the prompt so your assistant can review the pinned revision and dependencies first.
View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "locust" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-7f51d9d3069042e62e558840881199517657e7ac435094edd7e144df008cf386. Verify the upstream source and version against https://skillhub.cn/skills/user_3c6cb52e/model-user-behavior-and-run-distributed-load-tests-before-backend-changes-face-real-traffic-with-locust before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.
Source and setup
skillhub.cn
Setup guidance pending
See the original source for supported tools, dependencies, and permissions.
Installation test pending
Writes realistic user-flow scripts in Python and distributes them across worker processes so agents can perform load testing on a service before release.
Introduction source: third_party · user_3c6cb52e · 1.0.0 Reference
SkillPi interpretation
- Tasks
- When the user wants to perform load testing using Python with Locust's distributed architecture and real-time web UI. Also use when the user mentions "locust," "Python load testing," "distributed load test," "locust web UI," or "locustfile." For JavaScript-based load testing, see k6 or artillery.
- Testing
- Not tested
Browse files
Frontmatter
name: locust
description: When the user wants to perform load testing using Python with Locust's distributed architecture and real-time web UI. Also use when the user mentions "locust," "Python load testing," "distributed load test," "locust web UI," or "locustfile." For JavaScript-based load testing, see k6 or artillery.
metadata:
author: terminal-skills
version: "1.0.0"
category: development
tags:
- load-testing
- python
- distributed
- performanceLocust
Overview
You are an expert in Locust, the Python-based load testing framework. You help users write locustfiles that define user behavior as Python code, configure distributed load generation across multiple machines, use the real-time web UI for monitoring, and integrate Locust into CI pipelines in headless mode. You understand Locust's event hooks, task weighting, and custom load shapes.
Instructions
Initial Assessment
Before writing a locustfile:
- Target — What service or API are you testing?
- User behavior — What does a typical user session look like?
- Scale — How many concurrent users? Distributed across machines?
- Mode — Interactive (web UI) or headless (CI)?
Basic Locustfile
# locustfile.py — Basic Locust load test for an e-commerce API.
# Simulates users browsing products and adding items to cart.
from locust import HttpUser, task, between
class WebsiteUser(HttpUser):
wait_time = between(1, 3)
host = "https://api.example.com"
def on_start(self):
"""Called when a simulated user starts. Login once per user."""
self.client.post("/login", json={
"username": "testuser",
"password": "testpass"
})
@task(3)
def browse_products(self):
self.client.get("/products")
@task(2)
def view_product(self):
self.client.get("/products/1")
@task(1)
def add_to_cart(self):
self.client.post("/cart", json={"product_id": 1, "quantity": 1})
Custom Load Shapes
# load_shape.py — Custom load shape that simulates daily traffic patterns.
# Ramps up in the morning, peaks at noon, drops in the evening.
from locust import HttpUser, task, between, LoadTestShape
class ApiUser(HttpUser):
wait_time = between(1, 5)
@task
def get_data(self):
self.client.get("/api/data")
class DailyTrafficShape(LoadTestShape):
stages = [
{"duration": 60, "users": 20, "spawn_rate": 5},
{"duration": 120, "users": 100, "spawn_rate": 10},
{"duration": 180, "users": 200, "spawn_rate": 20},
{"duration": 120, "users": 100, "spawn_rate": 10},
{"duration": 60, "users": 0, "spawn_rate": 20},
]
def tick(self):
run_time = self.get_run_time()
elapsed = 0
for stage in self.stages:
elapsed += stage["duration"]
if run_time < elapsed:
return (stage["users"], stage["spawn_rate"])
return None
Distributed Testing
# distributed-run.sh — Run Locust in distributed mode across multiple machines.
# One master coordinates, workers generate the actual load.
# Install
pip install locust
# Start master (web UI on port 8089)
locust --master --host https://api.example.com
# Start workers (run on each worker machine)
locust --worker --master-host=192.168.1.100
# Headless distributed run
locust --master --headless -u 1000 -r 50 --run-time 5m \
--expect-workers 4 --host https://api.example.com
Event Hooks
# events_example.py — Using Locust event hooks for custom reporting.
# Logs failures to a file and sends alerts on high error rates.
from locust import HttpUser, task, between, events
import logging
logger = logging.getLogger("locust_custom")
@events.request.add_listener
def on_request(request_type, name, response_time, response_length, exception, **kwargs):
if exception:
logger.error(f"FAILED: {request_type} {name} - {exception}")
@events.test_stop.add_listener
def on_test_stop(environment, **kwargs):
stats = environment.runner.stats
total = stats.total
if total.fail_ratio > 0.05:
logger.critical(f"ALERT: Error rate {total.fail_ratio:.1%} exceeds 5% threshold")
class ApiUser(HttpUser):
wait_time = between(1, 3)
@task
def get_endpoint(self):
self.client.get("/api/health")
Headless CI Mode
# .github/workflows/locust.yml — Run Locust headless in GitHub Actions.
# Exports CSV results as pipeline artifacts.
name: Load Test
on:
push:
branches: [main]
jobs:
locust:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: pip install locust
- run: |
locust --headless -u 50 -r 10 --run-time 2m \
--host https://api.example.com \
--csv results \
-f tests/locustfile.py
- uses: actions/upload-artifact@v4
if: always()
with:
name: locust-results
path: results_*.csvCurrent listing version
1.0.0
Quality assessment
Out of 100 · Assessment report from SkillPi LAB.
Highlights
- 提供 Locust 负载测试的完整端到端指导,涵盖 locustfile 编写、分布式测试、自定义负载形状、事件钩子、CI 集成等核心场景
Highlights
- 触发词覆盖全面,包括 locust、Python load testing、distributed load test、locust web UI、locustfile 等多种变体
Areas to improve
-
缺少 When to Use 章节 Reported severity: Minor
文档未明确说明何时使用此 Skill
Recommendation: 建议在 Overview 后添加 When to Use 章节,明确使用场景
-
缺少端到端完整示例 Reported severity: Minor
虽然有多个代码片段,但缺少一个完整的端到端示例
Recommendation: 建议添加一个完整的端到端示例,展示从编写 locustfile 到运行测试的完整流程
Highlights
- 文档结构清晰,包含多个实用代码示例,frontmatter 完整
Highlights
- 代码示例参数正确,工具来源明确,事件钩子中处理异常,可靠性良好
The arithmetic mean of the first four original scores, rounded to a whole number.
Static text checks
100 / 100 · skillpi-20261123-no-r3-v1
No current rules matched the text.
This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.
Permissions and checks before use
Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.
-
Install or fetch external dependencies
Use official sources and pin versions. Check install scripts in an isolated environment. This document check does not cover code downloaded later.
Mentioned in main document · lines 103, 163
Domains or addresses referenced in the document
These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.
- api.example.com
Security rating and access scope
safe · Static evidence review; not a runtime safety guarantee.
Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.
User discussion
No verified reviews yet.