Poor WebAPI performance
Asked Answered
D

1

7

I recently converted our existing ASP.NET MVC 2 application to MVC 4 with a WebAPI backend. Unfortunately though, I have been noticing some severe performance issues in regards to WebAPI.

I have MiniProfiler setup and added some steps to see if I could identify the bottleneck, and to my surprise, it is not the database. Before the conversion, a request like this would take no more than ~50ms, so seeing these simple requests take upwards of 2 seconds is a bit shocking.

enter image description here

The odd part is that all of this is that the majority of the latency occurs before the request even makes it to the SQL calls itself.

I was wondering if there was a known way to more deeply tie MiniProfiler into WebAPI's calls to further inspect what is actually going on here. Any assistance would be greatly appreciated.

FWIW, here is the code being used for this request

WebAPI Controller:

[HttpGet]
public bool AssetExistsById(string assetId) {
    using (Current.Profiler.Step("WebAPI Call To Model")) {
        return Asset.AssetExists(assetId);
    }
}

Asset Model:

public static bool AssetExists(string assetId) {
    using (Current.Profiler.Step("WCF call to DataAccess lib")) {
        return WcfEndPoint.AssetExists(assetId);
    }
}

Thanks!

Update

So I found out what was going on here... It turns out that I had System Diagnostics Tracing enabled in my App_Start/WebApiConfig.cs file. I randomly commented out the following line, and everything was fixed.

config.EnableSystemDiagnosticsTracing();

I hope this helps others!

Dumpy answered 16/4, 2013 at 17:36 Comment(6)
Have you tried taking a VS profile to figure out what's taking so much time?Smaltite
Do you have any static pages/images inside the web application to test the load times? It may be network/server related.Parachronism
@YoussefMoussaoui Thanks for the response! I actually spun up the profiler but didn't find anything particularly interesting as to why my requests were taking so long... The longest part was routing the request but even that was relatively short. Perhaps I am using the wrong profiler? I'm using VS2012 if that helps.Dumpy
@DmitryStarosta Interesting thought. I have a very client-side heavy application with many, many js files. Perhaps if I run this in prod and minify everything I'll see a difference...Dumpy
@Jaysche Youssef is talking about Visual Studio Profiler, not MvcMiniProfiler. Can you reproduce the issue ? Have you tested Asset.AssetExists without WebApi ?Judie
Found out the problem, gang. I updated my post with the solution. Thanks for your helps, everyone!Dumpy
D
7

So I found out what was going on here... It turns out that I had System Diagnostics Tracing enabled in my App_Start/WebApiConfig.cs file. I randomly commented out the following line, and everything was fixed.

config.EnableSystemDiagnosticsTracing();

I hope this helps others!

Dumpy answered 4/6, 2013 at 20:19 Comment(4)
I wish I had seen this 4 hours ago! I had this exact problem, and found the solution the exact same way. :) Interestingly, we only saw the performance hit when deploying to Azure. When running locally, the application seemed fine.Parabolize
Yeah I had actually messed around with different diagnostic runners again a few weeks ago and noticed no latency issues this time around. Interesting that you only saw issues after deploying to Azure though! Possibly an issue with using diagnostics tracing when running Release vs Debug?Dumpy
The Azure instance I mentioned is a destination for continuous deployment and integration testing. It is running a debug version of the build.Parabolize
Same here, nearly five years after this post was made. +1!Squish

© 2022 - 2024 — McMap. All rights reserved.