Skip to content

Latest commit

 

History

History
75 lines (48 loc) · 3.56 KB

README.md

File metadata and controls

75 lines (48 loc) · 3.56 KB

Locust

Locust is a Python library for performance testing and load testing of web applications. It allows users to define user behaviour, simulate virtual users (locusts), and generate load on a target system to assess its performance under various conditions.

How to run Locust

First, install the Locust library by running the following command:

pip install locust

Once the library is installed, create a Python script and import the necessary elements from Locust:

  • HttpUser: virtual user for load testing web applications;
  • task: decorator to define tasks that a virtual user performs during a test;
  • tag: decorator to categorize tasks with metadata for better result analysis;
  • between: function to set a random wait time between tasks, simulating user think time.

You can easily import those elements with the following command:

from locust import HttpUser, task, between, tag

The following snippet of code is taken directly from our locusfile.py and serves as an example of the usage of those elements:

DEFAULT_PLAYLIST_PAYLOAD = {"id_playlist_train": "", "id_playlist_test": ""}

@tag('default_scenario', 'default_user')
@task(2)
def extract_data_default(self):
    """Extract default data behaviour"""
    self.client.post("/extract", json=DEFAULT_PLAYLIST_PAYLOAD)
    time.sleep(5)

When Locust is run, the task in the code snippet sends requests to the /extract endpoint using default data.

You can easily run Locust by running the following command in the directory in which your locustfile.py is located:

locust

After executing this command, a UI will be accessible at the following URL: http://localhost:8089.

Within this UI, you need to specify the number of users, the time required to spawn users, and the host to be monitored.

plot

Here's an example of a Locust run, along with charts displaying the corresponding results.

plot plot

Conducted Tests

We conducted tests to assess the scalability of our website and encountered a limitation related to the maximum number of requests allowed by Spotify's API.

Caution

As outlined in the Spotify for Developer - Rate Limits webpage: Spotify's API rate limit is calculated based on the number of calls that your app makes to Spotify in a rolling 30 second window. If your app exceeds the rate limit for your app then you'll begin to see 429 error responses from Spotify's Web API, and you may hear from users about unexpected behavior that they have noticed while using your app. The limit varies depending on whether your app is in development mode or extended quota mode.

Unfortunately, we are unable to request the extended quota mode for university projects, and we were only able to perform 2 out of the 3 tests we designed:

plot

During the last test (the one in the table that has the orange background), we consistently got blocked from Spotify after some time elapsed, preventing us from obtaining additional results.

We stored the Locust reports for the initial two tests in the reports/locust/ folder, and the links to access them are provided below: