title: Tracking Concurrent Web Service Requests with Timestamps
body: <p>I have an ASP.NET 4.0 Web Service that accepts transmission of XML files.  In the past (with a different implementation of the same web service) we have tracked the concurrency (# of XML files being received/processed at the same time) using timestamps.  I have replicated this behavior in the new version of the web service as such:</p>
  
  <p>In the constructor for the Web Service class I record <code>ConnectionStartTime</code> using <code>HttpContext.Current.Timestamp</code></p>
  
  <pre><code>public class MyWebService : System.Web.Services.WebService
  {
    public MyWebService()
    {
      ConnectionStartTime = HttpContext.Current.Timestamp
    }
  }
  </code></pre>
  
  <p>After I'm done processing the XML file within the <code>WebMethod</code> I insert the file into a database (recording <code>ConnectionEndTime</code>) and return the response to the user.  I execute the database insert in a new <code>Thread</code> so the end user doesn't have to wait for the insert to occur to receive their response.</p>
  
  <pre><code>new Thread (() =&gt;
    {
      insertIntoDatabase(ConnectionStartTime, ConnectionEndTime=Datetime.Now, xmlFile);
    }).Start();
  return responseToUser;
  </code></pre>
  
  <p>Now I'm trying to gauge how many concurrent XML transmissions we've reached with two methods:</p>
  
  <p><strong>1. Performance Counters</strong></p>
  
  <ul>
  <li>ASP.NET Apps v4.0\Requests Executing - This counter peaked at 52.</li>
  <li>ASP.NET Apps v4.0\Requests Queued - This counter peaked at 19.</li>
  </ul>
  
  <p>To me this means I should see a point where we have 33 records with overlapping <code>ConnectionStartTime</code> and <code>ConnectionEndTime</code>.  </p>
  
  <p><strong>2. Querying Against Timestamps</strong>
   - In <a href="https://stackoverflow.com/q/5828264/100776">this question</a> I reference the query I'm using to calculate the number of concurrent transmissions based on <code>ConnectionStartTime</code> and <code>ConnectionEndTime</code>.  These are <code>datetime</code> fields in a SQL Server database.  <strong>Note:</strong> The query in that question is a reworked version of the algorithm we've been using for the past 3 years to determine concurrency so it may not be 100% correct but the other implementations of the algorithm (Excel macros, etc) have been validated.</p>
  
  <p>My problem is that the two methods never align.  The maximum results from querying the timestamps hit 10 while the performance counters suggested the maximum should be 30+. I'm having a hard time locating where the discrepancy is.  Am I making a mistake in how I'm recording my timestamps?  Does the <code>HttpContext.Current.Timestamp</code> value not record the beginning of a transmission to the web service?  </p>