title: Measure performance of ASP.NET SQL session state provider
body: <p>We have a very large three-tier .NET 4.0 web application (ASP.NET, WCF, SQL Server 2008 R2) with some performance issues I'm trying to diagnose.  The ASP.NET tier uses the SQL session state provider, and there is reasonably extensive use of session state.   </p>
  
  <pre><code>&lt;sessionState mode="SQLServer" sqlConnectionString="..." cookieless="false" timeout="20"/&gt;
  </code></pre>
  
  <p>I'm trying to figure out how much time it takes to load and save the session to the database. Note that this is different than using SQL profiler or other database means to measure time on that tier; I want to measure <strong>total time taken from the ASP.NET tier.</strong>  I.e. that would include session object serialization/deserialization, wire time, and SQL save/load time.  </p>
  
  <p>I am pretty experienced developer (since the early 80's), and I have Googled the web for <em>hours</em> now -- there are tons of articles contrasting session state approaches and general performance concepts etc, but I can find nothing on how to actually measure this total time for the SQL session state provider.  I initially thought of using an HttpModule to hook events and use a stopwatch, but there doesn't appear to be a clean path to this. (I would settle for an approach that's <em>reasonably</em> accurate to few percent...)  </p>
  
  <p>Any ideas/suggestions are much appreciated, thanks.</p>