Locust – Simple Open-Source Load Testing

Curiositry1 pts0 comments

Locust - A modern load testing framework

An open source load testing tool.

Define user behaviour with Python code, and swarm your system with<br>millions of simultaneous users.

Tweet

Follow @locustio

Define user behaviour in code

No need for clunky UIs or bloated XML. Just plain code.

Distributed & Scalable

Locust supports running load tests distributed over multiple machines,<br>and can therefore be used to simulate millions of simultaneous users

Proven & Battle-tested

Locust has been used to simulate millions of simultaneous users.<br>Battlelog, the web app for the Battlefield games, is load tested<br>using Locust, so one can really say Locust is Battle tested ;).

Need Dedicated Support?

Locust.cloud provides dedicated commercial support for Locust.

I'm impressed not more people talk about locust (http://locust.io/).<br>The thing is awesome :) Shoutout too the guys from ESN :)

Armin Ronacher<br>@mitsuhiko<br>Author of Flask, Jinja2 & more

it’s become a mandatory part of the development of any large scale<br>HTTP service built at DICE at this point.

Joakim Bodin<br>@jbripley<br>Lead Software Engineer at EA/DICE

locust.io is pretty fantastic, wish it had a bit more in the way<br>of docs for non-HTTP stuff though

Alex Gaynor<br>@alex_gaynor<br>Django & PyPy core developer

locustfile.py

from locust import HttpUser, between, task

class WebsiteUser(HttpUser):<br>wait_time = between(5, 15)

def on_start(self):<br>self.client.post("/login", {<br>"username": "test_user",<br>"password": ""<br>})

@task<br>def index(self):<br>self.client.get("/")<br>self.client.get("/static/assets.js")

@task<br>def about(self):<br>self.client.get("/about/")

# This locust test script example will simulate a user<br># browsing the Locust documentation on https://docs.locust.io

import random<br>from locust import HttpUser, between, task<br>from pyquery import PyQuery

class AwesomeUser(HttpUser):<br>host = "https://docs.locust.io/en/latest/"

# we assume someone who is browsing the Locust docs,<br># generally has a quite long waiting time (between<br># 10 and 600 seconds), since there's a bunch of text<br># on each page<br>wait_time = between(10, 600)

def on_start(self):<br># start by waiting so that the simulated users<br># won't all arrive at the same time<br>self.wait()<br># assume all users arrive at the index page<br>self.index_page()<br>self.urls_on_current_page = self.toc_urls

@task(10)<br>def index_page(self):<br>r = self.client.get("")<br>pq = PyQuery(r.content)<br>link_elements = pq(".toctree-wrapper a.internal")<br>self.toc_urls = [<br>l.attrib["href"] for l in link_elements

@task(50)<br>def load_page(self):<br>url = random.choice(self.toc_urls)<br>r = self.client.get(url)<br>pq = PyQuery(r.content)<br>link_elements = pq("a.internal")<br>self.urls_on_current_page = [<br>l.attrib["href"] for l in link_elements

@task(30)<br>def load_sub_page(self):<br>url = random.choice(self.urls_on_current_page)<br>r = self.client.get(url)

# An example on how to use and nest TaskSets

from locust import HttpUser, TaskSet, task, between

class ForumThread(TaskSet):<br>pass

class ForumPage(TaskSet):<br># wait_time can be overridden for individual TaskSets<br>wait_time = between(10, 300)

# TaskSets can be nested multiple levels<br>tasks = {<br>ForumThread:3

@task(3)<br>def forum_index(self):<br>pass

@task(1)<br>def stop(self):<br>self.interrupt()

class AboutPage(TaskSet):<br>pass

class WebsiteUser(HttpUser):<br>wait_time = between(5, 15)

# We can specify sub TaskSets using the tasks dict<br>tasks = {<br>ForumPage: 20,<br>AboutPage: 10,

# We can use the @task decorator as well as the<br># tasks dict in the same Locust/TaskSet<br>@task(10)<br>def index(self):<br>pass

$ locust -f locustfile.py

Example code

A fundamental feature of Locust is that you describe all your test in<br>Python code. No need for clunky UIs or bloated XML, just plain code.

Select example

Installation

The easiest way to install Locust is from PyPI,<br>using pip:

> pip install locust

Read more detailed installations instructions in the<br>documentation.

Get the source code at Github.

Cloud Hosted Locust

We are working on a hosted cloud version of Locust. It's the simplest way to set up large-scale load tests<br>with detailed reporting.

Check it out at locust.cloud

Maintainers & Contributors

Jonatan Heyman

@jonatanheyman

Corey Goldberg

@cgoldberg

Peter Darrow

@pmdarrow

Justin Iso

@JustinIso

Alden Peterson

Mark Beacom

@mbeacom

Lars Holmberg

@cyberw

Andrew Baldwin

mboutet

tdadela

DennisKrone

mquinnfd

HeyHugo

Trouv

max-rocket-internet

cgbystrom

ajt89

Jahaja

FooQoo

mgor

delulu

aek

samuelspagl

And more than 200<br>additional awesome contributors!

Original Authors

Jonatan Heyman

@jonatanheyman

Follow @jonatanheyman

Carl Byström

@cgbystrom

Follow @cgbystrom

Joakim Hamrén

@jahaaja

Follow @jahaaja

Hugo Heyman

@hugoheyman

Follow @hugoheyman

Tweet

Follow @locustio

locust self task between code client

Related Articles