I have hosted a WebAPI (using latest version) in my VM (has .net framework 4.5.2, Windows Server 2012 R2 with all updates).
WebAPI code returns RSS feed from my Blog (external public URL).
Here is the code for same.
I am using this to Cache WebAPI Output.
[AllowAnonymous]
[CacheOutput(ServerTimeSpan = 9000, ExcludeQueryStringFromCacheKey = false)]
[HttpGet]
public async Task<HttpResponseMessage> GetRecentPost(string type)
{
string responseFromServer;
WebRequest request = null;
request = WebRequest.Create("My_EXTERNAL_BLOG_URL_HERE");
using (var response = await request.GetResponseAsync())
{
using (var dataStream = response.GetResponseStream())
{
using (var reader = new StreamReader(dataStream))
{
responseFromServer = await reader.ReadToEndAsync();
}
}
}
return new HttpResponseMessage() { Content = new StringContent(responseFromServer, Encoding.UTF8, ContentType) };
}
I can see from IIS that few requests stay for very long time.
What can be the reason ? Secondly, I see that the app serves around 300 requests per min. Is it a good practice to have async-await in above code ?