user422688
user422688

Reputation: 617

Windows based application to test my ASP.NET application

I want to stress my website with multiple access. To do that i created a windows based application that call 1000 times the website. Unfortunatly it work just for 2 call. This is the code:

    static void myMethod( int i)
    {
        int j = 0;

        try
        {
            string url = "";
            WebRequest wr = null;
            HttpWebResponse response = null;                                
            url = String.Format("http://www.google.com");
            wr = WebRequest.Create(url);
            //wr.Timeout = 1000;
            response = (HttpWebResponse)wr.GetResponse();                
            MessageBox.Show("end");
        }
        catch (Exception ex)
        {
            MessageBox.Show(j.ToString() + "   " + ex.Message);
        }
    }

    private void button1_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < 1000; i++)
        {
            ThreadStart starter = delegate { myMethod(i); };
            Thread thread = new Thread(starter);
            thread.Start();               
        }

    }

Upvotes: 0

Views: 813

Answers (3)

to StackOverflow
to StackOverflow

Reputation: 124726

By default HttpRequest only allows two connections to the same host. You can change this by setting the DefaultConnectionLimit property.

Upvotes: 1

Dirk Strauss
Dirk Strauss

Reputation: 641

Rather use the Free WCAT Tool to load test your ASP.NET page.

Also view this video [How Do I:] Load Test a Web Application

If you have Visual Studio 2010 Ultimate, see this link

I hope this helps.

Upvotes: 2

spender
spender

Reputation: 120500

Try disposing the IDisposable instances (i.e. the response) before continuing.

static void myMethod( int i)
{
    int j = 0;

    try
    {

        string url = String.Format("http://www.google.com");
        WebRequest wr = WebRequest.Create(url);
        using(HttpWebResponse response = (HttpWebResponse)wr.GetResponse())
        using(Stream responseStream = wr.GetResponseStream())
        {
            //handle response / response stream
        }                
        MessageBox.Show("end");  //this won't scale!!!
    }
    catch (Exception ex)
    {
        MessageBox.Show(j.ToString() + "   " + ex.Message);
    }
}

Upvotes: 0

Related Questions