Click here to Skip to main content
15,887,135 members
Articles / Web Development / ASP.NET

Performance Scripting ASP.NET

Rate me:
Please Sign up or sign in to vote.
1.00/5 (1 vote)
26 Apr 20064 min read 33.9K   153   13  
An article detailing a custom ASP.NET performance testing application.
using System;

namespace AGENT
{
	public class ExecutionInstance
	{
		public WebInterface WebInterface;
		public QTools.IWebTest WebTest;
		public QTools.LogFile LogFile;
		public QTools.DelayHelper DelayHelper;
		public QTools.Setting Settings;
		public string TestInstance = System.Guid.NewGuid().ToString();
		public Guid TestGuid = Guid.Empty;
		public int StartDelay;
		public QTools.SimultaneousConnections SimultaneousConnections;
		public string BaseURL;

		public int Iterations;

		public ExecutionInstance()
		{
		}

		public void Start()
		{
			System.Threading.Thread.Sleep(StartDelay);

			switch (SimultaneousConnections)
			{

				case QTools.SimultaneousConnections.Fixed:
					FixedConnections();
					break;

				case QTools.SimultaneousConnections.Increasing:
					IncreasingConnections();
					break;
			}
		}

		private void FixedConnections()
		{
			for (int i=0;i<Iterations; i++)
			{
				DateTime dtStart = DateTime.Now;
				WebTest.Start();
				DateTime dtEnd = DateTime.Now;
				TimeSpan tsTime = dtEnd - dtStart;
			}
		}

		private void IncreasingConnections()
		{
			for (int i=1; i<=Settings.NumberOfSimulatenousConnections; i++)
			{
				int startDelay = 0;
				System.Collections.ArrayList arrThreads = new System.Collections.ArrayList();
				for (int j=1; j<=i; j++)
				{
					ExecutionInstance ei = new ExecutionInstance();

					ei.BaseURL = BaseURL;
					ei.DelayHelper = DelayHelper;
					ei.WebInterface = WebInterface;
					ei.LogFile = LogFile;
					ei.Settings = Settings;
					ei.WebTest =  WebInterface.GetInstance();
					ei.TestGuid = TestGuid;
					ei.TestInstance =  TestInstance + "_" + i.ToString() + "_" + j.ToString();
					ei.StartDelay = StartDelay;
					startDelay += Settings.StartDelayMilliSeconds;

					ei.WebTest.InitializeTest(Settings, LogFile, DelayHelper, ei.TestInstance, BaseURL);
	
					ei.Iterations = Settings.NumberOfIterations;
					ei.SimultaneousConnections = QTools.SimultaneousConnections.Fixed;

					System.Threading.ThreadStart ts = new System.Threading.ThreadStart(ei.Start);
					System.Threading.Thread t = new System.Threading.Thread(ts);
					lock (ExecuteRun.ExecutingThreads)
					{
						ExecuteRun.ExecutingThreads.Add(t);
					}
					arrThreads.Add(t);
					t.Start();
				}

				//Wait for all threads to finish...
				foreach (System.Threading.Thread thread in arrThreads)
				{
					if (thread.IsAlive)
					{
						thread.Join();
					}
				}
			}
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions