Cloud Load Testing With Visual Studio And Azure

Its been a long while since the last post and that is because…well…I have been busy working and living.   Most times I have every intention of writing up some new post but this funny little thing called life sort of gets in the way.  Not to mention that sometimes (well ok…often times) I am lazy, but hey, at least I am still thinking about posting. There should be some developer corollary to the famous quote of “Life is what happens when your are busy making plans”.  Something like “Documentation/Blog Posts is not what happens when you are busy with life/work/ and coding all day long”

Usually my post ideas revolve around some technology or technique I have encountered during my everyday project work and I wind up thinking to myself  some form of:

“Wow this is a nice technology that is saving me a lot or work.  I should share this with others”

“Slick tool!  Wish I had known about this sooner.”

“Cool!  Other people should know about this if they don’t already because its a time saver”

This post is one of those situations. Specifically I want to talk about Load Testing and how Visual Studio and Azure can really help.

Over the course of my career there have been too many situations where some new application was ready to be released but prior to doing so it needed to be load tested.  The app works great in acceptance environments but who the heck knows what is going to happen when it gets into the wild (a.k.a production).  Believe me something will happen….  Its amazing the kind of things that pop up when web sites take a large amount of traffic.    I have worked on many high volume websites and that high volume introduces a whole new twist on things to think/worry about.  Wouldn’t it be great to know before hand?  Yes there are tons of tools out there and I have used them in the past.  Some free ones like  JMeter and some really AWESOME but expensive ones like Dynatrace .  They really help with providing visibility into the application under load.

Another set of tools I have worked with that REALLY made it easy to spin up some load tests was combining Visual Studio and Azure Cloud Load Testing.  Price tag was right too and it was dead simple.  In the next few sections I am going to walk through setting up a simple Visual Studio project to demonstrate just how easy it is to spin up load tests using VS and Azure.

Tools You Will Need

  1. Visual Studio 2017 Enterprise
  2. Visual Studio Team Services Account

Getting Started

Creating the Load Test Project

  1. Open Up Visual Studio and create a new Web Performance Load Test Project

Project

Record a Simple Test

Next, we are going to record some actions against our site so we can repeat these under load/testing scenarios.  To do that press the record button.

Record

Once you hit record it will open a web browser and record all your events.  For this recording, I am just going to visit microsoft.com and hit a few pages.  Note that you can record fill out forms, submit forms, run api requests, execute ajax requests etc…  In short, you can record all the same things you normally do when running your website.  Once you stop recording, Visual Studio will show all the actions that were performed.

RecordEvents

Generate Code From Recorded Test

Next, you can run your test by right clicking on the WebTest that was just recorded.

Runtests

However, what I am going to to is generate some code from this recorded test.  This gives us the ability to write our own additional code.  For example, maybe you want to submit that recorded form request using data out of a database or from a CSV file.

GenerateCode

What this will do is generate code like the following

RecordedCode

Its in this code base that we can add our own C# to fit our needs.  We can also use this code during a load test.

Add a Load Test

Next, add a load test to the project by right clicking on the project and selecting add Load Test.  This is where it gets slick!  You will be presented with a wizard that will set up a testing environment for you in Azure in which you can have your testing scenarios run either the recorded webtest or the generated code.  The wizard will look like the following.  Furthermore, we can tell the load test where to run from.  For example a cluster of Azure VMs or the local PC.  That is slick!  Basically we get a bunch of VMs out in the wild that can simulate “hammering” on our website.

To get this going, once you right click and select “Add Load Test” you will see this wizard.

TestWizard

By following this wizard we can set all sorts of options.  Some important ones are, for example, setting the number of simulated users or setting the data center where the load will run from.  There are TONs of other settings….how long the test will run for, what tests to run, what browsers to use during the test etc.  There is a entire suite of settings and configurations that can be leveraged.  That is beyond the scope of this blog post.  Suffice to say you can get very sophisticated in the configurations and mix and match scenarios to give us the ability to simulate as close as possible real world load traffic.

Note, you can run these same load tests from your machine but some of the configuration settings won’t be relevant when running from one machine.  When I was first getting started with load testing, I would run tests locally and then create a version that I would run out in the cloud.  I gave them different scenario / test names so I could distinguish between the two different versions.

(Sample Run Duration Settings)

RunSettings

(Sample User Settings)

UserCounts

(Sample Mix of Either Recorded Tests or Web Tests to Run)

LoadTestScenarios

 

Run The Load Test In The Cloud

Once you get through the wizard, you will wind up with a Load Test harness that looks like the following.  From here you can run your test and watch progress.  You can also configure the metrics you want to measure.  For example, metrics like requests/sec, available memory, # error pages etc..  There are a TONS of them.

LoadTestHarness

What we were doing was spinning up various scenarios, throwing load at our servers and ensuring our ELMAH logs were clean under heavy load.  We were also checking that all the form submissions and other various api functionality was performing as expected.   All of this was achieved though simulated load.

In short, with not much work we were able to get a good look at how our web applications would perform under load thanks to Visual Studio and Azure.

 

 

Leave a Reply