Skip to content

Commit

Permalink
Merge pull request #797 from joar/doc-code-blocks
Browse files Browse the repository at this point in the history
docs: Syntax highlight code and commands
  • Loading branch information
mbeacom authored May 20, 2018
2 parents 5277177 + 4bc0f17 commit bf5066a
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 61 deletions.
20 changes: 13 additions & 7 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@ 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
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
61 changes: 39 additions & 22 deletions docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +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 @@ -49,15 +52,17 @@ 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()
Expand Down Expand Up @@ -88,6 +93,8 @@ By default the time is randomly chosen uniformly between *min_wait* and *max_wai
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):
Expand All @@ -99,29 +106,39 @@ 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
22 changes: 14 additions & 8 deletions docs/retrieving-stats.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,37 @@ You may wish to consume your Locust results via a CSV file. In this case, there
First, when running Locust with the web UI, you can retrieve CSV files under the Download Data tab.

Secondly, you can run Locust with a flag which will periodically save two CSV files. This is particularly useful
if you plan on running Locust in an automated way with the ``--no-web`` flag::

locust -f examples/basic.py --csv=example --no-web -t10m
if you plan on running Locust in an automated way with the ``--no-web`` flag:

.. code-block:: console
$ locust -f examples/basic.py --csv=example --no-web -t10m
The files will be named ``example_distribution.csv`` and ``example_requests.csv`` (when using ``--csv=example``) and mirror Locust's built in stat pages.

You can also customize how frequently this is written if you desire faster (or slower) writing::
You can also customize how frequently this is written if you desire faster (or slower) writing:

.. code-block:: python
import locust.stats
locust.stats.CSV_STATS_INTERVAL_SEC = 5 # default is 2 seconds
This data will write two files with ``_distribution.csv`` and ``_requests.csv`` added to the name you give::
This data will write two files with ``_distribution.csv`` and ``_requests.csv`` added to the name you give:

$cat example_distribution.csv
.. code-block:: console
$ cat example_distribution.csv
"Name","# requests","50%","66%","75%","80%","90%","95%","98%","99%","100%"
"GET /",31,4,4,4,4,4,4,4,4,4
"/does_not_exist",0,"N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A","N/A"
"GET /stats/requests",38,3,4,4,4,4,5,5,5,5
"None Total",69,3,4,4,4,4,4,5,5,5
and::
and:

.. code-block:: console
$cat example_requests.csv
$ cat example_requests.csv
"Method","Name","# requests","# failures","Median response time","Average response time","Min response time","Max response time","Average Content Size","Requests/s"
"GET","/",51,0,4,3,2,6,12274,0.89
"GET","/does_not_exist",0,56,0,0,0,0,0,0.00
Expand Down
14 changes: 9 additions & 5 deletions docs/running-locust-without-web-ui.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ Running Locust without the web UI
=================================

You can run locust without the web UI - for example if you want to run it in some automated flow,
like a CI server - by using the ``--no-web`` flag together with ``-c`` and ``-r``::
like a CI server - by using the ``--no-web`` flag together with ``-c`` and ``-r``:

.. code-block:: console
$ locust -f locust_files/my_locust_file.py --no-web -c 1000 -r 100
locust -f locust_files/my_locust_file.py --no-web -c 1000 -r 100
``-c`` specifies the number of Locust users to spawn, and ``-r`` specifies the hatch rate
(number of users to spawn per second).

Expand All @@ -20,9 +22,11 @@ Setting a time limit for the test

This is a new feature in v0.9. For 0.8 use ``-n`` to specify the number of requests

If you want to specify the run time for a test, you can do that with ``--run-time`` or ``-t``::
If you want to specify the run time for a test, you can do that with ``--run-time`` or ``-t``:

.. code-block:: console
locust -f --no-web -c 1000 -r 100 --run-time 1h30m
$ locust -f --no-web -c 1000 -r 100 --run-time 1h30m
Locust will shutdown once the time is up.

Expand Down
Loading

0 comments on commit bf5066a

Please sign in to comment.