Our product is in the acceptance testing phase. In the assigned environment the available tooling is very limited. But we must do a loadtest to report on the average requests / second our webservice can handle from a single client. Lucky for us we have access to powershell, but it is version 2.0.
The Invoke-RestMethod cmdlet is available from version 3.0 and up. I’ll have to write my own to use it in version 2.0. Below is my “implementation”.
function Invoke-RestMethod { [cmdletbinding()] param ([string] $url) Write-Verbose $url $client = New-Object System.Net.WebClient $client.DownloadString($url) }
We created a loadtest method that reads a csv-file and calls the Invoke-RestMethod with every record. A simplified version of this loadtest method is listed below.
function LoadTest { [cmdletbinding()] param() [System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") # this reads 10000 unique id-s $testdata = Import-CSV 'C:\loadtest\data.csv' $template = "http://srv01/api/information/1/{0}/{1}" foreach($record in $testdata) { # call webservice $request = [System.String]::Format($template, $record.Id, $record.Name) $response = Invoke-RestMethod $request } }
Now to measure the time needed to process the 10000 records we use the Measure-Command. The output tells us the time needed to process 10000 records, so divide 10000 by the seconds needed and we have the requests per second.
Measure-Command { LoadTest }
My preferred tool for loadtesting is Visual Studio, but when not available Powershell is the next best thing.
References
Powershell version 2.0 cmdlets, list of cmdlets available in Windows Powershell version 2.0.