基于 Windows 的应用程序来测试我的 ASP.NET 应用程序

发布于 2024-12-26 20:56:55 字数 996 浏览 7 评论 0原文

我想强调我的网站具有多种访问能力。为此,我创建了一个基于 Windows 的应用程序,该应用程序调用网站 1000 次。 不幸的是它只适用于 2 个电话。这是代码:

    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();               
        }

    }

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();               
        }

    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

苄①跕圉湢 2025-01-02 20:56:55

而是使用 免费 WCAT 工具 用于加载测试您的 ASP.NET 页面。

另请观看此视频 [如何:] 对 Web 应用程序进行负载测试

如果您有 Visual Studio 2010 Ultimate,请参阅此链接

我希望这有帮助。

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.

半枫 2025-01-02 20:56:55

默认情况下,HttpRequest 仅允许到同一主机的两个连接。
您可以通过设置 DefaultConnectionLimit 属性来更改此设置。

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

神也荒唐 2025-01-02 20:56:55

在继续之前尝试处理 IDisposable 实例(即响应)。

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);
    }
}

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);
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文