/// <summary> /// Creates a buffer pool. /// </summary> /// <param name="bufferSize">The size, in bytes, of each buffer.</param> /// <param name="maxBuffers">The maximum number of buffers to keep around, unused; by default, the number of unused buffers is unbounded.</param> private BufferPool(int bufferSize, int maxBuffers, int preallocationSize, string name) { Name = name; byteBufferSize = bufferSize; buffers = maxBuffers <= 0 ? new BlockingCollection <byte[]>() : new BlockingCollection <byte[]>(maxBuffers); var globalPoolSizeStat = IntValueStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_BUFFERS_INPOOL, () => Count); allocatedBufferCounter = CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_ALLOCATED_BUFFERS); checkedOutBufferCounter = CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_CHECKED_OUT_BUFFERS); checkedInBufferCounter = CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_CHECKED_IN_BUFFERS); droppedBufferCounter = CounterStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_CHECKED_IN_DROPPED_BUFFERS); // Those 2 counters should be equal. If not, it means we don't release all buffers. IntValueStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_INUSE_CHECKED_OUT_NOT_CHECKED_IN_BUFFERS, () => checkedOutBufferCounter.GetCurrentValue() - checkedInBufferCounter.GetCurrentValue() - droppedBufferCounter.GetCurrentValue()); IntValueStatistic.FindOrCreate(StatisticNames.SERIALIZATION_BUFFERPOOL_INUSE_ALLOCATED_NOT_INPOOL_BUFFERS, () => allocatedBufferCounter.GetCurrentValue() - globalPoolSizeStat.GetCurrentValue() - droppedBufferCounter.GetCurrentValue()); if (preallocationSize <= 0) { return; } var dummy = GetMultiBuffer(preallocationSize * Size); Release(dummy); }
internal static void Init(TimeSpan responseTimeout) { if (!StatisticsCollector.CollectApplicationRequestsStats) { return; } const CounterStorage storage = CounterStorage.LogAndTable; appRequestsLatencyHistogram = ExponentialHistogramValueStatistic.Create_ExponentialHistogram_ForTiming( StatisticNames.APP_REQUESTS_LATENCY_HISTOGRAM, NUM_APP_REQUESTS_EXP_LATENCY_HISTOGRAM_CATEGORIES); timedOutRequests = CounterStatistic.FindOrCreate(StatisticNames.APP_REQUESTS_TIMED_OUT, storage); totalAppRequests = CounterStatistic.FindOrCreate(StatisticNames.APP_REQUESTS_TOTAL_NUMBER_OF_REQUESTS, storage); appRequestsTotalLatency = CounterStatistic.FindOrCreate(StatisticNames.APP_REQUESTS_LATENCY_TOTAL, false, storage, true); appRequestsAverageLatency = FloatValueStatistic.FindOrCreate( StatisticNames.APP_REQUESTS_LATENCY_AVERAGE, () => { long totalLatencyInTicks = appRequestsTotalLatency.GetCurrentValue(); if (totalLatencyInTicks == 0) { return(0); } long numReqs = totalAppRequests.GetCurrentValue(); long averageLatencyInTicks = (long)((double)totalLatencyInTicks / (double)numReqs); return((float)Utils.TicksToMilliSeconds(averageLatencyInTicks)); }, storage); }
public TimeSpan GetCurrentValue() { long sampleCount, tickCount; lock (instanceLock) { sampleCount = sampleCounter.GetCurrentValue(); tickCount = tickAccum.GetCurrentValue(); } return(sampleCount == 0 ? TimeSpan.Zero : TimeSpan.FromTicks(tickCount / sampleCount)); }
public QueueTrackingStatistic(string queueName) { if (StatisticsCollector.CollectQueueStats) { const CounterStorage storage = CounterStorage.LogAndTable; averageQueueSizeCounter = AverageValueStatistic.FindOrCreate( new StatisticName(StatisticNames.QUEUES_QUEUE_SIZE_AVERAGE_PER_QUEUE, queueName), storage); numEnqueuedRequestsCounter = CounterStatistic.FindOrCreate( new StatisticName(StatisticNames.QUEUES_ENQUEUED_PER_QUEUE, queueName), false, storage); if (TrackExtraStats) { totalExecutionTime = TimeIntervalFactory.CreateTimeInterval(true); averageArrivalRate = FloatValueStatistic.FindOrCreate( new StatisticName(StatisticNames.QUEUES_AVERAGE_ARRIVAL_RATE_PER_QUEUE, queueName), () => { TimeSpan totalTime = totalExecutionTime.Elapsed; if (totalTime.Ticks == 0) { return(0); } long numReqs = numEnqueuedRequestsCounter.GetCurrentValue(); return((float)((((double)numReqs * (double)TimeSpan.TicksPerSecond)) / (double)totalTime.Ticks)); }, storage); } averageTimeInQueue = AverageValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_TIME_IN_QUEUE_AVERAGE_MILLIS_PER_QUEUE, queueName), storage); averageTimeInQueue.AddValueConverter(Utils.AverageTicksToMilliSeconds); if (averageTimeInAllQueues == null) { averageTimeInAllQueues = AverageValueStatistic.FindOrCreate(new StatisticName(StatisticNames.QUEUES_TIME_IN_QUEUE_AVERAGE_MILLIS_PER_QUEUE, "AllQueues"), storage); averageTimeInAllQueues.AddValueConverter(Utils.AverageTicksToMilliSeconds); } if (totalTimeInAllQueues == null) { totalTimeInAllQueues = CounterStatistic.FindOrCreate( new StatisticName(StatisticNames.QUEUES_TIME_IN_QUEUE_TOTAL_MILLIS_PER_QUEUE, "AllQueues"), false, storage); totalTimeInAllQueues.AddValueConverter(Utils.TicksToMilliSeconds); } } }