Click here to Skip to main content
15,886,639 members
Articles / All Topics

Generate thousand of request

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
3 Aug 2011CPOL1 min read 11.6K   2  
Lastly I was working on the project where I have to designed web page which is exposing some set of the functions and which is get consume by some external application like java and flex.
Lastly I was working on the project where I have to designed web page which is exposing some set of the functions and which is get consume by some external application like java and flex. It's worked fine and providing the output I want.

But now I want to perform the load test, so for that I want to generate thousand of request which consume the page and show me how it works. But the problem is how to generate the request because I don't have that many people who can make request at given time.

Solution for this problem I make use of the Thread class and loop it to the no. of request I have to generate as you see in below code.
for (int i = 0; i < 100; i++)
{
    Thread thread1 = new Thread(new ThreadStart(WorkThreadFunction1));
    thread1.Start();
}
Now the secondly I made use of HttpWebRequest class which allow me to call the page and to get the response. You can get more information about HttpWebRequest.
public void WorkThreadFunction1()
{
   try
   {
     string param = string.Empty;
     HttpWebRequest oWebReq =     
      (HttpWebRequest)WebRequest.Create("http://mywebsite/WebForm1.aspx" + param);
     HttpWebResponse oWebResp = (HttpWebResponse)oWebReq.GetResponse();
     StreamReader oStream = new StreamReader(oWebResp.GetResponseStream(),     
                                                     System.Text.Encoding.ASCII);
     Console.WriteLine(oStream.ReadToEnd());
   }
   catch (Exception ex)
   {
      // log errors
   }
}
As you can see in the above code I am making the call to the my page and writing the response to the console window.
Note:
Here WebForm1 is entry point based on the parameter passed to it , it calls the different function and may be the pages in your site.
Here I am making request to one single page but you can write you own script to call the different page and pass the parameter to it.

Summary
So you can easily make no. of request without need of the no. of people. But this thing depends on the requirement in you case.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior)
India India

Microsoft C# MVP (12-13)



Hey, I am Pranay Rana, working as a Team Leadin MNC. Web development in Asp.Net with C# and MS sql server are the experience tools that I have had for the past 5.5 years now.

For me def. of programming is : Programming is something that you do once and that get used by multiple for many years

You can visit my blog


StackOverFlow - http://stackoverflow.com/users/314488/pranay
My CV :- http://careers.stackoverflow.com/pranayamr

Awards:



Comments and Discussions

 
-- There are no messages in this forum --