1

Question on logging and performance measurement best practices.

When trying to do performance logging, I've discovered that there is a timing delay if you start your timer at OnActionExecuting vs Application_BeginRequest. It was off by 40% in some cases, which is significant (This is with MVC 4 Web API). I'm looking for best practices as far as insertion points of various monitoring code, including performance monitoring, and a good place at which to write the log at the end.

A framework like MiniProfiler (http://miniprofiler.com/) instructs people to use Application_BeginRequest and Applicaiton_EndRequest, but this is deemed as "ugly" by some professionals in the forums (PS Why?).

Is there a non-ugly way to accurately get the full timing of a request? Thanks.

I have seen the following suggested:

  • Application_BeginRequest
  • OnActionExecuting (ActionFilter)
  • OnAuthorization (ActionFilter)
  • HttpModule with an edit in Web.config as described here
  • DelegatingHandler (Web API audit logging)

Perhaps DelegatingHandler is the best one I have seen suggested, as it takes place before routing. My only concern is that a lot of official Microsoft blogs and pros have recommended the ActionFilters instead, so perhaps I'm missing something here.

Currently I'm using Application_BeginRequest (because its easy) to start the counter and am modifying a global variable if a real route was found at OnActionExecuting. Back at Application_EndRequest I check if a route was found and then log accordingly, not logging other http requests like "/favicon.ico" which apparently show up at Applicaiton_BeginRequest.

Community
  • 1
  • 1
Dmitri R117
  • 2,502
  • 23
  • 20

1 Answers1

1

I think there are many ways to get what you want. Personally, i'm a fan of MiniProfiler for EF query logging.

For performance logging, i use an ActionAttribute / Filter, because it's the "MVC" way and can easily be inserted through the entire application ( or on Controllers / methods only, depending on what you want). HttpModules are more the Asp.Net way.

None the less, i haven't seen a "perfect" solution, there is a serious performance difference/issue when the application is compiling, which doesn't get tracked.

You could dive into IIS Logging for more "trustworthy" solutions http://www.iis.net/learn/extensions/configuring-application-request-routing-(arr)/using-performance-counters .

Tip: Log Parser is a great way to parse your ugly IIS logs :) --> http://www.microsoft.com/en-us/download/details.aspx?id=24659 and a GUI for it --> http://www.lizard-labs.com/log_parser_lizard.aspx

Just a thought though. I have been in the same situation and just used ActionFilters. It isn't "exact", but it gives a good enough estimation of what the slowest methods are.

NicoJuicy
  • 3,435
  • 4
  • 40
  • 66