internal WebEventBuffer(BufferedWebEventProvider provider, string bufferMode, WebEventBufferFlushCallback callback) { this._provider = provider; BufferModeSettings settings = RuntimeConfig.GetAppLKGConfig().HealthMonitoring.BufferModes[bufferMode]; if (settings == null) { throw new ConfigurationErrorsException(System.Web.SR.GetString("Health_mon_buffer_mode_not_found", new object[] { bufferMode })); } if (settings.RegularFlushInterval == TimeSpan.MaxValue) { this._regularFlushIntervalMs = Infinite; } else { try { this._regularFlushIntervalMs = (long)settings.RegularFlushInterval.TotalMilliseconds; } catch (OverflowException) { this._regularFlushIntervalMs = Infinite; } } if (settings.UrgentFlushInterval == TimeSpan.MaxValue) { this._urgentFlushIntervalMs = Infinite; } else { try { this._urgentFlushIntervalMs = (long)settings.UrgentFlushInterval.TotalMilliseconds; } catch (OverflowException) { this._urgentFlushIntervalMs = Infinite; } } this._urgentFlushThreshold = settings.UrgentFlushThreshold; this._maxBufferSize = settings.MaxBufferSize; this._maxFlushSize = settings.MaxFlushSize; this._maxBufferThreads = settings.MaxBufferThreads; this._burstWaitTimeMs = Math.Min(this._burstWaitTimeMs, this._urgentFlushIntervalMs); this._flushCallback = callback; this._buffer = new Queue(); if (this._regularFlushIntervalMs != Infinite) { this._startTime = DateTime.UtcNow; this._regularTimeoutUsed = true; this._urgentFlushScheduled = false; this.SetTimer(this.GetNextRegularFlushDueTimeInMs()); } }
internal WebEventBuffer(BufferedWebEventProvider provider, string bufferMode, WebEventBufferFlushCallback callback) { Debug.Assert(callback != null, "callback != null"); _provider = provider; HealthMonitoringSection section = RuntimeConfig.GetAppLKGConfig().HealthMonitoring; BufferModesCollection bufferModes = section.BufferModes; BufferModeSettings bufferModeInfo = bufferModes[bufferMode]; if (bufferModeInfo == null) { throw new ConfigurationErrorsException(SR.GetString(SR.Health_mon_buffer_mode_not_found, bufferMode)); } if (bufferModeInfo.RegularFlushInterval == TimeSpan.MaxValue) { _regularFlushIntervalMs = Infinite; } else { try { _regularFlushIntervalMs = (long)bufferModeInfo.RegularFlushInterval.TotalMilliseconds; } catch (OverflowException) { _regularFlushIntervalMs = Infinite; } } if (bufferModeInfo.UrgentFlushInterval == TimeSpan.MaxValue) { _urgentFlushIntervalMs = Infinite; } else { try { _urgentFlushIntervalMs = (long)bufferModeInfo.UrgentFlushInterval.TotalMilliseconds; } catch (OverflowException) { _urgentFlushIntervalMs = Infinite; } } _urgentFlushThreshold = bufferModeInfo.UrgentFlushThreshold; _maxBufferSize = bufferModeInfo.MaxBufferSize; _maxFlushSize = bufferModeInfo.MaxFlushSize; _maxBufferThreads = bufferModeInfo.MaxBufferThreads; _burstWaitTimeMs = Math.Min(_burstWaitTimeMs, _urgentFlushIntervalMs); _flushCallback = callback; _buffer = new Queue(); if (_regularFlushIntervalMs != Infinite) { _startTime = DateTime.UtcNow; _regularTimeoutUsed = true; _urgentFlushScheduled = false; SetTimer(GetNextRegularFlushDueTimeInMs()); } Debug.Trace("WebEventBuffer", "\n_regularFlushIntervalMs=" + _regularFlushIntervalMs + "\n_urgentFlushThreshold=" + _urgentFlushThreshold + "\n_maxBufferSize=" + _maxBufferSize + "\n_maxFlushSize=" + _maxFlushSize + "\n_urgentFlushIntervalMs=" + _urgentFlushIntervalMs); }
internal LowPhysicalMemoryMonitor() { /* * The chart below shows physical memory in megabytes, and the 1, 3, and 10% values. * * RAM 1% 3% 10% * ----------------------------- * 128 1.28 3.84 12.8 * 256 2.56 7.68 25.6 * 512 5.12 15.36 51.2 * 1024 10.24 30.72 102.4 * 2048 20.48 61.44 204.8 * 4096 40.96 122.88 409.6 * 8192 81.92 245.76 819.2 * * Low memory notifications from CreateMemoryResourceNotification are calculated as follows * (.\base\ntos\mm\initsup.c): * * MiInitializeMemoryEvents() { * ... * // * // Scale the threshold so on servers the low threshold is * // approximately 32MB per 4GB, capping it at 64MB. * // * * MmLowMemoryThreshold = MmPlentyFreePages; * * if (MmNumberOfPhysicalPages > 0x40000) { * MmLowMemoryThreshold = MI_MB_TO_PAGES (32); * MmLowMemoryThreshold += ((MmNumberOfPhysicalPages - 0x40000) >> 7); * } * else if (MmNumberOfPhysicalPages > 0x8000) { * MmLowMemoryThreshold += ((MmNumberOfPhysicalPages - 0x8000) >> 5); * } * * if (MmLowMemoryThreshold > MI_MB_TO_PAGES (64)) { * MmLowMemoryThreshold = MI_MB_TO_PAGES (64); * } * ... * * E.g. * * RAM(mb) low % * ------------------- * 256 20 92% * 512 24 95% * 768 28 96% * 1024 32 97% * 2048 40 98% * 3072 48 98% * 4096 56 99% * 5120 64 99% */ long memory = AspNetMemoryMonitor.s_totalPhysical; Debug.Assert(memory != 0, "memory != 0"); if (memory >= 0x100000000) { _pressureHigh = 99; } else if (memory >= 0x80000000) { _pressureHigh = 98; } else if (memory >= 0x40000000) { _pressureHigh = 97; } else if (memory >= 0x30000000) { _pressureHigh = 96; } else { _pressureHigh = 95; } _pressureLow = _pressureHigh - 9; InitHistory(); _appManager = ApplicationManager.GetApplicationManager(); _observers = new List <IObserver <LowPhysicalMemoryInfo> >(); CacheSection cacheConfig = null; RuntimeConfig lkgAppConfig = RuntimeConfig.GetAppLKGConfig(); RuntimeConfig appConfig = null; try { appConfig = RuntimeConfig.GetAppConfig(); cacheConfig = appConfig.Cache; } catch (Exception) { cacheConfig = lkgAppConfig.Cache; } ReadConfig(cacheConfig); // PerfCounter: Cache Percentage Machine Memory Limit Used // = total physical memory used / total physical memory used limit PerfCounters.SetCounter(AppPerfCounter.CACHE_PERCENT_MACH_MEM_LIMIT_USED_BASE, _pressureHigh); // start timer with initial poll interval _timer = new Timer(new TimerCallback(this.MonitorThread), null, Timeout.Infinite, _currentPollInterval); }