public ResourceMetricPolicy(ResourceMetricType metricType, WorkloadClassification classification, IResourceSettings settings) { this.MetricType = metricType; this.Classification = classification; switch (classification) { case WorkloadClassification.Discretionary: this.UnderloadedThreshold = settings.DiscretionaryUnderloaded; this.OverloadedThreshold = settings.DiscretionaryOverloaded; this.CriticalThreshold = settings.DiscretionaryCritical; break; case WorkloadClassification.InternalMaintenance: this.UnderloadedThreshold = settings.InternalMaintenanceUnderloaded; this.OverloadedThreshold = settings.InternalMaintenanceOverloaded; this.CriticalThreshold = settings.InternalMaintenanceCritical; break; case WorkloadClassification.CustomerExpectation: this.UnderloadedThreshold = settings.CustomerExpectationUnderloaded; this.OverloadedThreshold = settings.CustomerExpectationOverloaded; this.CriticalThreshold = settings.CustomerExpectationCritical; break; case WorkloadClassification.Urgent: this.UnderloadedThreshold = settings.UrgentUnderloaded; this.OverloadedThreshold = settings.UrgentOverloaded; this.CriticalThreshold = settings.UrgentCritical; break; } this.Validate(); }
public override ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null) { this.LastAccessUtc = DateTime.UtcNow; ResourceLoad resourceLoad; switch (this.constraintResult) { case ConstraintCheckResultType.Retry: resourceLoad = ResourceLoad.Unknown; goto IL_48; case ConstraintCheckResultType.Satisfied: resourceLoad = ResourceLoad.Zero; goto IL_48; case ConstraintCheckResultType.NotSatisfied: resourceLoad = ResourceLoad.Full; goto IL_48; } resourceLoad = ResourceLoad.Critical; IL_48: Guid databaseGuid = (base.Key as LegacyResourceHealthMonitorKey).DatabaseGuid; MrsTracer.ResourceHealth.Debug("LegacyResourceHealthMonitor.GetResourceLoad(): Mdb: '{0}', Constraint result: '{1}', Load: '{2}'", new object[] { databaseGuid, this.constraintResult, resourceLoad }); return(resourceLoad); }
public static ResourceLoadPerfCounterWrapper Get(ResourceKey resource, WorkloadClassification classification) { ResourceLoadPerfCounterWrapper resourceLoadPerfCounterWrapper = null; Tuple <ResourceKey, WorkloadClassification> key = new Tuple <ResourceKey, WorkloadClassification>(resource, classification); lock (ResourceLoadPerfCounterWrapper.staticLock) { if (ResourceLoadPerfCounterWrapper.instances.TryGetValue(key, out resourceLoadPerfCounterWrapper)) { resourceLoadPerfCounterWrapper.lastUpdateUtc = DateTime.UtcNow; } } if (resourceLoadPerfCounterWrapper == null) { if (ResourceHealthMonitorManager.Active) { string text = string.Concat(new object[] { ResourceLoadPerfCounterWrapper.GetDefaultInstanceName(), "_", resource, "_", classification }); try { MSExchangeResourceLoadInstance instance = MSExchangeResourceLoad.GetInstance(text); resourceLoadPerfCounterWrapper = new ResourceLoadPerfCounterWrapper(instance); } catch (Exception ex) { Globals.LogEvent(DirectoryEventLogConstants.Tuple_InitializeResourceHealthPerformanceCountersFailed, string.Empty, new object[] { ResourceLoadPerfCounterWrapper.GetDefaultInstanceName(), ex.ToString() }); ExTraceGlobals.ClientThrottlingTracer.TraceError <string, string, string>(0L, "[ResourceLoadPerfCounterWrapper::Get] Perf counter initialization failed for key instance: {0} with exception type: {1}, Messsage: {2}", text, ex.GetType().FullName, ex.Message); } } if (resourceLoadPerfCounterWrapper == null) { resourceLoadPerfCounterWrapper = new ResourceLoadPerfCounterWrapper(null); } lock (ResourceLoadPerfCounterWrapper.staticLock) { ResourceLoadPerfCounterWrapper resourceLoadPerfCounterWrapper2; if (!ResourceLoadPerfCounterWrapper.instances.TryGetValue(key, out resourceLoadPerfCounterWrapper2)) { ResourceLoadPerfCounterWrapper.instances.Add(key, resourceLoadPerfCounterWrapper); } else { resourceLoadPerfCounterWrapper = resourceLoadPerfCounterWrapper2; } } } return(resourceLoadPerfCounterWrapper); }
// Token: 0x060075F8 RID: 30200 RVA: 0x001844C0 File Offset: 0x001826C0 private static Dictionary <WorkloadClassification, CacheableResourceHealthMonitor.LoadInfo> CreateLoadInfoDictionary() { Dictionary <WorkloadClassification, CacheableResourceHealthMonitor.LoadInfo> dictionary = new Dictionary <WorkloadClassification, CacheableResourceHealthMonitor.LoadInfo>(); foreach (object obj in Enum.GetValues(typeof(WorkloadClassification))) { WorkloadClassification workloadClassification = (WorkloadClassification)obj; if (workloadClassification != WorkloadClassification.Unknown) { dictionary.Add(workloadClassification, new CacheableResourceHealthMonitor.LoadInfo()); } } return(dictionary); }
public static void AddActiveClassification(WorkloadClassification classification) { lock (SystemWorkloadManagerBlackBox.activeLock) { if (SystemWorkloadManagerBlackBox.active == null || !SystemWorkloadManagerBlackBox.active.Contains(classification)) { HashSet <WorkloadClassification> hashSet; if (SystemWorkloadManagerBlackBox.active == null) { hashSet = new HashSet <WorkloadClassification>(); } else { hashSet = new HashSet <WorkloadClassification>(SystemWorkloadManagerBlackBox.active); } hashSet.Add(classification); SystemWorkloadManagerBlackBox.active = hashSet; } } }
// Token: 0x060075E8 RID: 30184 RVA: 0x00183D14 File Offset: 0x00181F14 public Guid SubscribeToHealthNotifications(WorkloadClassification classification, HealthRecoveryNotification delegateToFire) { if (delegateToFire == null) { throw new ArgumentNullException("delegateToFire"); } if (classification == WorkloadClassification.Unknown) { throw new ArgumentException("You cannot use Unknown to register for health change notifications.", "classification"); } ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceKey, WorkloadClassification>((long)this.GetHashCode(), "[CacheableResourceHealthMonitor.SubscribeToHealthNotifications] Registration was made for resource '{0}', classification: {1}.", this.Key, classification); Guid key; lock (this.instanceLock) { CacheableResourceHealthMonitor.NotificationWrapper notificationWrapper = new CacheableResourceHealthMonitor.NotificationWrapper(classification, delegateToFire); this.notifications.Add(notificationWrapper); this.notificationCount++; key = notificationWrapper.Key; } return(key); }
// Token: 0x060075FA RID: 30202 RVA: 0x00184597 File Offset: 0x00182797 public NotificationWrapper(WorkloadClassification classification, HealthRecoveryNotification delegateToFire) { this.Classification = classification; this.Notification = delegateToFire; this.Key = Guid.NewGuid(); }
// Token: 0x060075F6 RID: 30198 RVA: 0x00184160 File Offset: 0x00182360 public virtual ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null) { if (!this.Settings.Enabled) { return(ResourceLoad.Zero); } int metricValue = this.GetMetricValue(optionalData); if (metricValue < 0) { return(ResourceLoad.Unknown); } ResourceMetricPolicy resourceMetricPolicy = new ResourceMetricPolicy(this.MetricType, classification, this.Settings); ResourceLoad resourceLoad = resourceMetricPolicy.InterpretMetricValue(metricValue); if (!raw) { CacheableResourceHealthMonitor.LoadInfo loadInfo = this.loadInfo[classification]; if (this.UpdateIsNeeded(loadInfo, resourceLoad)) { try { if (Monitor.TryEnter(this.instanceLock) && this.UpdateIsNeeded(loadInfo, resourceLoad)) { switch (resourceLoad.State) { case ResourceLoadState.Unknown: loadInfo.Load = resourceLoad; break; case ResourceLoadState.Underloaded: case ResourceLoadState.Full: if (loadInfo.Load < ResourceLoad.Full) { loadInfo.Load = resourceLoad; } else if (this.LastUpdateUtc > loadInfo.UpdateUtc) { if (loadInfo.Load == ResourceLoad.Full) { loadInfo.Load = resourceLoad; } else if (loadInfo.Load == ResourceLoad.Critical) { loadInfo.Load = new ResourceLoad(resourceMetricPolicy.MaxOverloaded.LoadRatio, new int?(metricValue), null); } else if (resourceLoad.State == ResourceLoadState.Underloaded) { double num = (resourceMetricPolicy.MaxOverloaded - ResourceLoad.Full) / (double)CacheableResourceHealthMonitor.numberOfAdjustmentSteps; if (loadInfo.Load - ResourceLoad.Full > num) { loadInfo.Load -= num; } else { loadInfo.Load = new ResourceLoad(ResourceLoad.Full.LoadRatio, new int?(metricValue), null); } } } break; case ResourceLoadState.Overloaded: if (loadInfo.Load < resourceLoad) { loadInfo.Load = resourceLoad; } else if (this.LastUpdateUtc > loadInfo.UpdateUtc) { double delta = (resourceMetricPolicy.MaxOverloaded - ResourceLoad.Full) / (double)CacheableResourceHealthMonitor.numberOfAdjustmentSteps; if (loadInfo.Load + delta <= resourceMetricPolicy.MaxOverloaded) { loadInfo.Load += delta; } else { loadInfo.Load = new ResourceLoad(ResourceLoad.Critical.LoadRatio, new int?(metricValue), null); } } break; case ResourceLoadState.Critical: loadInfo.Load = resourceLoad; break; } } } finally { if (Monitor.IsEntered(this.instanceLock)) { Monitor.Exit(this.instanceLock); } } } resourceLoad = loadInfo.Load; } object resourceLoadlInfo = this.GetResourceLoadlInfo(resourceLoad); if (resourceLoadlInfo != null) { resourceLoad = new ResourceLoad(resourceLoad.LoadRatio, resourceLoad.Metric, resourceLoadlInfo); } ResourceLoadPerfCounterWrapper.Get(this.resourceKey, classification).Update(metricValue, resourceLoad); lock (this.lastEntries) { SystemWorkloadManagerLogEntry value = null; this.lastEntries.TryGetValue(classification, out value); SystemWorkloadManagerBlackBox.RecordMonitorUpdate(ref value, this.resourceKey, classification, resourceLoad); this.lastEntries[classification] = value; } ExTraceGlobals.ResourceHealthManagerTracer.TraceDebug <ResourceMetricType, ResourceLoad>((long)this.GetHashCode(), "[ResourceLoadMonitor.GetResourceLoad] MetricType={0}, Current Load={1}.", this.MetricType, resourceLoad); return(resourceLoad); }
public SystemWorkloadManagerLogEntry(SystemWorkloadManagerLogEntryType type, ResourceKey resource, WorkloadClassification classification, SystemWorkloadManagerEvent currentEvent, SystemWorkloadManagerEvent previousEvent) { this.Type = type; this.Resource = resource; this.Classification = classification; this.CurrentEvent = currentEvent; this.PreviousEvent = previousEvent; }
public override ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null) { return(ResourceLoad.Zero); }
public static void RecordMonitorUpdate(ref SystemWorkloadManagerLogEntry lastEntry, ResourceKey resource, WorkloadClassification classification, ResourceLoad load) { SystemWorkloadManagerBlackBox.Record(ref lastEntry, SystemWorkloadManagerLogEntryType.Monitor, resource, classification, load, -1, false); }
public ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null) { this.CheckExpired(); return(this.wrappedMonitor.GetResourceLoad(classification, raw, optionalData)); }
public override ResourceLoad GetResourceLoad(WorkloadClassification classification, bool raw = false, object optionalData = null) { this.PingIfNecessary(); return(base.GetResourceLoad(classification, raw, null)); }
public ResourceMetricPolicy(ResourceMetricType type, WorkloadClassification classification) : this(type, classification, VariantConfiguration.GetSnapshot(MachineSettingsContext.Local, null, null)) { }
public static void RecordAdmissionUpdate(ref SystemWorkloadManagerLogEntry lastEntry, ResourceKey resource, WorkloadClassification classification, ResourceLoad load, int slots, bool delayed) { SystemWorkloadManagerBlackBox.Record(ref lastEntry, SystemWorkloadManagerLogEntryType.Admission, resource, classification, load, slots, delayed); }
public ResourceMetricPolicy(ResourceMetricType type, WorkloadClassification classification, VariantConfigurationSnapshot config) : this(type, classification, config.WorkloadManagement.GetObject <IResourceSettings>(type, new object[0])) { }
private static void Record(ref SystemWorkloadManagerLogEntry lastEntry, SystemWorkloadManagerLogEntryType type, ResourceKey resource, WorkloadClassification classification, ResourceLoad load, int slots, bool delayed) { if ((SystemWorkloadManagerBlackBox.active == null || SystemWorkloadManagerBlackBox.active.Contains(classification)) && (lastEntry == null || lastEntry.CurrentEvent.Load.State != load.State || lastEntry.CurrentEvent.Slots != slots || lastEntry.CurrentEvent.Delayed != delayed)) { SystemWorkloadManagerEvent currentEvent = new SystemWorkloadManagerEvent(load, slots, delayed); lock (SystemWorkloadManagerBlackBox.history) { while (SystemWorkloadManagerBlackBox.history.Count >= SystemWorkloadManagerBlackBox.maxHistoryDepth) { SystemWorkloadManagerBlackBox.history.Dequeue(); } if (lastEntry == null) { lastEntry = new SystemWorkloadManagerLogEntry(type, resource, classification, currentEvent, null); SystemWorkloadManagerBlackBox.history.Enqueue(lastEntry); } else { lastEntry = new SystemWorkloadManagerLogEntry(type, resource, classification, currentEvent, lastEntry.CurrentEvent); SystemWorkloadManagerBlackBox.history.Enqueue(lastEntry); } } } }