简体   繁体   中英

Windows Phone HttpClient GetAsync performance

I'm working with twitch REST API for education purposes(MVVM pattern) on Windows Phone platform. I noticed pure performance while using HttpClient:

  1. I get a collection of 10 elements
  2. Pass it to CheckCannelStreamStatus

I removed the code because it was draft for prototype.

Like in the answer bellow the problem is in the HttpClient.GetAsync that resulted in ~671ms execution time.

This has nothing to do with the "performance" of HttpClient . The reason for this is rather that you're going 10 times to a server to get back some information. That'll be ~768ms per request, which sounds reasonable given some latency. There's little the HttpClient can do about latency and server response times.

To verify this is the case, I suggest you pop up Fiddler or a similar tool to make sure the response time is the offender. You could also wrap both client.GetAsync and response.Content.ReadAsAsync<TwitchStream>() in separate stopwatches and verify that the serialization is not the root cause here.

To decrease the time it takes to get all the needed information, I'd suggest you look into executing the HTTP requests in parallel. HttpClient is designed to be both reused both for multiple calls, and across multiple threads. So reusing a single instance and executing multiple requests in parallel, using something like Task.WhenAll or similar, will make it perform better.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM