8

We installed miniprofiler. It has been an edifying experience, but now we see that our database queries run 3x as fast with the profiler enabled as with it disabled.

The only code we changed in our app was to add the profiledDbConnection:

public static DbConnection GetOpenConnection(string connectionString)
{
    var cnn = new System.Data.SqlClient.SqlConnection(connectionString);  
    // wrap the connection with a profiling connection that tracks timings 
    return MvcMiniProfiler.Data.ProfiledDbConnection.Get(cnn, MiniProfiler.Current);
}

Linq2Sql is suddenly...fast.

I'm not complaining, but why is this happening?

Code Silverback
  • 3,204
  • 5
  • 32
  • 39
  • 2
    The only thing that springs to mind would be that perhaps adding the ProfiledDbConnection has caused the query to return cached items, but that's a total guess... – chrisfrancis27 Jun 27 '11 at 22:15
  • 4
    there is nothing we do to accelerate performance, the expectation is that performance will be ever so slightly slower when profiling is enabled. Since this hit only affects a fraction of the users (developers) it is acceptable. – Sam Saffron Jun 28 '11 at 12:27
  • Which is what I expected...but that's not what we are observing. I, for one, am baffled. – Code Silverback Jun 28 '11 at 13:14
  • 6
    It runs *faster*? Wow, this profiler **is** pretty great, isn't it? – Brant Bobby Jun 28 '11 at 19:01
  • I'm experiencing the exact opposite. I'm using EF and it adds around 300ms to most Linq statements. Issue here: http://stackoverflow.com/questions/6439827/slow-ef-profiling-performance-with-mvc-mini-profiler – WVDominick Jun 29 '11 at 12:04

1 Answers1

5

What do you mean by 'database queries run 3x faster'?

  1. If you run SQL Profiler - do you see that the db execution time is 3 times lower?
  2. The time to execute a high level method in your code that eventually queries database is 3 time lower?

If it is case 1 than the difference will be in the SQL generated - compare both statements. If it is case 2 than run a C# profiler (Ants, dotTrace) and compare execution time of all the methods.

Difference of this magnitude will be related to a totally different path of execution - maybe you're not doing a heavy loop or you're getting data from cache.

First of all you can verify if you are hitting database at all and the number of queries is exactly the same.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126