Skip to content

Commit 6a1283b

Browse files
authored
Merge pull request #297038 from Nagarjuna-Vipparthi/locust-docs-update
Locust docs update
2 parents ebd6fa0 + 9d7dd34 commit 6a1283b

File tree

10 files changed

+208
-2
lines changed

10 files changed

+208
-2
lines changed

articles/load-testing/concept-load-testing-concepts.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ A test engine is computing infrastructure, managed by Microsoft that runs the te
124124

125125
The test engines are hosted in the same location as your Azure Load Testing resource. You can configure the Azure region when you create the Azure load testing resource.
126126

127+
Azure Load Testing uses Standard_D4d_v4 size virtual machines with four vCPUs, 16GB memory and Azure Linux operating system as the test engines. For JMeter based tests, the test engines use JDK 21 and Apache JMeter version 5.6.3. For Locust based tests, the test engines use Python 3.9.19 and Locust version 2.33.2.
128+
127129
While the test script runs, Azure Load Testing collects and aggregates the testing framework logs from all test engine instances. You can [download the logs for analyzing errors during the load test](./how-to-diagnose-failing-load-test.md).
128130

129131
### App component

articles/load-testing/index.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ landingContent:
3434
url: quickstart-create-and-run-load-test.md
3535
- text: Create a load test with a JMeter script
3636
url: how-to-create-and-run-load-test-with-JMeter-script.md
37+
- text: Create a load test with a Locust script
38+
url: quickstart-create-run-load-test-with-locust.md
39+
- text: Create and run a load test with Visual Studio Code and GitHub Copilot
40+
url: quickstart-create-run-load-tests-from-visual-studio-code.md
3741
- text: Automate load tests with Azure Pipelines
3842
url: quickstart-add-load-test-cicd.md
3943
- linkListType: tutorial
98.6 KB
Loading
Loading
126 KB
Loading
1.65 MB
Loading
526 KB
Loading

articles/load-testing/quickstart-create-run-load-test-with-locust.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,15 @@ To create a load test for a Locust-based test in the Azure portal:
8787
| **Host endpoint** | (Optional) The HTTP endpoint URL. For example, https://www.contoso.com/products.|
8888
| **Test engine instances** | Select the number of parallel test engine instances. |
8989

90-
The optional inputs can be provided in the load configuration, in the Locust test script, or in the Locust configuration file. For more information, see [Configure for high scale loads](./how-to-high-scale-load.md)
90+
The optional inputs can be provided in the load configuration, in the Locust test script, or in the Locust configuration file. For more information, see [Configure for high scale loads](./how-to-high-scale-load.md)
9191

9292
1. Select **Review + create**. Review all settings, and then select **Create** to create the load test.
9393

9494
You can update the test configuration at any time, for example to upload a different Locust test file, or to modify the load parameters. Choose your test in the list of tests, and then select **Edit**.
9595

96+
> [!NOTE]
97+
> Azure Load Testing runs your Locust script in *LocalRunner* mode on all the engine instances.
98+
9699
## Run the load test
97100

98101

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
---
2+
title: 'Quickstart: Create and run load tests from Visual Studio Code'
3+
titleSuffix: Azure Load Testing
4+
description: 'This quickstart shows how to create and run load tests using the Visual Studio Code extension for Azure Load Testing. Azure Load Testing is a managed, cloud-based load testing tool.'
5+
services: load-testing
6+
ms.service: azure-load-testing
7+
ms.topic: quickstart
8+
author: nagarjuna-vipparthi
9+
ms.author: vevippar
10+
ms.date: 04/04/2024
11+
---
12+
13+
# Quickstart: Create and run a load test with Visual Studio Code and GitHub Copilot
14+
15+
Learn how to use the Azure Load Testing extension for Visual Studio Code to easily create Locust load tests using Copilot, iterate locally, and scale effortlessly in Azure. Whether you're new to Locust or a performance testing expert, the Azure Load Testing extension streamlines test creation, iteration, and scaling, right from your VS Code environment. Azure Load Testing is a managed service that lets you run a load test at cloud scale. [Locust](https://locust.io/) is an open source load testing tool that enables you to write all your tests in Python code.
16+
17+
This quickstart guides you through generating, refining, and running realistic load tests. By the end, you have a fully functional load test script generated from a **Postman collection**, **Insomnia collection**, or **.http file**, enhanced with Copilot-powered improvements, and ready to scale in **Azure Load Testing**.
18+
19+
## Prerequisites
20+
21+
- Azure Load Testing extension for VS Code. [Download and install it here](https://aka.ms/malt-vscode/get).
22+
- GitHub Copilot. [Set up Copilot in VS Code](https://code.visualstudio.com/docs/copilot/setup) to generate and refine test scripts. If you don't have a subscription, you can activate a free trial.
23+
- Python & Locust. Required to run and validate your **Locust** test scripts locally from VS Code. [Install Locust here](https://docs.locust.io/en/stable/installation.html).
24+
- An Azure account with an active subscription. Needed to run load tests at scale in **Azure Load Testing**. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
25+
26+
> [!TIP]
27+
> VS Code's GitHub Copilot Chat offers multiple AI models. You can switch models using the model picker in the chat input field. If you're unsure which one to use, we recommend GPT-4o.
28+
29+
## Open the walkthrough
30+
31+
To get started, open the command palette in VS Code and run: **Load Testing: Open Walkthrough**. This walkthrough provides the key entry points of the extension.
32+
33+
You can also access the features directly from the command palette by using the **Load Testing** prefix. Some commonly used commands include:
34+
- Load Testing: Create Locust test
35+
- Load Testing: Run load test (local)
36+
- Load Testing: Run load test (Azure Load Testing)
37+
38+
:::image type="content" source="./media/quickstart-create-run-load-tests-from-visual-studio-code/walkthrough.png" alt-text="Screenshot that shows the key entry points for the Azure Load Testing VS Code extension." lightbox="./media/quickstart-create-run-load-tests-from-visual-studio-code/walkthrough.png":::
39+
40+
## Generate a Locust script with Copilot
41+
42+
You can generate a Locust script from any existing Postman collection, Insomnia collection, or .http file. If the file contains multiple requests, Copilot attempts to sequence them into a cohesive scenario.
43+
44+
1. Click the **Create a Load Test** button in the walkthrough, or run **Load Testing: Create Locust test** from the command palette.
45+
46+
1. You can choose the source to auto-generate a Locust test script:
47+
- Selecting a **Postman collection**, **Insomnia collection**, or **.http file** lets Copilot extract multiple API operations, request data, and authentication details—creating a more complete and realistic load test.
48+
- Choosing **Single URL** allows you to enter a single endpoint URL, generating a simple script you can customize or expand.
49+
50+
1. **For this walkthrough**, you can select **Try Sample: Pet Shop API**, which uses the [**`petstore-sample.http`**](https://aka.ms/malt-vscode/http-sample) file to generate a sample Locust test script.
51+
52+
1. Copilot analyzes the selected file and generate a **Locust-based load test script**, automatically sequencing API requests to simulate real-world usage and handling authentication securely.
53+
54+
1. Once the script is generated, the **Copilot Chat** window will suggest other setup steps, such as defining **environment variables**. If Copilot suggests environment variables, create a `.env` file in your project and add the recommended values.
55+
56+
## Customize the load test script
57+
58+
Before running the test, you can refine it with Copilot. For example, by examining the script, you might notice that the same request payload is sent with every request:
59+
60+
```python
61+
payload = {
62+
"id": self.pet_id,
63+
"name": "Fluffy",
64+
"category": {"id": 1, "name": "Dogs"},
65+
"photoUrls": ["https://example.com/photo.jpg"],
66+
"tags": [{"id": 1, "name": "cute"}],
67+
"status": "available"
68+
}
69+
```
70+
71+
To make the test more dynamic by randomizing the request payload:
72+
73+
1. Open the **Copilot Chat** panel.
74+
2. Type: `Randomize request payloads` and press Enter.
75+
3. Copilot generates a suggested modification to introduce randomization.
76+
4. Click **Apply in Editor** that appears above the generated code snippet in Copilot Chat window.
77+
5. After reviewing the changes, click **Keep** to accept and update your script.
78+
6. Save the file
79+
80+
Now, each request simulates a more realistic user interaction. The code looks something like the following snippet:
81+
82+
```python
83+
payload = {
84+
"id": self.pet_id,
85+
"name": f"Pet{random.randint(1, 1000)}",
86+
"category": {"id": random.randint(1, 10), "name": random.choice(["Dogs", "Cats", "Birds"])},
87+
"photoUrls": [f"https://example.com/photo{random.randint(1, 100)}.jpg"],
88+
"tags": [{"id": random.randint(1, 10), "name": random.choice(["cute", "friendly", "playful"])}],
89+
"status": random.choice(["available", "pending", "sold"])
90+
}
91+
```
92+
93+
## Run the load test
94+
95+
You can run your load test in two ways:
96+
- Run locally for quick validation
97+
- Run in Azure Load Testing for high-scale, multi-region load
98+
99+
### Run locally for quick validation
100+
To quickly validate your test, run it locally using Locust from **Visual Studio Code**:
101+
102+
1. Open the command palette and run: **Load Testing: Run load test (local)**.
103+
104+
1. The **Locust web UI** gets automatically launched in a browser. It can take a few seconds for the Locust server to be ready and for the browser to open.
105+
106+
1. In the **Start new load test** page, review the input fields and click **Start**. Locust starts sending requests, logging any failures, and tracking performance statistics.
107+
108+
:::image type="content" source="./media/quickstart-create-run-load-tests-from-visual-studio-code/locust-start-new-load-test.png" alt-text="Screenshot that shows the Locust web UI to run a load test locally." lightbox="./media/quickstart-create-run-load-tests-from-visual-studio-code/locust-start-new-load-test.png":::
109+
110+
111+
1. Explore the **Locust UI** to analyze response times, error rates, and request throughput.
112+
113+
:::image type="content" source="./media/quickstart-create-run-load-tests-from-visual-studio-code/locust-web-ui.png" alt-text="Screenshot that shows the Locust web UI to view and analyze test results locally." lightbox="./media/quickstart-create-run-load-tests-from-visual-studio-code/locust-web-ui.png":::
114+
115+
> [!TIP]
116+
> If Locust reports failures for the `Retrieve Pet` and `Update Pet` requests, it may be due to how the Pet Store API processes requests. Try asking Copilot to "**Add random delays between requests in run_scenario**". If you suspect an issue with the script itself, set `DEBUG_MODE=True` as an environment variable and rerun the test to get more detailed debug information.
117+
118+
If you prefer running the test from a **VS Code Terminal**:
119+
120+
1. Open a terminal in VS Code.
121+
122+
1. Run the following command:
123+
```sh
124+
locust -f path/to/locustfile.py -u 10 -r 2 --run-time 1m
125+
```
126+
* `-f path/to/locustfile.py`: Specifies the Locust test script.
127+
* `-u 10`: Simulates up to 10 virtual users.
128+
* `-r 2`: Ramps up two virtual users per second.
129+
* `--run-time 1m`: Runs the test for 1 minute.
130+
1. Open a browser to `http://0.0.0.0:8089` to view the Locust web UI.
131+
132+
### Scale up in Azure Load Testing
133+
134+
For high-load scenarios where you need to simulate many thousands of concurrent virtual users across multiple regions, you can run your test in **Azure Load Testing**.
135+
136+
To execute a large-scale test:
137+
138+
1. Open the **command palette** and run: **Load Testing: Run load test (Azure Load Testing)**.
139+
140+
1. Select **Create a configuration file...**.
141+
142+
1. Follow the guided setup, which includes:
143+
- Signing into Azure and selecting your subscription.
144+
145+
- Creating a new Azure Load Testing resource or selecting an existing one.
146+
147+
- Choosing load test regions to distribute traffic globally.
148+
149+
1. Once the setup is complete, a YAML configuration file (for example, `loadtest.config.yaml`) is generated and added to your workspace root folder.
150+
- This file defines the Locust script, load parameters, environment variables, regions, and any other files (for example, CSV datasets).
151+
152+
- Defaults are 200 virtual users running for 120 seconds in each selected region.
153+
154+
- Commit this file in your repository to reuse and automate future load test executions.
155+
156+
1. Copilot validates the configuration before execution. Follow any instructions provided in the chat window. Otherwise, if everything checks out, the test script and its related artifacts are uploaded to Azure Load Testing and prepared for execution. This process may take up to a minute, and progress is shown in the **Output** panel.
157+
158+
159+
:::image type="content" source="./media/quickstart-create-run-load-tests-from-visual-studio-code/load-test-progress.png" alt-text="Screenshot that shows the load test progress in VS Code output console." lightbox="./media/quickstart-create-run-load-tests-from-visual-studio-code/load-test-progress.png":::
160+
1. When the test starts, a notification (toast message) appears in the bottom-right corner of VS Code. Click the **Open in Azure Portal** button to monitor test execution in real time.
161+
162+
1. When the test starts, a notification (toast message) appears in the bottom-right corner. Click the **Open in Azure Portal** button to monitor test execution in real time.
163+
164+
:::image type="content" source="./media/quickstart-create-run-load-tests-from-visual-studio-code/run-load-test-azure.png" alt-text="Screenshot that shows the load test results in Azure Load Testing." lightbox="./media/quickstart-create-run-load-tests-from-visual-studio-code/run-load-test-azure.png":::
165+
166+
> [!TIP]
167+
> To quickly access test results from previous runs, use the command: **Load Testing: View load test runs**.
168+
169+
In this quickstart, sensitive variables like `API_KEY` were stored in a `.env` file and uploaded to the cloud service. However, as a best practice, secrets should be securely managed in **Azure Key Vault**. The extension provides guidance on setting this up.
170+
171+
So far in this quickstart, sensitive variables like `API_KEY` were stored in a `.env` file and uploaded to the cloud service. However, as a best practice, secrets should be securely managed in **Azure Key Vault**. The extension provides guidance on setting this up.
172+
173+
1. Open the **Copilot Chat** window, type `@testing /setupLoadTestSecretsInAzure` and press Enter.
174+
175+
1. Copilot guides you through the following steps:
176+
177+
178+
1. Copilot guides you through:
179+
- Creating an Azure Key Vault.
180+
- Assigning a managed identity to your Azure Load Testing resource.
181+
- Adding secrets to Azure Key Vault.
182+
- Configuring your YAML file to reference Key Vault secrets instead of `.env`.
183+
184+
Whenever you modify your Locust script or YAML configuration, you can re-run the test by executing **Run load test (Azure Load Testing)**.
185+
186+
## Summary
187+
188+
In this quickstart, you used the Azure Load Testing extension for Visual Studio Code to easily create Locust load tests using Copilot, iterate locally, and scale effortlessly in Azure. Azure Load Testing extension for VS Code simplifies the process of creating a realistic test script for your test scenario. Azure Load Testing abstracts the complexity of setting up the infrastructure for simulating high-scale user load for your application.
189+
190+
You can further expand the load test to also monitor server-side metrics of the application under load, and to specify test fail metrics to get alerted when the application doesn't meet your requirements. To ensure that the application continues to perform well, you can also integrate load testing as part of your continuous integration and continuous deployment (CI/CD) workflow.
191+
192+
## Related content
193+
194+
- Learn how to [monitor server-side metrics for your application](./how-to-monitor-server-side-metrics.md).
195+
- Learn how to configure [automated performance testing with CI/CD](./how-to-configure-load-test-cicd.md).

articles/load-testing/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ items:
1515
- name: Create a load test with a JMeter script
1616
href: how-to-create-and-run-load-test-with-JMeter-script.md
1717
- name: Create a load test with a Locust script
18-
href: quickstart-create-run-load-test-with-locust.md
18+
href: quickstart-create-run-load-test-with-locust.md
19+
- name: Create and run a load test from Visual Studio Code
20+
href: quickstart-create-run-load-tests-from-visual-studio-code.md
1921
- name: Automate load tests with Azure Pipelines
2022
displayName: Azure Pipelines, CI/CD, continuous integration, Azure DevOps, GitHub Actions, automation, automated testing, regression testing
2123
href: quickstart-add-load-test-cicd.md

0 commit comments

Comments
 (0)