bad performance for the code to send Http request
Hi guys,
I am new to Http in C#. Here is my code segment. My performance test result is 1st time it takes long time, almost 30 seconds, and from the 2nd time to the 10th time, it takes very little time (expected).
TestBlade is a machine which is located in local LAN. I have tried with IE, very quick response each time.
Code:
Uri server = new Uri("http://TestBlade:8080/monitor");
WebClient myWebClient = new WebClient();
// open file to read
byte[] returnRawBytes;
int counter = 10;
try
{
Console.WriteLine("Testing TestBlade performance... ");
while (counter > 0)
{
// post data
Console.WriteLine("Round " + counter + " Begin time: " + DateTime.Now);
returnRawBytes = myWebClient.UploadData(server.AbsoluteUri, System.Text.Encoding.ASCII.GetBytes("Hello server"));
Console.WriteLine(System.Text.Encoding.ASCII.GetString(returnRawBytes));
Console.WriteLine("Round " + counter + " Complete time: " + DateTime.Now);
Thread.Sleep (10000);
counter--;
}
}
catch (Exception e) // get any other error
{
Console.WriteLine(e.ToString());
throw;
}
Any ideas why 1st time is so slow?