static CpuStatistics() { if (bool.TryParse(ConfigurationManager.AppSettings["Raven/DynamicLoadBalancing"], out dynamicLoadBalancing) && dynamicLoadBalancing == false) { return; // disabled, so we avoid it } dynamicLoadBalancing = true; AppDomain.CurrentDomain.DomainUnload += (sender, args) => _domainUnload.Set(); new Thread(() => { try { var usage = new CpuUsage(); while (true) { if (_domainUnload.Wait(1000)) { return; } var totalUsage = usage.GetCurrentUsage(); try { HandleCpuUsage(totalUsage); } catch (Exception e) { Log.WarnException("Failed to notify handlers about CPU usage, aborting CPU throttling", e); return; } } } catch (Exception e) { Log.ErrorException("Errpr handling CPU statistics during automatic CPU throttling, aborting automatic thorttling!", e); } }) { IsBackground = true, Name = "CPU usage notification thread" }.Start(); }
static CpuStatistics() { if (bool.TryParse(ConfigurationManager.AppSettings["Raven/DynamicLoadBalancing"], out dynamicLoadBalancing) && dynamicLoadBalancing == false) return; // disabled, so we avoid it dynamicLoadBalancing = true; AppDomain.CurrentDomain.DomainUnload += (sender, args) => _domainUnload.Set(); new Thread(() => { try { var usage = new CpuUsage(); while (true) { if (_domainUnload.Wait(1000)) return; var totalUsage = usage.GetCurrentUsage(); try { HandleCpuUsage(totalUsage); } catch (Exception e) { Log.WarnException("Failed to notify handlers about CPU usage, aborting CPU throttling", e); return; } } } catch (Exception e) { Log.ErrorException("Errpr handling CPU statistics during automatic CPU throttling, aborting automatic thorttling!", e); } }) { IsBackground = true, Name = "CPU usage notification thread" };//.Start(); }