Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it safe to leave MiniProfiler's ProfiledDbConnection in production code?

Given that MiniProfiler isnt actually running for non-local requests due to the following:

    protected void Application_BeginRequest()
    {
        if (Request.IsLocal)
            MiniProfiler.Start();
    }

Is it still okay then (performance-wise) to leave the use of ProfiledDbConnection in production code?

var db = new MyDataContext(new StackExchange.Profiling.Data.ProfiledDbConnection(new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString), MiniProfiler.Current))
like image 435
Jimbo Avatar asked Oct 22 '25 04:10

Jimbo


1 Answers

In short: yes.

Every page on Stack Overflow is running it, so that connection sees something like a hundred billion uses a month just here (and we're at ~2-4% CPU load at peak traffic). It's meant to be extremely low overhead and safe for production code. Compared to the trip off-box you're about to take to query SQL, Redis, etc. - the profiling bits are very minimal.

I strive to keep it small because our primary use case is Stack Overflow scale and load. The only likely way it is problematic would be to unboundedly store profiles for a large number of requests. They have to eat storage somewhere and that might be an issue at scale.

For Stack Overflow: we're profiling all requests and storing the slow ones, for further analysis and to keep an eye on problematic routes. So not only is profiled db connection present, it's profiling, on all requests here. I'm not trying to brag on numbers, only provide a hopefully compelling use case for: it's fine, we're slamming it hard and have a vested interest in keeping it low-overhead.

like image 70
Nick Craver Avatar answered Oct 23 '25 18:10

Nick Craver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!