I have a simple console application which looks like this:
private static StringBuilder sb = new StringBuilder();
private static HttpClient client = new HttpClient();
private static async Task<HttpStatusCode> AccessTheWebAsync()
{
HttpResponseMessage response = await client.GetAsync("http://www.google.com").ConfigureAwait(false);
return response.StatusCode;
}
static void Main(string[] args)
{
Stopwatch sw = new Stopwatch();
sw.Start();
List<Task> tasks = new List<Task>();
for (int i = 0; i < 10; i++)
tasks.Add(AccessTheWebAsync());
Task.WaitAll(tasks.ToArray());
foreach (Task<HttpStatusCode> t in tasks)
sb.Append((int)t.Result).Append(Environment.NewLine);
Console.WriteLine(sb.ToString());
sw.Stop();
Console.WriteLine("Run Completed, Time elapsed: {0}", sw.Elapsed);
Console.ReadLine();
}
Here I initiate 10 async web requests and collect the response codes when the requests are completed and list them.
Reason being is I found out there's something you can change on the App.config
:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.net>
<connectionManagement>
<add address = "*" maxconnection = "10" />
</connectionManagement>
</system.net>
</configuration>
But, I've not a good way to determine if this is actually working or not.
Do servers set this limit?
Does the OS set this limit?
Does this app config and/or .NET set this limit?
Is it possible to use VS2012 to debug the app in such a way where I can determine the number of concurrent web requests that are happening at any given point during execution?
Yes, surely. Use Parallel Tasks and Parallel Stacks windows, they are very good.
Do servers set this limit?
Does the OS set this limit?
Does this app config and/or .NET set this limit?
The setting specifies the maximum number of connections to a network host and can be set on the machine or application level. A server could set a connection limit for the clients as well but that's not related to maxconnection
attribute.
In your example the actual maximum number of connections can also be limited by thread pool settings. Have a look at this KB entry for more details.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With