Skip to main content

Auto-import and compilation of locust TaskSets.

Project description

locust-nest

license PyPI PyPI GitHub contributors

Locust wrapper. Import Locust classes from a folder and run Locust using those classes with weights determined in a config file, with an option to guide the generation of the config file.

Locust.io

What is locust-nest for?

locust-nest is a wrapper around Locust to simplify load testing.

Use locust-nest for load generation.

Unit tests or live user testing will tell you if your system works for 1 user, locust-nest will show you if it can scale to 100, 1000 or 100,000 simultaneous users.

It allows you to configure the weighting of each of your Locust classes so that you can run different load scenarios without changing any Python code.

Installation

pip install locust-nest

The following will create an example file and script in the [example/] dir:

locust-nest install [example/]

Note: At the moment locust-nest uses pslocust to provide more current Locust features than the current Locust release.

Quick start

locust-nest is designed to provide a framework for simulating a specified load on a system.

Behaviour models are codified using Locust, an open-source load testing tool that allows abitrarily complex user behaviour modelling since all tasks are written in Python.

This wrapper searches all .py files in the --model_dir (-d) directory and subdirectories for subclasses of Locust and runs Locust with all of those classes.

To run locust-nest, simply use locust-nest command with default Locust arguments:

locust-nest --model_dir=models/ --host=https://www.example.com ...

To be guided through the generation of a config file, use the --configure flag:

locust-nest --configure --host=https://www.example.com ...

An example structure for one of these TaskSets is:

from locust import TaskSet, task

class ModelBehaviour(TaskSet):
  weight = 0
  def on_start(self):
    # Log in & save token

    # retrieve bulk information needed for other tasks

    # other to-dos on starting this group of tasks
    pass

  def on_stop(self):
    # unclaim resources e.g. username
    pass

  @task(5) # task decorator with relative weight of executing the task
  def model_action(self):
    # codified behaviour of a particular action this model may perform
    # e.g. registering a customer
    return

If the --include-tasksets (-T) flag is used, it will also find all subclasses of TaskSet and add these to a NestTaskset, which packages all the tasks with their desired weights into a HTTPLocust class. of those classes, with weights specified in a --config_file. Note: Python 2 does not have support for recursive subdirectories, so at the moment only searches 1 directory deep {model_dir}/*/

Workflow

  1. locust-nest will import all TaskSets from models/ into one NestLocust, weighting according to --config_file.

  2. locust-nest will find all Locust’s, weighting according to --config_file.

  3. Display weightings that will be used with confirmation prompt (skippable with some commandline argument).

  4. Run Locust with weightings set from config for the Locusts and NestLocust classes

  5. locust-nest will have an option to automatically manage distributed resources for Locust master-slave mode. (NOT IMPLEMENTED)

Example TaskSet

from locust import TaskSet, task

class ExampleModel(TaskSet):
    weight = 0

    def on_start(self):
        """Set up before running tasks.

        For example:
        * Log in & save token
        * Retrieve bulk information needed for other tasks

        """
        return

    def on_stop(self):
        """Teardown: unclaim resources e.g. claimed user.

        """

        return

    # task decorator with relative weight of executing the task
    @task(5)
    def model_action(self):
        """Codified behaviour of a particular action this model may perform
        e.g. registering a customer

        """
        self.client.get("/")
        return

Aims of locust-nest

  1. Users will be able to place any number of directories containing TaskSets and Locusts with each representing an encapsulated group of tasks.

  2. locust-nest will find all TaskSets contained in a specified directory and group them into one Locust class with corresponding weights specified in a config file, allowing easy modularity in adding or removing TaskSets without needing to change any code in the locust-nest repository. Locusts will also be found and configured with specific weights.

  3. There will be an interactive configure option which creates a config file that specifies the relative weights of each TaskSet, allowing users to easily adjust the different ratios of TaskSet types, but still allowing non-interactive use of the system when the config file has been created.

  4. locust-nest will be automatable, ideally callable with a git hook for load-testing continuous integration or in response to a Slack command. The results will be human readable, ideally some kind of index of scalability of the system, so that the evolution of the system under test’s scalability can be tracked.

  5. locust-nest will be able to automatically deploy to AWS Lambda or equivalent and run load testing under the distributed master-slave variant in order to be able to easily scale arbitrarily.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

locust-nest-0.39.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

locust_nest-0.39-py2.py3-none-any.whl (13.7 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file locust-nest-0.39.tar.gz.

File metadata

  • Download URL: locust-nest-0.39.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for locust-nest-0.39.tar.gz
Algorithm Hash digest
SHA256 f8694da3f78c005cbb2f8cfc874915cced9db912db49ccb9f52098310c15b743
MD5 50a66321ad393db8a839a06194de41f6
BLAKE2b-256 2ad5487482267602119185b9b258755917b18ae8bd0ff54287fc30492be074f9

See more details on using hashes here.

File details

Details for the file locust_nest-0.39-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for locust_nest-0.39-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3200ffab9bc16f8428a7ced8c41659f737c7b7a7f798d9e33ceefaf06d343dc4
MD5 1427d0e8af865ef2f06ffa50613e76da
BLAKE2b-256 9d927bfa8a3974255e1024761d92e94d874a5943bc61a338d5d27508b57eb8dc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page