Exemplo n.º 1
0
        static RequestModule()
        {
            _config           = ServiceLocator.Current.Resolve <IConfigurationModule>();
            _statisticsModule = ServiceLocator.Current.Resolve <IDomainStatisticsModule>();

            _handlers = Enumerable.Range(0, Environment.ProcessorCount * 2).Select(i => new RequestThread(i)).ToArray();

            _requestSlots     = Enumerable.Range(1, 5).Select(i => new RequestSlot(_handlers.Length)).ToArray();
            _currentSlotIndex = 0;
            _currentSlot      = _requestSlots[_currentSlotIndex];
            _timeLine         = DateTime.Now.AddSeconds(_config.CoreDelay / 5.0);
            _statsTimer       = new Timer(CountStats, null, 0, 100);
        }
Exemplo n.º 2
0
        private static void CountStats(object o)
        {
            if (DateTime.Now >= _timeLine)
            {
                _timeLine = _timeLine.AddSeconds(_config.CoreDelay / 5.0);

                if (DateTime.Now >= _timeLine)
                {
                    if (++_failCount > 5)
                    {
                        _config.CoreDelay *= 2;
                        _failCount         = 0;
                    }
                }
                else
                {
                    _failCount = 0;
                }

                var slot = _requestSlots[_currentSlotIndex];
                if (_currentSlotIndex >= _requestSlots.Length - 1)
                {
                    _currentSlotIndex = 0;
                }
                else
                {
                    _currentSlotIndex++;
                }
                _currentSlot = _requestSlots[_currentSlotIndex];

                slot.Reset();
                var stats = new Dictionary <Guid, DomainStatistics>();
                _requestSlots.Each(i => i.Count(stats));

                foreach (var statItem in stats.Values)
                {
                    var selector  = (IPageSelector)statItem;
                    var statCount = new DomainStatisticsData(statItem);
                    if (selector.SelectorType == (int)PageSelectorType.DomainPattern)
                    {
                        _statisticsModule.SetDomainStatistics(new DomainSelector(DomainSelector.TotalDomain, selector.Id), statCount);
                    }
                    _statisticsModule.SetDomainStatistics(selector, statCount);
                }
            }
        }