最大并发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属性来控制它。
拉莫斯之舞
TA贡献1820条经验 获得超10个赞
对于.NET Core,我没有听说过这个。ServicePointManager未包含在.NET Core 1中,但在版本2中似乎又回来了。但是,对于HttpClient,您还可以设置最大连接数,如下所示:
new HttpClient(new HttpClientHandler { MaxConnectionsPerServer = 100 })
- 3 回答
- 0 关注
- 627 浏览
添加回答
举报
0/150
提交
取消