VM images and marketplace in Azure - Time & Space Complexity
When using VM images from the Azure Marketplace, it's important to understand how the time to deploy grows as you add more virtual machines.
We want to know how the number of VM deployments affects the total time and operations involved.
Analyze the time complexity of deploying multiple VMs using marketplace images.
// Deploy multiple VMs from marketplace images
for (int i = 0; i < vmCount; i++) {
var vm = azure.VirtualMachines.Define($"vm-{i}")
.WithRegion(region)
.WithExistingResourceGroup(rgName)
.WithPopularLinuxImage(KnownLinuxVirtualMachineImage.UbuntuServer18_04_Lts)
.WithRootUsername("adminUser")
.WithSsh(sshKey)
.WithSize(VirtualMachineSizeTypes.StandardDS1V2)
.Create();
}
This code deploys a number of virtual machines, each using a popular marketplace image, one after another.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Creating a VM from a marketplace image involves multiple API calls to allocate resources and copy the image.
- How many times: This happens once per VM, so it repeats vmCount times.
Each VM deployment requires a similar set of operations, so as you add more VMs, the total operations grow proportionally.
| Input Size (vmCount) | Approx. Api Calls/Operations |
|---|---|
| 10 | About 10 sets of VM creation calls |
| 100 | About 100 sets of VM creation calls |
| 1000 | About 1000 sets of VM creation calls |
Pattern observation: The total work grows directly with the number of VMs you create.
Time Complexity: O(n)
This means the time and operations increase in a straight line as you add more virtual machines.
[X] Wrong: "Deploying multiple VMs from marketplace images happens all at once, so time stays the same no matter how many VMs."
[OK] Correct: Each VM deployment is a separate process that takes time and resources, so total time grows with the number of VMs.
Understanding how deployment time grows helps you plan cloud resources and manage expectations when scaling infrastructure.
"What if we deployed multiple VMs in parallel instead of one after another? How would the time complexity change?"