I want to use multi threaded web requests but i am not getting the performance I expect.
i am running with computer with 4 cores, with 1 Gbps of upload and 1 Gbps of download.
For the test i am downloading the google main page.
the size of the data from the google page is ~50 KB.
I am sending 1000 requests simultaneously and I except to complete all requests within ~2 seconds but it takes more than 20 seconds to complete
my code looks like this:
bool success = ThreadPool.SetMinThreads(workerThreads: 2000, completionPortThreads: 1000);
success = ThreadPool.SetMaxThreads(2000, 2000);
DateTime dt = DateTime.UtcNow;
Parallel.For(0, 1000, (num) =>
{
string url = "https://www.google.co.il/?gfe_rd=cr&dcr=0&ei=OZy3WcmoMY7b8Affj4F4&gws_rd=ssl";
using (WebClient web = new WebClient())
{
byte[] bytes = web.DownloadData(url);
}
}
);
double sec = (DateTime.UtcNow - dt).TotalSeconds;
Console.WriteLine(sec);