Example #1
0
        public void LogConnectionEndedNormally(Socket s, RequestInfo req)
        {
            try
            {
                var now = Now;

                TimeSpan requestTime;
                lock (connectionReceivedLock)
                {
                    ConcurrentConnectionsNow--;

                    // Stop the watch
                    requestTime = StopConnectionTimer(s);
                }

                if (req.ResponseStatusCode != 200 && req.ResponseStatusCode != 301)
                {
                    return;
                }

                // Look for the times with our method
                // We could do with a global lock here, but that just sounds so bad.
                // Instead, we try to avoid a global lock as much as possible, and count on another method
                // to give us a finer grained lock.
                LinkedList <RequestTimes> timesForEndpoint = null; // Incompatibility
                lock (CreateAndReturnRelativePathLock(req.RelativePath, out timesForEndpoint))
                {
                    var verbTimes = timesForEndpoint.FirstOrDefault(t => t.HttpMethod == req.HttpMethod);
                    if (verbTimes == null)
                    {
                        // First request to this endpoint with this method. Add it.
                        verbTimes = new RequestTimes(req.HttpMethod, req.RelativePath, requestTime);
                        timesForEndpoint.AddLast(verbTimes);
                    }
                    else
                    {
                        // Just update the times
                        if (verbTimes.MinimumTime > requestTime)
                        {
                            verbTimes.MinimumTime = requestTime;
                        }
                        if (verbTimes.MaximumTime < requestTime)
                        {
                            verbTimes.MaximumTime = requestTime;
                        }

                        verbTimes.AverageTime = new TimeSpan((verbTimes.NumRequests * verbTimes.AverageTime.Ticks + requestTime.Ticks) / (verbTimes.NumRequests + 1));
                        verbTimes.NumRequests++;
                    }
                }
            }
            catch
            {
            }
        }
Example #2
0
        public void LogConnectionEndedNormally(Socket s, RequestInfo req)
        {
            try
            {
                var now = Now;

                TimeSpan requestTime;
                lock (connectionReceivedLock)
                {
                    ConcurrentConnectionsNow--;

                    // Stop the watch
                    requestTime = StopConnectionTimer(s);
                }

                if (req.ResponseStatusCode != 200 && req.ResponseStatusCode != 301)
                    return;

                // Look for the times with our method
                // We could do with a global lock here, but that just sounds so bad.
                // Instead, we try to avoid a global lock as much as possible, and count on another method
                // to give us a finer grained lock.
                LinkedList<RequestTimes> timesForEndpoint;
                lock (CreateAndReturnRelativePathLock(req.RelativePath, out timesForEndpoint))
                {
                    var verbTimes = timesForEndpoint.FirstOrDefault(t => t.HttpMethod == req.HttpMethod);
                    if (verbTimes == null)
                    {
                        // First request to this endpoint with this method. Add it.
                        verbTimes = new RequestTimes(req.HttpMethod, req.RelativePath, requestTime);
                        timesForEndpoint.AddLast(verbTimes);
                    }
                    else
                    {
                        // Just update the times
                        if (verbTimes.MinimumTime > requestTime)
                            verbTimes.MinimumTime = requestTime;
                        if (verbTimes.MaximumTime < requestTime)
                            verbTimes.MaximumTime = requestTime;

                        verbTimes.AverageTime = new TimeSpan((verbTimes.NumRequests * verbTimes.AverageTime.Ticks + requestTime.Ticks) / (verbTimes.NumRequests + 1));
                        verbTimes.NumRequests++;
                    }
                }
            }
            catch
            {
            }
        }