Run distributed Locust load tests on Azure Container Instances. It's quick, cheap and scalable!
During testing, it ran 96 workers over about 2hr 10min and cost ~$15CAD in Azure Credit
Credit to https://github.com/Lingaro/azure-locust for the base of this code.
You can deploy and manage resources using either:
- Azure Portal - easier
- Azure Cli - faster
Make sure you are logged in to Azure Portal.
Click the Deploy to Azure button (ctrl click to open it in new tab):
NOTE: If you are cloning this code, the Deploy to Azure button is coded to point to the file in the source repo, so you will need to change it.
Then fill form with given values.
- Subscription: choose your subscription
- Resource Group: select existing Resource Group or create new one
- Location: Canada Central (any allowed, but keep in mind its part of Locust DNS address!)
- Instances: number of workers
- Instances RegionX (optional): number of workers in that region
- Location RegionX (optional): region for those workers. NOTE: Must be the short names like
canadacentral
,westus1
etc.
This template allows up to 5 regions, with 16 workers for region 1 (based on vCPU limit of 20) and 20 in the remaining regions due to no need for provisioner or master in those regions.
Click Review + Create and on the following Screen click Create then wait for deployment ends. The following screen should show you when the deployment is complete:
Click Go to resource group to verify your deployment:
Go to xxxxxxxxxxxxx-master
and find out Locust FQDN - copy it.
When deployment succeeded, your load generator is ready. Go to the above FQDN and port 8089:
http://xxxxxxxxxxxxx-master.canadacentral.azurecontainer.io:8089
At this point you can start tests.
Go to your Resource Group and click Storage Account named xxxxxxxxxxxxx
.
Click File shares under Data Storage (left panel).
Go to share called scripts
then click Browse (Left bar) and then edit locustfile.py
(click ...
and edit).
Edit contents of your new file and click Save.
Then restart all containers called like master and worker. NOTE: This might be easier to do in the CLI if you have a large number of workers
Click on each container to restart it:
Tip: This step is really faster using Azure CLI.
Go to your Resource Group and remove it (it will destroy all resources inside group). You will need to type Resource Group name to confirm.
In Powershell, Login and set subscription context
az login
az account set --subscription <SubscriptionId>
Step 1: Setup your names
In Powershell: $RG= "<ResourceGroup>"
Step 2: Create Resource Group (if not exists)
az group create --name ${RG} --location canadacentral
Step 3: Deploy ARM template
az group deployment create --resource-group ${RG} --query properties.outputs --template-file mainTemplate.json
- To change number of instances append
--parameters instances=<n>
, for other regions you need to add--parameters instancesRegionX=<n>
(for regions 2-5 if you want something other than default values)
Step 4: Note values of prefix
and url
from console output.
{
"outputs": {
"prefix": {
"type": "String",
"value": "xxxxxxxxxxxxx"
},
"url": {
"type": "String",
"value": "http://xxxxxxxxxxxxx-master.canadacentral.azurecontainer.io:8089"
}
}
}
When deployment succeeded, your load generator is ready. Go to above url
address.
At this point you can start tests.
Upload your custom script. Replace account name with above prefix
. You can change --source
param if you want use different .py file:
az storage file upload --account-name <prefix> -s scripts --source locustfile.py --path locustfile.py
Then restart containers:
az container list --resource-group $RG --query '[].name' -o tsv | ForEach-Object { az container restart --no-wait --resource-group $RG --name $_ }
NOTE: This may take a few minutes, roughly 5 min for 96 workers. You can ignore the message about provisioner being stopped.
Remove resources from Azure:
az group delete --name $RG --yes
- Load test affects target service performance. Never run load tests without service owner permission!
- Some services can block traffic from generator - you should whitelist Azure Region IPs (Download prefixes).
- After load tests cleanup Azure resources. You will be billed for running Azure Contianers Instance and Storage Account usage. You can check cost of ACI here.