コード例 #1
0
        public void Handle(TcpMessage.TcpSend message)
        {
            var start = _watch.ElapsedTicks;

            message.ConnectionManager.SendMessage(message.Message);
            HistogramService.SetValue(_tcpSendHistogram,
                                      (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
        }
コード例 #2
0
        public void Handle(HttpMessage.HttpSend message)
        {
            var deniedToHandle = message.Message as HttpMessage.DeniedToHandle;

            if (deniedToHandle != null)
            {
                int code;
                switch (deniedToHandle.Reason)
                {
                case DenialReason.ServerTooBusy:
                    code = HttpStatusCode.ServiceUnavailable;
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }

                var start = _watch.ElapsedTicks;
                message.HttpEntityManager.ReplyStatus(
                    code,
                    deniedToHandle.Details,
                    exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                     message.Message, exc.Message));
                HistogramService.SetValue(_httpSendHistogram,
                                          (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
            }
            else
            {
                var response = message.Data;
                var config   = message.Configuration;
                var start    = _watch.ElapsedTicks;
                if (response is byte[])
                {
                    message.HttpEntityManager.ReplyContent(
                        response as byte[],
                        config.Code,
                        config.Description,
                        config.ContentType,
                        config.Headers,
                        exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                         message.Message, exc.Message));
                }
                else
                {
                    message.HttpEntityManager.ReplyTextContent(
                        response as string,
                        config.Code,
                        config.Description,
                        config.ContentType,
                        config.Headers,
                        exc => Log.Debug("Error occurred while replying to HTTP with message {message}: {e}.",
                                         message.Message, exc.Message));
                }

                HistogramService.SetValue(_httpSendHistogram,
                                          (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
            }
        }
コード例 #3
0
        public void Handle(StorageMessage.RequestCompleted message)
        {
            Stopwatch watch = null;

            if (_currentTimedRequests.TryGetValue(message.CorrelationId, out watch))
            {
                HistogramService.SetValue(_requestManagerHistogram,
                                          (long)((((double)watch.ElapsedTicks) / Stopwatch.Frequency) * 1000000000));
                _currentTimedRequests.Remove(message.CorrelationId);
            }
            if (!_currentRequests.Remove(message.CorrelationId))
            {
                throw new InvalidOperationException("Should never complete request twice.");
            }
        }
コード例 #4
0
ファイル: StorageChaser.cs プロジェクト: ylorph/EventStore
        private void ChaserIteration()
        {
            _queueStats.EnterBusy();

            _flushSignal.Reset(); // Reset the flush signal just before a read to reduce pointless reads from [flush flush read] patterns.

            var result = _chaser.TryReadNext();

            if (result.Success)
            {
                _queueStats.ProcessingStarted(result.LogRecord.GetType(), 0);
                ProcessLogRecord(result);
                _queueStats.ProcessingEnded(1);
            }

            var start = _watch.ElapsedTicks;

            if (!result.Success || start - _lastFlush >= _flushDelay + MinFlushDelay)
            {
                _queueStats.ProcessingStarted <ChaserCheckpointFlush>(0);
                var startflush = _watch.ElapsedTicks;
                _chaser.Flush();
                HistogramService.SetValue(_chaserFlushHistogram,
                                          (long)((((double)_watch.ElapsedTicks - startflush) / Stopwatch.Frequency) * 1000000000));
                _queueStats.ProcessingEnded(1);

                var end = _watch.ElapsedTicks;
                _flushDelay = end - start;
                _lastFlush  = end;
            }

            if (!result.Success)
            {
                _queueStats.EnterIdle();
                var startwait = _watch.ElapsedTicks;
#if MONO
                _flushSignal.WaitOne(FlushWaitTimeout);
#else
                _flushSignal.Wait(FlushWaitTimeout);
#endif
                HistogramService.SetValue(_chaserWaitHistogram,
                                          (long)((((double)_watch.ElapsedTicks - startwait) / Stopwatch.Frequency) * 1000000000));
            }
        }
コード例 #5
0
        protected bool Flush(bool force = false)
        {
            var start = _watch.ElapsedTicks;

            if (force || FlushMessagesInQueue == 0 || start - _lastFlushTimestamp >= _lastFlushDelay + _minFlushDelay)
            {
                var flushSize = Writer.Checkpoint.ReadNonFlushed() - Writer.Checkpoint.Read();

                Writer.Flush();
                HistogramService.SetValue(_writerFlushHistogram,
                                          (long)((((double)_watch.ElapsedTicks - start) / Stopwatch.Frequency) * 1000000000));
                var end        = _watch.ElapsedTicks;
                var flushDelay = end - start;
                Interlocked.Exchange(ref _lastFlushDelay, flushDelay);
                Interlocked.Exchange(ref _lastFlushSize, flushSize);
                _lastFlushTimestamp = end;

                if (_statCount >= LastStatsCount)
                {
                    Interlocked.Add(ref _sumFlushSize, -_lastFlushSizes[_statIndex]);
                    Interlocked.Add(ref _sumFlushDelay, -_lastFlushDelays[_statIndex]);
                }
                else
                {
                    _statCount += 1;
                }

                _lastFlushSizes[_statIndex]  = flushSize;
                _lastFlushDelays[_statIndex] = flushDelay;
                Interlocked.Add(ref _sumFlushSize, flushSize);
                Interlocked.Add(ref _sumFlushDelay, flushDelay);
                Interlocked.Exchange(ref _maxFlushSize, Math.Max(Interlocked.Read(ref _maxFlushSize), flushSize));
                Interlocked.Exchange(ref _maxFlushDelay, Math.Max(Interlocked.Read(ref _maxFlushDelay), flushDelay));
                _statIndex = (_statIndex + 1) & (LastStatsCount - 1);

                PurgeNotProcessedInfo();
                Bus.Publish(new ReplicationTrackingMessage.WriterCheckpointFlushed());
                return(true);
            }

            return(false);
        }
コード例 #6
0
ファイル: StorageChaser.cs プロジェクト: vebin/EventStore
        private void ChaserIteration()
        {
            _queueStats.EnterBusy();
            var result = _chaser.TryReadNext();

            if (result.Success)
            {
                _queueStats.ProcessingStarted(result.LogRecord.GetType(), 0);
                ProcessLogRecord(result);
                _queueStats.ProcessingEnded(1);
            }

            var start = _watch.ElapsedTicks;

            if (!result.Success || start - _lastFlush >= _flushDelay + MinFlushDelay)
            {
                _queueStats.ProcessingStarted <ChaserCheckpointFlush>(0);
                _chaser.Flush();
                var startflush = _watch.ElapsedTicks;
                HistogramService.SetValue(_chaserFlushHistogram,
                                          (long)((((double)_watch.ElapsedTicks - startflush) / Stopwatch.Frequency) * 1000000000));
                _queueStats.ProcessingEnded(1);

                var end = _watch.ElapsedTicks;
                _flushDelay = end - start;
                _lastFlush  = end;
            }

            if (!result.Success)
            {
                _queueStats.EnterIdle();
                //Thread.Sleep(1);
                var startwait = _watch.ElapsedTicks;
                _writerCheckpoint.WaitForFlush(FlushWaitTimeout);
                HistogramService.SetValue(_chaserWaitHistogram,
                                          (long)((((double)_watch.ElapsedTicks - startwait) / Stopwatch.Frequency) * 1000000000));
            }
        }