Are there any limit to how many concurrent/parallel requests you can send using WebClient, HttpWebRequest, and HttpClient class in .NET 4.5? Or is it that you can send unlimited parallel requests if there is no restriction on the web API or server? Sorry if the question is too broad, please correct me so I can narrow it down.
相关问题
- Angular RxJS mergeMap types
- Generic Generics in Managed C++
- How to Debug/Register a Permanent WMI Event Which
- 'System.Threading.ThreadAbortException' in
- Bulk update SQL Server C#
相关文章
- C#使用http访问网络,有办法用指定网卡访问网络嘛?
- .net中MessageBox.Show使用问题
- IdentityServer 报错:"idp claim is missing"
- 在 IdentityServer 中如何给 id token 添加更多信息
- IdentityServer 的 Selector 在哪个 nuget 包
- 使用 IdentityServer 的项目遭遇错误:"IDX20803: Unable to obt
- ASP.NET Core ConfigureServices 中从 appsettings.json
- .netCore 控制台程序输出配置问题
Yes, there is a limit. The default connection limit is 2 concurrent connections per remote host. This can be overridden. For example, I believe that ASP.NET by default overrides the default to be 10 connections per remote host.
From https://msdn.microsoft.com/en-us/library/7af54za5.aspx:
To change the connection limit yourself, use
ServicePointManager.DefaultConnectionLimit
. Make sure to make this change soon after your process starts up, before you start making HTTP connections to the remote host. This is because because once you actually make an HTTP connection to a remote host, then aServicePoint
will be created for that remote host using the current default connection limit.Note that there are other effective limits on concurrent connections beyond what's enforced by the HTTP client classes. For example, if you wanted to open a million concurrent connections, you'd probably run out of RAM, or threads, or some other OS resource. If you're bumping up against those limits, then you'll need to ask another more general question about how to scale up a .net process to process a lot of concurrent I/O. But if you're only opening a few tens of connections then you should be fine.
BTW, if you're curious why the default limits are so low, it's actually baked into the HTTP specification-- the goal was to ensure that selfish HTTP clients didn't swamp HTTP servers with simultaneous connections. Although modern browsers ignore the spec. See http://www.stevesouders.com/blog/2008/03/20/roundup-on-parallel-connections/ for a lot more detail about this topic than you ever wanted to know!