为了账号安全,请及时绑定邮箱和手机立即绑定

最大并发HttpWebRequests数

最大并发HttpWebRequests数

HUH函数 2019-07-30 15:57:21
最大并发HttpWebRequests数我正在对一个Web应用程序进行压力测试,并设置了一个Windows测试程序,该程序可以旋转多个线程并在每个线程上发出Web请求。问题是我得到以下输出:01/09/09 11:34:04 Starting new HTTP request on 1001/09/09 11:34:04 Starting new HTTP request on 1101/09/09 11:34:04 Starting new HTTP request on 1301/09/09 11:34:05 Starting new HTTP request on 1401/09/09 11:34:05 Starting new HTTP request on 1101/09/09 11:34:05 11 has finished!01/09/09 11:34:05 Starting new HTTP request on 1301/09/09 11:34:05 13 has finished!01/09/09 11:34:05 Starting new HTTP request on 1401/09/09 11:34:05 14 has finished!01/09/09 11:34:05 Starting new HTTP request on 1101/09/09 11:34:05 11 has finished!01/09/09 11:34:05 Starting new HTTP request on 1401/09/09 11:34:05 14 has finished!01/09/09 11:34:05 Starting new HTTP request on 1301/09/09 11:34:05 13 has finished!01/09/09 11:34:05 Starting new HTTP request on 1501/09/09 11:34:06 Starting new HTTP request on 1101/09/09 11:34:06 11 has finished!01/09/09 11:34:06 Starting new HTTP request on 1401/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();    }任何人都可以告诉我发生了什么事吗?
查看完整描述

3 回答

?
温温酱

TA贡献1752条经验 获得超4个赞

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

查看完整回答
反对 回复 2019-07-30
?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

对于.NET Core,我没有听说过这个。ServicePointManager未包含在.NET Core 1中,但在版本2中似乎又回来了。但是,对于HttpClient,您还可以设置最大连接数,如下所示:

new HttpClient(new HttpClientHandler
                {
                    MaxConnectionsPerServer = 100
                })


查看完整回答
反对 回复 2019-07-30
  • 3 回答
  • 0 关注
  • 627 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信