Share via


Creating a custom load profile which will step user load up and then back down

This blog post is going to show you how to create a custom load profile. Out of the box there are 3 load profiles: constant, step and goal. I will show you how to create a load profile and how to set it with a load test plug-in. We will walk through creating a profile which is similar to the step profile, but after a set number of seconds will start decreasing the load in a step manner.

First, the ability to create a custom load profile was added in VS 2008 SP1. So if you have not installed SP1, please install it now.

Creating the profile:

1) Add a class to the test project.

2) Add a using statement for Microsoft.VisualStudio.TestTools.LoadTesting

3) To implement a custom profile, you have to extend the LoadTestLoadProfile class. Check out Bill Barnett’s blog post for more information on the base class: https://blogs.msdn.com/billbar/pages/load-test-api-enhancements-in-vsts-2008-sp1-beta.aspx

4) You can extend one of the existing profiles. We will extend LoadTestStepLoadProfile. We want our custom profile to do the what the step profile does, but then switch behavior at a configured time in the load test.

5) We need to add 3 new properties to our custom profile:

public int StepDownUserCount {get; set;}

      public int StepDownStepDuration { get; set; }

      public int StartStepDownAtRunOffset { get; set; }

6) A custom load profile needs to override the int GetLoad(int elapsed) method. We want to use the base functionality up until the StartStepDownAtRunOffset. At that point we need to start the step down. Here is what our method will look like:

public override int GetLoad(int elapsed)

        {

            if (elapsed < StartStepDownAtRunOffset)

            {

             m_lastStepUpCount = base.GetLoad(elapsed);

                return m_lastStepUpCount;

            }

            else

            {

                long currentUserCount = m_lastStepUpCount - (StepDownUserCount * ((elapsed - StartStepDownAtRunOffset) / StepDownStepDuration));

                return (int)Math.Max(Math.Max(currentUserCount, 0), MinUserCount);

            }

        }

7) Here is the full class:

 

using System;

using System.Diagnostics;

using Microsoft.VisualStudio.TestTools.LoadTesting;

namespace TestProject1

{

    [Serializable()]

    public class StepUpAndDownLoadProfile : LoadTestStepLoadProfile

    {

        public StepUpAndDownLoadProfile(int runDuration)

        {

            InitialUserCount = 10;

            StepUserCount = 10;

            StepDuration = 10;

            StartStepDownAtRunOffset = runDuration;

            m_runDuration = runDuration;

          

        }

       

        // ******************************************************************

               

        public override int GetLoad(int elapsed)

        {

            if (elapsed < StartStepDownAtRunOffset)

            {

                m_lastStepUpCount = base.GetLoad(elapsed);

                return m_lastStepUpCount;

            }

            else

            {

                long currentUserCount = m_lastStepUpCount - (StepDownUserCount * ((elapsed - StartStepDownAtRunOffset) / StepDownStepDuration));

                return (int)Math.Max(Math.Max(currentUserCount, 0), MinUserCount);

            }

        }

        public override void Validate()

        {

            base.Validate();

           

        }

        public int StepDownUserCount {get; set;}

        public int StepDownStepDuration { get; set; }

        public int StartStepDownAtRunOffset { get; set; }

        // ******************************************************************

        // Private members

        // ******************************************************************

        private int m_runDuration;

        private int m_lastStepUpCount;

    }

}

 

Creating the Plug-in:

You set a custom load profile in a load test plug-in. The plug-in below will create an instance of the new plug-in and set it on the first scenario. You can see that it sets the step up and step down properties. The user load does not need to decrease at the same rate that it increased.

 

using Microsoft.VisualStudio.TestTools.LoadTesting;

namespace TestProject1

{

    public class SampleLoadTestPlugin : ILoadTestPlugin

    {

        #region ILoadTestPlugin Members

        public void Initialize(LoadTest loadTest)

        {

            StepUpAndDownLoadProfile p = new StepUpAndDownLoadProfile(loadTest.RunSettings.RunDuration);

            p.InitialUserCount = 20;

            p.MaxUserCount = 100;

            p.MinUserCount = 5;

            p.StepUserCount = 5;

            p.StepDuration = 10;

            p.StepRampTime = 0;

            p.StartStepDownAtRunOffset = 480;

            p.StepDownStepDuration = 5;

            p.StepDownUserCount = 10;

            loadTest.Scenarios[0].LoadProfile = p;

        }

        #endregion

    }

}

 

 

The values used in the above plug-in do the following:

1) Start at 20 users.

2) Add 5 users every 10 seconds until you reach 100 users

3) Stay at 100 users until 480 seconds into the test.

4) Then start decreasing the user load by 10 users every 5 second until you reach 5 users.

I ran this test for ten minutes. Here is what the user load counter for this test looks like:

 

 

 

I hope this post shows you how to create custom plug-in and set them on a scenario. Another way to extend this example would be to create a xml document that has the user load at different times during the load test. Then you could read that xml do in from the plugin and pass it to your custom profile. Then the custom profile would set the userload based on the values from the xml doc. This would allow you to step the load up, step down, back up, etc.

Comments

  • Anonymous
    May 04, 2009
    This blog post will show you how to create custom load profiles by walking you thorugh the process of

  • Anonymous
    May 06, 2009
    How does this work with Test Mix allocation. Say I have two scripts in my test mix. A@ 25% and B@ 75%. And the scripts dont take more than a minute. The user will drop off after a minute, will a new user be brought in to keep up with the count? And how does ramping down work? how does the tool figure out which user (A Script or B Script) to drop?

  • Anonymous
    May 07, 2009
    It drops users off based on who finishes first.  So if I drop the user load by 10 users, then the next 10 users to finish will be stopped. As for the percentages, it doesn't necessarily go hand in hand with user load.  So if you have 75/25 split, that means for the next test selected there is a 75% chance it is test a and a 25 % chance it is test b.  Or if you choose the mix profile which is based on # of tests running, the engine will attempt to keep the mix of tests running as close to what you have entered as possible.

  • Anonymous
    November 18, 2009
    Hey, I notice a lot of information on how to run a Custom Load test plugin on a local machine but how do you do it on a rig with 5 agents? My plugin works when i'm running a load test on my local machine, but when i run it remotely the default settings step settings are registering and my custom load does not work. The way the plug-in changes the load is through the heartbeat methods while reading the custom number from a txt.file stored in "C:/UserLoad.txt". Do i need to write this file on all 5 agents or something?  Can you please advise me on how to use a custom load plugin that reads from a text file on a rig with 5 agents. Thank You. Keaton

  • Anonymous
    November 18, 2009
    The comment has been removed