Skip to content

Commit

Permalink
Merge branch 'master' into geventhttpclient
Browse files Browse the repository at this point in the history
  • Loading branch information
heyman committed Jul 15, 2018
2 parents 40aebc6 + c59360e commit f02363a
Show file tree
Hide file tree
Showing 33 changed files with 665 additions and 229 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ locust.egg-info/**
locustio.egg-info/**
docs/_build/**
mock.*.egg
unittest2-*.egg/
dist/**
.idea/**
*.iml
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
sudo: false
language: python
cache: pip
matrix:
include:
- python: 3.6
Expand All @@ -8,8 +9,6 @@ matrix:
env: TOXENV=py35
- python: 3.4
env: TOXENV=py34
- python: 3.3
env: TOXENV=py33
- python: 2.7
env: TOXENV=py27
addons:
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
coverage:
coverage run -m unittest2 discover
coverage run -m unittest discover

test:
unit2 discover
tox

release:
rm dist/* && python setup.py sdist && twine upload dist/*
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
[![Build Status](https://img.shields.io/travis/locustio/locust.svg)](https://travis-ci.org/locustio/locust)
[![codecov](https://codecov.io/gh/locustio/locust/branch/master/graph/badge.svg)](https://codecov.io/gh/locustio/locust)
[![license](https://img.shields.io/github/license/locustio/locust.svg)](https://github.com/locustio/locust/blob/master/LICENSE)
[![PyPI](https://img.shields.io/pypi/v/locustio.svg)](https://pypi.python.org/pypi/locustio)
[![PyPI](https://img.shields.io/pypi/pyversions/locustio.svg)](https://pypi.python.org/pypi/locustio)
[![PyPI](https://img.shields.io/pypi/v/locustio.svg)](https://pypi.org/project/locustio/)
[![PyPI](https://img.shields.io/pypi/pyversions/locustio.svg)](https://pypi.org/project/locustio/)
[![GitHub contributors](https://img.shields.io/github/contributors/locustio/locust.svg)](https://github.com/locustio/locust/graphs/contributors)

## Links

* Website: <a href="http://locust.io">locust.io</a>
* Documentation: <a href="http://docs.locust.io">docs.locust.io</a>
* Website: <a href="https://locust.io">locust.io</a>
* Documentation: <a href="https://docs.locust.io">docs.locust.io</a>
* Support/Questions: [Slack signup](https://slack.locust.io/)

## Description
Expand Down Expand Up @@ -50,7 +50,7 @@ of callbacks, your code looks and behaves like normal, blocking Python code.

## Documentation

More info and documentation can be found at: <a href="http://docs.locust.io/">http://docs.locust.io/</a>
More info and documentation can be found at: <a href="https://docs.locust.io/">https://docs.locust.io/</a>

## Questions/help?

Expand All @@ -62,10 +62,10 @@ Open a Github issue and follow the template listed there.

## Authors

- <a href="http://cgbystrom.com">Carl Bystr&ouml;m</a> (@<a href="http://twitter.com/cgbystrom">cgbystrom</a> on Twitter)
- <a href="http://heyman.info">Jonatan Heyman</a> (@<a href="http://twitter.com/jonatanheyman">jonatanheyman</a> on Twitter)
- Joakim Hamrén (@<a href="http://twitter.com/Jahaaja">Jahaaja</a>)
- Hugo Heyman (@<a href="http://twitter.com/hugoheyman">hugoheyman</a>)
- <a href="http://cgbystrom.com">Carl Bystr&ouml;m</a> (@<a href="https://twitter.com/cgbystrom">cgbystrom</a> on Twitter)
- <a href="http://heyman.info">Jonatan Heyman</a> (@<a href="https://twitter.com/jonatanheyman">jonatanheyman</a> on Twitter)
- Joakim Hamrén (@<a href="https://twitter.com/Jahaaja">Jahaaja</a>)
- Hugo Heyman (@<a href="https://twitter.com/hugoheyman">hugoheyman</a>)

## License

Expand All @@ -74,4 +74,4 @@ Open source licensed under the MIT license (see _LICENSE_ file for details).

## Supported Python Versions

Locust supports Python 2.7, 3.3, 3.4, 3.5, and 3.6.
Locust supports Python 2.7, 3.4, 3.5, and 3.6.
16 changes: 13 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,36 @@ Locust class
============

.. autoclass:: locust.core.Locust
:members: min_wait, max_wait, task_set, weight
:members: min_wait, max_wait, wait_function, task_set, weight

HttpLocust class
================

.. autoclass:: locust.core.HttpLocust
:members: min_wait, max_wait, task_set, client
:members: min_wait, max_wait, wait_function, task_set, client


TaskSet class
=============

.. autoclass:: locust.core.TaskSet
:members: locust, parent, min_wait, max_wait, client, tasks, interrupt, schedule_task
:members: locust, parent, min_wait, max_wait, wait_function, client, tasks, interrupt, schedule_task

task decorator
==============

.. autofunction:: locust.core.task

TaskSequence class
==================

.. autoclass:: locust.core.TaskSequence
:members: locust, parent, min_wait, max_wait, wait_function, client, tasks, interrupt, schedule_task

seq_task decorator
==============

.. autofunction:: locust.core.seq_task

HttpSession class
=================
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

# Intersphinx config
intersphinx_mapping = {
'requests': ('http://requests.readthedocs.org/en/latest/', None),
'requests': ('https://requests.readthedocs.io/en/latest/', None),
}


Expand Down
26 changes: 15 additions & 11 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,41 +8,45 @@ Locust Documentation

Locust is a scalable load testing framework written in Python

* **Website**: `http://locust.io <http://locust.io>`_
* **Source code**: `http://github.com/locustio/locust <http://github.com/locustio/locust>`_
* **Twitter**: `@locustio <http://twitter.com/locustio>`_
* **Website**: `https://locust.io/ <https://locust.io/>`_
* **Source code**: `https://github.com/locustio/locust <https://github.com/locustio/locust>`_
* **Twitter**: `@locustio <https://twitter.com/locustio>`_



.. toctree ::
:maxdepth: 1
:maxdepth: 4
what-is-locust
installation
quickstart
.. toctree ::
:maxdepth: 2
:maxdepth: 4
writing-a-locustfile
.. toctree ::
:maxdepth: 1
:maxdepth: 4
running-locust-distributed
running-locust-without-web-ui
increase-performance
.. toctree ::
:maxdepth: 1
:maxdepth: 4
retrieving-stats
testing-other-systems
api
extending-locust
changelog
.. toctree ::
:maxdepth: 3
:maxdepth: 4
third-party-tools
.. toctree ::
:maxdepth: 4
changelog
22 changes: 14 additions & 8 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ Installation

Locust is available on PyPI and can be installed through pip or easy_install

::
.. code-block:: console
pip install locustio
When Locust is installed, a **locust** command should be available in your shell (if you're not using
virtualenv—which you should—make sure your python script directory is on your path).

To see available options, run::
To see available options, run:

locust --help
.. code-block:: console
$ locust --help
Supported Python Versions
-------------------------

Locust supports Python 2.7, 3.3, 3.4, 3.5, and 3.6.
Locust supports Python 2.7, 3.4, 3.5, and 3.6.


Installing Locust on Windows
Expand All @@ -33,9 +35,11 @@ the pre built binary packages for pyzmq, gevent and greenlet.
You can find an unofficial collection of pre built python packages for windows here:
`http://www.lfd.uci.edu/~gohlke/pythonlibs/ <http://www.lfd.uci.edu/~gohlke/pythonlibs/>`_

When you've downloaded a pre-built ``.whl`` file, you can install it with::
When you've downloaded a pre-built ``.whl`` file, you can install it with:

.. code-block:: console
pip install name-of-file.whl
$ pip install name-of-file.whl
Once you've done that you should be able to just ``pip install locustio``.

Expand All @@ -52,9 +56,11 @@ Installing Locust on OS X
The following is currently the shortest path to installing gevent on OS X using Homebrew.

#. Install `Homebrew <http://mxcl.github.com/homebrew/>`_.
#. Install libev (dependency for gevent)::
#. Install libev (dependency for gevent):

.. code-block:: console
brew install libev
brew install libev
#. Then follow the above instructions.

Expand Down
79 changes: 59 additions & 20 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,34 @@ Quick start
Example locustfile.py
=====================

Below is a quick little example of a simple **locustfile.py**::
Below is a quick little example of a simple **locustfile.py**:


.. code-block:: python
from locust import HttpLocust, TaskSet
def login(l):
l.client.post("/login", {"username":"ellen_key", "password":"education"})
def logout(l):
l.client.post("/logout", {"username":"ellen_key", "password":"education"})
def index(l):
l.client.get("/")
def profile(l):
l.client.get("/profile")
class UserBehavior(TaskSet):
tasks = {index: 2, profile: 1}
def on_start(self):
login(self)
def on_stop(self):
logout(self)
class WebsiteUser(HttpLocust):
task_set = UserBehavior
min_wait = 5000
Expand All @@ -43,18 +52,27 @@ The :py:class:`HttpLocust <locust.core.HttpLocust>` class inherits from the
:py:class:`HttpSession <locust.clients.HttpSession>` that can be used to make HTTP requests.

Another way we could declare tasks, which is usually more convenient, is to use the
``@task`` decorator. The following code is equivalent to the above::
``@task`` decorator. The following code is equivalent to the above:

.. code-block:: python
from locust import HttpLocust, TaskSet, task
class UserBehavior(TaskSet):
def on_start(self):
""" on_start is called when a Locust start before any task is scheduled """
self.login()
def on_stop(self):
""" on_stop is called when the TaskSet is stopping """
self.logout()
def login(self):
self.client.post("/login", {"username":"ellen_key", "password":"education"})
def logout(self):
self.client.post("/logout", {"username":"ellen_key", "password":"education"})
@task(2)
def index(self):
self.client.get("/")
Expand All @@ -69,37 +87,58 @@ Another way we could declare tasks, which is usually more convenient, is to use
max_wait = 9000
The :py:class:`Locust <locust.core.Locust>` class (as well as :py:class:`HttpLocust <locust.core.HttpLocust>`
since it's a subclass) also allows one to specify minimum and maximum wait time—per simulated
since it's a subclass) also allows one to specify minimum and maximum wait time in milliseconds—per simulated
user—between the execution of tasks (*min_wait* and *max_wait*) as well as other user behaviours.
By default the time is randomly chosen uniformly between *min_wait* and *max_wait*, but any user-defined
time distributions can be used by setting *wait_function* to any arbitrary function.
For example, for an exponentially distributed wait time with average of 1 second:

.. code-block:: python
import random
class WebsiteUser(HttpLocust):
task_set = UserBehaviour
wait_function = lambda self: random.expovariate(1)*1000
Start Locust
============

To run Locust with the above Locust file, if it was named *locustfile.py* and located in the current working
directory, we could run::
directory, we could run:

locust --host=http://example.com
.. code-block:: console
$ locust --host=http://example.com
If the Locust file is located under a subdirectory and/or named different than *locustfile.py*, specify
it using ``-f``::
it using ``-f``:

.. code-block:: console
locust -f locust_files/my_locust_file.py --host=http://example.com
$ locust -f locust_files/my_locust_file.py --host=http://example.com
To run Locust distributed across multiple processes we would start a master process by specifying
``--master``::
``--master``:

locust -f locust_files/my_locust_file.py --master --host=http://example.com
.. code-block:: console
and then we would start an arbitrary number of slave processes::
$ locust -f locust_files/my_locust_file.py --master --host=http://example.com
locust -f locust_files/my_locust_file.py --slave --host=http://example.com
and then we would start an arbitrary number of slave processes:

.. code-block:: console
$ locust -f locust_files/my_locust_file.py --slave --host=http://example.com
If we want to run Locust distributed on multiple machines we would also have to specify the master host when
starting the slaves (this is not needed when running Locust distributed on a single machine, since the master
host defaults to 127.0.0.1)::
host defaults to 127.0.0.1):

.. code-block:: console
locust -f locust_files/my_locust_file.py --slave --master-host=192.168.0.100 --host=http://example.com
$ locust -f locust_files/my_locust_file.py --slave --master-host=192.168.0.100 --host=http://example.com
.. note::
Expand Down
Loading

0 comments on commit f02363a

Please sign in to comment.