Compartilhar via


Load Test Plug-in – Simulate Repeated Peak Load Modeling

In my previous posts, I have shown how to simulate repeated custom user load pattern groups. Here is another plug-in sample to simulate the PeakLoad modeling, i.e. VallyLoad-StepUp-PeakLoad-StepDown. In this plug-in, all the configurations can be passed in through the Load Test Plug-in properties. As shown in the below screenshot, it simulates a peak load of 800 users every 3 minutes.

image

Step 1 – Create CustomLoadProfiles library

You can copy the code in this post and build the class library. [The sample code can be downloaded from codeplex.]

Step 2 – Add a reference to class library CustomLoadProfiles in the test project

Step 3 – Add the PeakLoadModelingPlugin to the test project

[PeakLoadModelingPlugin . cs] [The sample code can be downloaded from codeplex.]

 using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using Microsoft.VisualStudio.TestTools.LoadTesting;
using CustomLoadProfiles;

namespace TestProject1
{
    [Description("This plug-in simulates the Peak user load Pattern every 3 minutes")]
    public class PeakLoadModelingPlugin : ILoadTestPlugin
    {     
        public void Initialize(LoadTest loadTest)
        {
            m_loadTest = loadTest;
            m_profileManager = new LoadProfileManager();

            // The heartbeat event will be fired every second, it can be used to adjust the user load
            m_loadTest.Heartbeat += new EventHandler<HeartbeatEventArgs>(m_loadTest_Heartbeat);

            // Create the custom load pattern based on the configurations passed through the plug-in properties
            CreateLoadProfileGroups();
        }

        // Create a custom user load profile group: Valley-StepUp-Peak-StepDown
        void CreateLoadProfileGroups()
        {           
            // Create the custom load pattern group
            // Calculate the duration
            // If the RepeatCount for the Peak Load pattern is not specified, check the PercentageOfDuration, and calculate
            int patternDuration = 0;
            if (RepeatCount == 0)
            {
                double patternDurationInDouble = m_loadTest.RunSettings.RunDuration * PercentageOfDuration / 100;
                patternDuration = (Int32)Math.Ceiling(patternDurationInDouble);
            }
            else
            {
                patternDuration = (ValleyTime + RampUpTime + PeakTime + RampDownTime) * RepeatCount;
            }

            LoadProfileGroup profileGroup = new LoadProfileGroup("Valley-StepUp-Peak-StepDown", patternDuration);

            // Add the load profiles to a group
            // The step duration 5 seconds will be used to simulate the step up/down
            int stepDuration = 5;

            // 1. Simulate the ValleyLoad for a duration of ValleyTime
            profileGroup.AddProfile(new ConstLoadWrapper(ValleyLoad, ValleyTime));

            // 2. Simulate step up load - step up from ValleyLoad to PeakLoad in the RampUpTime window
            double stepCount = Math.Round((double)(PeakLoad - ValleyLoad) * stepDuration / RampUpTime);
            profileGroup.AddProfile(new StepLoadWrapper(ValleyLoad, ValleyLoad, PeakLoad, (int)stepCount, stepDuration, 0, RampUpTime));

            // 3. Simulate Peakload for PeakTime
            profileGroup.AddProfile(new ConstLoadWrapper(PeakLoad, PeakTime));

            // 4. Simulate step down load - step down from PeakLoad to ValleyLoad in the RampDownTime window
            stepCount = Math.Round((double)(PeakLoad - ValleyLoad) * stepDuration / RampDownTime);
            CustomLoadWrapper profileWrapper = new CustomLoadWrapper(RampDownTime);
            profileWrapper.Profile = new LoadTestStepDownLoadProfile(PeakLoad, ValleyLoad, PeakLoad, (int)stepCount, stepDuration);
            profileGroup.AddProfile(profileWrapper);

            // Add the profile group 
            m_profileManager.ProfileGroups.Add(profileGroup);

            // Tell the profile manager that we want to simulate the custom pattern right after test run is started
            m_profileManager.SetStartEndTimeForProfileGroups(0);
        }

        // The following heartbeat event will be fired every second, it can be used to adjust the user load
        void m_loadTest_Heartbeat(object sender, HeartbeatEventArgs e)
        {
            if (!e.IsWarmupComplete)
            {
                return;
            }

            // Get the load profile to be applied for the event
            LoadTestLoadProfile profile = m_profileManager.GetCurrentLoadProfile(e.ElapsedSeconds, m_loadTest.Scenarios[0].CurrentLoad);
            if (profile != null)
            {
                m_loadTest.Scenarios[0].LoadProfile = profile;
            }
        }

        #region Load Profile Configurations
        [DefaultValue(20)]
        [Description("The Valley Load")]
        public int ValleyLoad
        {
            get { return m_valleyLoad; }
            set { m_valleyLoad = value; }
        }

        [DefaultValue(20)]
        [Description("The Peak Load")]
        public int PeakLoad
        {
            get { return m_peakLoad; }
            set { m_peakLoad = value; }
        }

        [DefaultValue(60)]
        [Description("The amount of time that ValleyLoad will be simulated")]
        public int ValleyTime
        {
            get { return m_valleyTime; }
            set { m_valleyTime = value; }
        }

        [DefaultValue(60)]
        [Description("The amount of time that PeakLoad will be simulated")]
        public int PeakTime
        {
            get { return m_peakTime; }
            set { m_peakTime = value; }
        }

        [DefaultValue(20)]
        [Description("The amount of time to ramp up from ValleyLoad to PeakLoad")]
        public int RampUpTime
        {
            get { return m_rampUpTime; }
            set { m_rampUpTime = value; }
        }

        [DefaultValue(20)]
        [Description("The amount of time to step down from PeakLoad to ValleyLoad")]
        public int RampDownTime
        {
            get { return m_rampDownTime; }
            set { m_rampDownTime = value; }
        }

        [DefaultValue(20)]
        [Description("The number of times to repeat this pattern")]
        public int RepeatCount
        {
            get { return m_repeatCount; }
            set { m_repeatCount = value; }
        }

        [DefaultValue(100)]
        [Description("When the RepeatCount is 0. This property specifies the % of the duration that the pattern will be simulated. Default to entire duration")]
        public int PercentageOfDuration
        {
            get { return m_percentageOfDuration; }
            set { m_percentageOfDuration = value; }
        }

        #endregion

        private LoadTest m_loadTest;
        private LoadProfileManager m_profileManager;

        private int m_valleyLoad;
        private int m_peakLoad;

        private int m_valleyTime;
        private int m_peakTime;
        private int m_rampUpTime;
        private int m_rampDownTime;

        private int m_repeatCount;
        private int m_percentageOfDuration;
    }
}

Step 4 – Configure the modeling properties

Add the PeakLoadModelingPlugin to your load test. The modeling properties can be configured through the Add Load Test Plug-in dialog.

image

Comments

  • Anonymous
    November 08, 2010
    Hello YuTong I am getting the following error which I am unable to figure out could you please offer me some advice on why the script is failing to build correctly. Am I missing a reference it requires? It doesn't not like LoadProfileManager? The type or namespace name 'LoadProfileManager' could not be found (are you missing a using directive or an assembly reference?)        private LoadTest m_loadTest;        private LoadProfileManager m_profileManager;        private int m_valleyLoad;        private int m_peakLoad; Error: TestProjectLivelink -> C:CIMSPerformanceTestScenariosTestProjectLivelinkTestProjectLivelinkbinDebugTestProjectLivelink.dll ------ Rebuild All started: Project: PeakLoadModelingPlugin, Configuration: Debug Any CPU ------ C:WINDOWSMicrosoft.NETFrameworkv3.5Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"c:Program FilesMicrosoft Visual Studio 9.0Common7IDEPublicAssembliesMicrosoft.VisualStudio.QualityTools.LoadTestFramework.dll" /reference:"c:Program FilesMicrosoft Visual Studio 9.0Common7IDEPublicAssembliesMicrosoft.VisualStudio.QualityTools.UnitTestFramework.dll" /reference:"c:Program FilesMicrosoft Visual Studio 9.0Common7IDEPublicAssembliesMicrosoft.VisualStudio.QualityTools.WebTestFramework.dll" /reference:"C:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Core.dll" /reference:"C:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Data.DataSetExtensions.dll" /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Data.dll /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.dll /reference:C:WINDOWSMicrosoft.NETFrameworkv2.0.50727System.Xml.dll /reference:"C:Program FilesReference AssembliesMicrosoftFrameworkv3.5System.Xml.Linq.dll" /reference:C:CIMSPerformanceTestScenariosTestProjectLivelinkTestProjectLivelinkbinDebugTestProjectLivelink.dll /debug+ /debug:full /filealign:512 /optimize- /out:objDebugPeakLoadModelingPlugin.dll /target:library Class1.cs PropertiesAssemblyInfo.cs C:CIMSPerformanceTestScenariosTestProjectLivelinkPeakLoadModelingPluginClass1.cs(157,17): error CS0246: The type or namespace name 'LoadProfileManager' could not be found (are you missing a using directive or an assembly reference?) Thanks for your Help

  • Anonymous
    December 09, 2010
    The link to codeplex does not seem to be correct - that's all about Silverlight web tests

  • Anonymous
    December 09, 2010
    The link to codeplex does not seem to be right - that's all about Silverlight web tests

  • Anonymous
    January 07, 2011
    I have cusomized this to read the load pattern from the file to have loade varying at diferent intervels.  But the problem is that with controller and agent scenario, the simulation is not working properly.  Any input on this