Why can't I have more than 5 WebClient.DownloadFileAsync?

I am trying to test another application by requesting a lot of files.

So, I started 10 WebClient instances with the following code, but it seems that I can have only 5 starts at a time.

 class Program { public static object locker = new object(); public static void Main(string[] args) { for (int i = 0; i < 10; i++) start(i); Console.ReadLine(); } private static void start(object row) { DateTime start = DateTime.Now; WebClient client = new WebClient(); client.Credentials = CredentialCache.DefaultNetworkCredentials; client.DownloadProgressChanged += (sender, e) => { lock (locker){ double throughput = e.BytesReceived / (DateTime.Now - start).TotalSeconds / 1024 / 1024; double error = 1 - (1 / throughput); Console.SetCursorPosition(0, (int)row); Console.WriteLine( @"({0}) {1:HH\:mm\:ss.ffff} - {2:0.00}Mb - " + @"{3:##0}% - {4:0.00}Mb/s ({5:+0.00%;-0.00%;0.00%}){6}", row, DateTime.Now, e.BytesReceived / 1024 / 1024, e.ProgressPercentage, throughput, error, " "); } }; client.DownloadFileAsync( new Uri("http://site/Download.ashx?Id=123"), String.Format("c:\\foo_{0}.xxx", row)); } } 

I got the following result:

  (0) 14: 51: 07.1830 - 39.00Mb - 5% - 0.94Mb / s (-6.45%)
 (1) 14: 51: 06.8610 - 39.00Mb - 5% - 1.00Mb / s (+ 0.24%)
 (2) 14: 51: 06.5650 - 39.00Mb - 5% - 0.99Mb / s (-1.34%)
 (3) 14: 51: 07.2810 - 38.00Mb - 5% - 0.95Mb / s (-5.12%)
 (4) 14: 51: 06.5740 - 37.00Mb - 5% - 0.95Mb / s (-5.19%)
 (5) 14: 50: 30.4640 - 0.00Mb - 100% - 0.01Mb / s (-12690.64%)
 (6) 14: 50: 30.5390 - 0.00Mb - 100% - 0.01Mb / s (-12845.38%)
 (7) 14: 50: 30.8380 - 0.00Mb - 100% - 0.01Mb / s (-13909.70%)
 (8) 14: 50: 30.6150 - 0.00Mb - 100% - 0.01Mb / s (-12988.80%)
 (9) 14: 50: 30.9210 - 0.00Mb - 100% - 0.01Mb / s (-14079.53%)

Can I change this restriction to simulate more concurrent users?

+4
source share
3 answers

Do you run all 10 from one machine? Check the event log. When you add other things that may contain a connection, you can use the 10 connection restrictions for TCP / IP imposed on XP and above.

+1
source

One of the reasons may be that your server (ASP.NET with the extension .ashx), where you download files only from 4 Request parallel processes.

You can change this in the web.config file.

+2
source

You need to increase the maximum server connections in the configuration file

 <system.net> <connectionManagement> <add address="*" maxconnection="100" /> </connectionManagement> </system.net> 
+2
source

All Articles