最大并发HttpWebRequests数

最大并发HttpWebRequests数

我正在对一个Web应用程序进行压力测试,并设置了一个Windows测试程序,该程序可以旋转多个线程并在每个线程上发出Web请求。


问题是我得到以下输出:


01/09/09 11:34:04 Starting new HTTP request on 10

01/09/09 11:34:04 Starting new HTTP request on 11

01/09/09 11:34:04 Starting new HTTP request on 13

01/09/09 11:34:05 Starting new HTTP request on 14

01/09/09 11:34:05 Starting new HTTP request on 11

01/09/09 11:34:05 11 has finished!

01/09/09 11:34:05 Starting new HTTP request on 13

01/09/09 11:34:05 13 has finished!

01/09/09 11:34:05 Starting new HTTP request on 14

01/09/09 11:34:05 14 has finished!

01/09/09 11:34:05 Starting new HTTP request on 11

01/09/09 11:34:05 11 has finished!

01/09/09 11:34:05 Starting new HTTP request on 14

01/09/09 11:34:05 14 has finished!

01/09/09 11:34:05 Starting new HTTP request on 13

01/09/09 11:34:05 13 has finished!

01/09/09 11:34:05 Starting new HTTP request on 15

01/09/09 11:34:06 Starting new HTTP request on 11

01/09/09 11:34:06 11 has finished!

01/09/09 11:34:06 Starting new HTTP request on 14

01/09/09 11:34:06 14 has finished!

哪种看起来最多有5个线程,即使我这样创建100个:


int numberOfThreads = Convert.ToInt32(txtConcurrentThreads.Text);


    List<BackgroundWorker> workers = new List<BackgroundWorker>();


    for (int N = 0; N < numberOfThreads; N++)

    {


        BackgroundWorker worker = new BackgroundWorker();

        worker.DoWork += new DoWorkEventHandler(worker_DoWork);

        worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);

        workers.Add(worker);

    }



    foreach(BackgroundWorker worker in workers)

    {

        worker.RunWorkerAsync();

    }

任何人都可以告诉我发生了什么事吗?


HUH函数
浏览 628回答 3
3回答

温温酱

同时传出HTTP连接的数量有限制。我认为你可以System.Net.ServicePointManager.DefaultConnectionLimit在创建HttpWebRequest对象之前使用static属性来控制它。

拉莫斯之舞

对于.NET Core,我没有听说过这个。ServicePointManager未包含在.NET Core 1中,但在版本2中似乎又回来了。但是,对于HttpClient,您还可以设置最大连接数,如下所示:new&nbsp;HttpClient(new&nbsp;HttpClientHandler &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;MaxConnectionsPerServer&nbsp;=&nbsp;100 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;})
打开App,查看更多内容
随时随地看视频慕课网APP