HTTP Users
Overview
LoadDensity ships two HTTP user templates, both wired through the same
request_executor and scenario_runner modules:
http_user— wrapslocust.HttpUser(requestsunder the hood).fast_http_user— wrapslocust.FastHttpUser(geventhttpclient, much higher RPS).
Choose fast_http_user for high-load scenarios. Use http_user
when you need requests-specific features or middleware.
Task fields
Every HTTP task is a dict; the runner forwards the fields below to the underlying client. Anything else is ignored.
Field |
Meaning |
|---|---|
|
|
|
Target URL (absolute or relative to |
|
Locust event name; defaults to the URL. |
|
Dict of request headers. |
|
Query string parameters (dict or list of pairs). |
|
Body serialised as JSON. |
|
Form-encoded body (dict, list, or str). |
|
Dict of cookies. |
|
Per-request timeout in seconds. |
|
Forwarded directly to the client. |
|
|
|
Response assertions (see Assertions & Extractors). |
|
Response extractors (see Parameter Resolver). |
|
Scenario flow controls (see Scenario Modes). |
Example
from je_load_density import start_test
start_test(
user_detail_dict={"user": "fast_http_user"},
user_count=50,
spawn_rate=10,
test_time=60,
variables={"base": "https://api.example.com"},
tasks=[
{"method": "post", "request_url": "${var.base}/login",
"json": {"email": "u@example.com", "password": "secret"},
"extract": [
{"var": "auth", "from": "json_path", "path": "data.token"}
]},
{"method": "get", "request_url": "${var.base}/profile",
"headers": {"Authorization": "Bearer ${var.auth}"},
"assertions": [{"type": "status_code", "value": 200}]},
],
)