I have to send 100,000 http requests every few seconds and with the code provided below it takes 19 seconds to send the requests and its longer than my interval.
During this time the CPU usage and Ethernet usage is 100% . I have tried it in a dual processor computer with a higher band width but the same result.
Is there any other way to have a better performance.
protected async void btnStartCallWhenAll_Click(object sender, EventArgs e)
{
t1 = DateTime.Now;
// Make a list of web addresses.
List<string> urlList = SetUpURLList(Convert.ToInt32(txtNoRecordsToAdd.Text));
// One-step async call.
await ProcessAllURLSAsync(urlList);
t2 = DateTime.Now;
double spent = t2.Subtract(t1).TotalMilliseconds;
txtTimeElapsed.Text = " Time Spent :" + spent.ToString() ;
}
private List<string> SetUpURLList(int No)
{
List<string> urls = new List<string>
{
};
for (int i = 1; i <= No; i++)
urls.Add("http://msdn.microsoft.com/library/windows/apps/br211380.aspx");
return urls;
}
private async Task ProcessAllURLSAsync(List<string> urlList)
{
ServicePointManager.UseNagleAlgorithm = true;
ServicePointManager.Expect100Continue = true;
ServicePointManager.CheckCertificateRevocationList = true;
ServicePointManager.MaxServicePointIdleTime = 10000;
ServicePointManager.DefaultConnectionLimit = 1000;
IEnumerable<Task> CallingTasksQuery =
from url in urlList select CallURLAsync(url);
Task[] CallingTasks = CallingTasksQuery.ToArray();
await Task.WhenAll(CallingTasks);
}
private async Task CallURLAsync(string url)
{
var content = new MemoryStream();
var webReq = (HttpWebRequest)WebRequest.Create(url);
using (WebResponse response = await webReq.GetResponseAsync())
{
}
}