My scenario is:
I've 20 servers:
\\server1.com
\\server2.com
\\server3.com
...
\\server20.com
My application need access the "best" server. "The best" means the one with the smallest response time.
How I can check this response time in C#?
You can calculate response time using HttpWebRequest
and HttpWebResponse
.
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(myUri);
System.Diagnostics.Stopwatch timer = new Stopwatch();
timer.Start();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
response.Close();
timer.Stop();
TimeSpan timeTaken = timer.Elapsed;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.