Loadtesting with Powershell

powershellOur 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 {
    param ([string] $url)    
    Write-Verbose $url
    $client = New-Object System.Net.WebClient

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 {
    # 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.


Powershell version 2.0 cmdlets, list of cmdlets available in Windows Powershell version 2.0.

About erictummers

Working in a DevOps team is the best thing that happened to me. I like challenges and sharing the solutions with others. On my blog I’ll mostly post about my work, but expect an occasional home project, productivity tip and tooling review.
This entry was posted in Test and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.