Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET Core Configuration - System.Net connectionManagement/maxconnections?

I am migrating a console app (REST client app) from .NET framework to .NET Core.

In my current (framework) version, I use the app.config file to set the System.Net configuration:

<system.net>
    <connectionManagement>
      <add address="*" maxconnection="65535"/>
    </connectionManagement>
</system.net>

In .NET Core, I have to use a JSON file for configuration. There is no documentation for implementing these settings using the new configuration schema. Does anyone know how this might look inside the new JSON config, or the correct way to implement this in Core? Do I need to build a designated "System.Net.json" config file (separate from an AppSettings.json) specifically to do this?

Thanks.

like image 803
mholberger Avatar asked Oct 04 '17 18:10

mholberger


2 Answers

I assume you're trying to avoid the limit of 2 connections per endpoint, which is default on .NET Framework. Such limit does not exist on .NET Core. So you don't need the above setting at all.

Note that to achieve better perf, we recommend to use HttpClient/HttpClientHandler over HttpWebRequest/ServicePoint on .NET Core. HttpWebRequest/ServicePoint APIs are compat-only.

If you want to limit HttpClient connections, then use HttpClientHandler.MaxConnectionsPerServer

like image 107
Karel Zikmund Avatar answered Oct 22 '22 01:10

Karel Zikmund


Assuming you are using Kestrel as your web server (and not doing it through IIS implementation), you should be able to set this in your UseKestrel in your BuildWebHost.

It would go something like this:

.UseKestrel(options =>
{
    options.Limits.MaxConcurrentConnections = 100;
})

You can also add this in your HttpClientHandler, It's called MaxConnectionsPerServer. It can be seen here.

like image 21
Scott Craig Avatar answered Oct 22 '22 03:10

Scott Craig