Fixing Invoke-WebRequest

Author by Nathan Stachowiak

Recently, we noticed that build times for Terraform deployments in Azure DevOps were taking an unusually long time, sometimes as much as three to five minutes per build. Upon further investigation, one of the steps that held up the build process the longest was the step to download Terraform. The download step, which downloads terraform using the Invoke-WebRequest command, took almost a full minute to download a zip file 20 MB in size. What was going on? Why was downloading using Invoke-WebRequest so slow?

After reading up on Microsoft’s forums and doing some small-scale tests of my own, it appears that leaving the progress bar turned on significantly impacts the speed at which Invoke-WebRequest downloads. Turning off the progress bar with the command $ProgressPreference = 'SilentlyContinue' before running Invoke-WebRequest reduced the time it took to download Terraform from 60 seconds to around 12 seconds. Applied to deployment builds, we found that suppressing the progress bar reduced build time, on average, by 22%.

For more information on Cloud Datacenter and DevOps at Concurrency, follow us at https://www.concurrency.com/blog/categories/categories/cloud-datacenter-devops.

2019-04-01-09_22_02-Concurrency_Blog-docx-Word-(1).png