Locust Plugins
Locust Plugins is a collection of useful extensions for Locust, the open-source load testing tool. It provides implementations for various non-HTTP protocols like Playwright, Selenium/Webdriver, Kafka, FTP, and Telnet 3270, as well as enhanced reporting capabilities for TimescaleDB, Grafana, and Azure Application Insights. The library is currently at version 5.0.0 and maintains an active development cycle, often aligning with updates to Locust core.
Warnings
- breaking As of `locust-plugins` version 5.0.0, the `MqttUser`, `SocketIOUser`, and `RestUser` classes have been removed from this library. They are now part of Locust core.
- breaking The `--profile` command-line argument was removed in `locust-plugins` 4.7.0. It has been integrated into Locust core functionality.
- gotcha User types like `PlaywrightUser` and `WebdriverUser` (Selenium) are resource-intensive. Running too many concurrent browser instances per worker can lead to high CPU usage and degraded performance.
- gotcha When implementing custom non-HTTP User classes (or using older versions of `SocketIOUser`), avoid directly calling blocking receive methods (e.g., `self.ws.recv()`).
- gotcha For logging and graphing results using TimescaleDB and Grafana, ensure you configure the `--timescale` argument when running Locust and have a TimescaleDB instance set up.
Install
-
pip install locust-plugins -
pip install 'locust-plugins[all]'
Imports
- PlaywrightUser
from locust_plugins.users.playwright import PlaywrightUser
- Timescale
from locust_plugins.listeners.timescale import Timescale
- ApplicationInsights
from locust_plugins.listeners.appinsights import ApplicationInsights
- FtpUser
from locust_plugins.users.ftpuser import FtpUser
- MqttUser
from locust.contrib.mqtt import MqttUser
- SocketIOUser
from locust.contrib.socketio import SocketIOUser
- RestUser
from locust.contrib.rest import RestUser
Quickstart
from locust import task, between
from locust_plugins.users.playwright import PlaywrightUser
class MyPlaywrightUser(PlaywrightUser):
host = "https://www.google.com"
wait_time = between(2, 5)
@task
async def search_for_locust(self):
page = self.page # Access the Playwright page object
await page.goto(self.host)
await page.fill('textarea[name="q"]', "Locust load testing")
await page.press('textarea[name="q"]', 'Enter')
await page.wait_for_selector("#search"); # Wait for search results
await page.screenshot(path="locust_search.png")
self.environment.events.request.fire(
request_type="Playwright",
name="/search",
response_time=1000, # Dummy response time
response_length=100,
context={
"user": self.id
},
exception=None,
)