protected void EnforceDelay() { if (this.context.ErrorInfo.TerminatePipeline) { return; } IPowerShellBudget psbudget = this.PSBudget; if (psbudget != null) { T t = (default(T) == null) ? Activator.CreateInstance <T>() : default(T); DelayEnforcementResults delayEnforcementResults = t.EnforceDelay(this, ThrottlingModule <T> .costTypesInEnforceDelay, ThrottlingModule <T> .CmdletMaxPreferredDelay); LocalizedString localizedString = this.GenerateDelayInfoLogString(this.PSBudget, delayEnforcementResults); if (!string.IsNullOrEmpty(localizedString)) { string text = string.Format("; PolicyDN: {0}; Snapshot: {1}", psbudget.ThrottlingPolicy.GetIdentityString(), psbudget); LocalizedString warningMessage = new LocalizedString(localizedString + text); this.context.Items["ThrottlingInfo"] = text; this.context.Items["DelayedInfo"] = localizedString; Guid uniqueId = this.context.UniqueId; CmdletLogger.SafeSetLogger(uniqueId, RpsCmdletMetadata.ThrottlingInfo, text); CmdletLogger.SafeSetLogger(uniqueId, RpsCmdletMetadata.DelayInfo, CmdletLogHelper.NeedConvertLogMessageToUS ? localizedString.ToString(CmdletLogHelper.DefaultLoggingCulture) : localizedString); this.WriteCmdletMicroDelayMessage(warningMessage, delayEnforcementResults.DelayInfo.Delay.TotalSeconds); } PowerShellBudgetWrapper powerShellBudgetWrapper = psbudget as PowerShellBudgetWrapper; WorkloadManagementLogger.SetBudgetBalance(powerShellBudgetWrapper.GetInnerBudget().CasTokenBucket.GetBalance().ToString(), null); } }
protected override void InternalDispose(bool disposing) { if (disposing) { if (this.budget != null) { if (!this.skipWLMThrottling) { TimeSpan timeSpan = MicroDelayScope.maxCallProcessingTime - (ExDateTime.UtcNow - this.startedCallProcessingAt); if (timeSpan < TimeSpan.Zero) { timeSpan = TimeSpan.Zero; } DelayEnforcementResults delayEnforcement = ResourceLoadDelayInfo.EnforceDelay(this.budget, this.workLoadSettings, this.resources, timeSpan, null); this.TraceDelay(delayEnforcement); } this.budget.Dispose(); this.budget = null; } if (this.scope != null) { this.scope.End(); this.scope = null; } } }
private void TraceDelay(DelayEnforcementResults delayEnforcement) { if (delayEnforcement.DelayInfo != DelayInfo.NoDelay) { MrsTracer.ResourceHealth.Debug("Micro Delay: {0} msec due to resource: '{1}'", new object[] { delayEnforcement.DelayedAmount.TotalMilliseconds, (delayEnforcement.DelayInfo as ResourceLoadDelayInfo).ResourceKey }); } }
private LocalizedString GenerateDelayInfoLogString(IBudget budget, DelayEnforcementResults info) { LocalizedString result = LocalizedString.Empty; if (!string.Equals(info.NotEnforcedReason, "No Delay Necessary", StringComparison.OrdinalIgnoreCase)) { CmdletLogger.SafeAppendGenericInfo(this.context.UniqueId, "DelayInfo.Type", info.DelayInfo.GetType().Name); if (info.NotEnforcedReason != null) { CmdletLogger.SafeAppendGenericInfo(this.context.UniqueId, "NotEnforcedReason", info.NotEnforcedReason); } if (string.Equals(info.NotEnforcedReason, "Max Delayed Threads Exceeded", StringComparison.OrdinalIgnoreCase)) { BudgetTypeSetting budgetTypeSetting = BudgetTypeSettings.Get(budget.Owner.BudgetType); if (info.DelayInfo is UserQuotaDelayInfo) { UserQuotaDelayInfo userQuotaDelayInfo = info.DelayInfo as UserQuotaDelayInfo; result = Strings.UserQuotaDelayNotEnforcedMaxThreadsExceeded((int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, userQuotaDelayInfo.OverBudgetException.PolicyPart, budgetTypeSetting.MaxDelayedThreads); } else if (info.DelayInfo is ResourceLoadDelayInfo) { ResourceLoadDelayInfo resourceLoadDelayInfo = info.DelayInfo as ResourceLoadDelayInfo; result = Strings.ResourceLoadDelayNotEnforcedMaxThreadsExceeded((int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, resourceLoadDelayInfo.ResourceKey.ToString(), resourceLoadDelayInfo.ResourceLoad.ToString(), budgetTypeSetting.MaxDelayedThreads); } else { result = Strings.MicroDelayNotEnforcedMaxThreadsExceeded((int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, budgetTypeSetting.MaxDelayedThreads); } } else { CmdletLogger.SafeSetLogger(this.context.UniqueId, RpsCmdletMetadata.ThrottlingDelay, info.DelayedAmount.TotalMilliseconds); if (info.DelayInfo is UserQuotaDelayInfo) { UserQuotaDelayInfo userQuotaDelayInfo2 = info.DelayInfo as UserQuotaDelayInfo; result = Strings.UserQuotaDelayInfo((int)info.DelayedAmount.TotalMilliseconds, info.Enforced, (int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, userQuotaDelayInfo2.OverBudgetException.PolicyPart, info.NotEnforcedReason); } else if (info.DelayInfo is ResourceLoadDelayInfo) { ResourceLoadDelayInfo resourceLoadDelayInfo2 = info.DelayInfo as ResourceLoadDelayInfo; result = Strings.ResourceLoadDelayInfo((int)info.DelayedAmount.TotalMilliseconds, info.Enforced, (int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, resourceLoadDelayInfo2.ResourceKey.ToString(), resourceLoadDelayInfo2.ResourceLoad.ToString(), info.NotEnforcedReason); } else { result = Strings.MicroDelayInfo((int)info.DelayedAmount.TotalMilliseconds, info.Enforced, (int)info.DelayInfo.Delay.TotalMilliseconds, info.DelayInfo.Required, info.NotEnforcedReason); } } } return(result); }
// Token: 0x06001D63 RID: 7523 RVA: 0x000755B4 File Offset: 0x000737B4 private void CompleteRequest(SpeechRecognitionProcessor.SpeechProcessorAsyncCompletedArgs args) { if (this.IsSpeechRequestNotCompleted()) { ExTraceGlobals.SpeechRecognitionTracer.TraceDebug <int, string>((long)this.GetHashCode(), "SpeechRecognitionProcessor - Status code='{0}', Status message='{1}'", args.HttpStatus.StatusCode, args.HttpStatus.StatusDescription); this.CollectAndLogStatisticsInformation(SpeechLoggerProcessType.RequestCompleted, -1); this.asyncResult.StatusCode = args.HttpStatus.StatusCode; this.asyncResult.StatusDescription = args.HttpStatus.StatusDescription; this.asyncResult.ResponseText = args.ResponseText; this.asyncResult.ThrottlingDelay = -1.0; this.asyncResult.ThrottlingNotEnforcedReason = string.Empty; if (this.budget != null) { try { this.budget.EndLocal(); DelayEnforcementResults delayEnforcementResults = ResourceLoadDelayInfo.EnforceDelay(this.budget, new WorkloadSettings(WorkloadType.OwaVoice, false), null, TimeSpan.MaxValue, null); if (delayEnforcementResults != null && delayEnforcementResults.DelayInfo != null) { ExTraceGlobals.SpeechRecognitionTracer.TraceDebug((long)this.GetHashCode(), "SpeechRecognitionProcessor - Request id={0}, Delayed amount={1}s, Capped delay={2}s, Delay Required={3}, NotEnforcedReason={4}", new object[] { this.RequestId, delayEnforcementResults.DelayedAmount.TotalSeconds, delayEnforcementResults.DelayInfo.Delay.TotalSeconds, delayEnforcementResults.DelayInfo.Required, delayEnforcementResults.NotEnforcedReason }); this.asyncResult.ThrottlingDelay = delayEnforcementResults.DelayedAmount.TotalSeconds; this.asyncResult.ThrottlingNotEnforcedReason = delayEnforcementResults.NotEnforcedReason; } this.budget.EndConnection(); } finally { this.budget.Dispose(); this.budget = null; } } this.asyncResult.IsCompleted = true; return; } ExTraceGlobals.SpeechRecognitionTracer.TraceDebug((long)this.GetHashCode(), "SpeechRecognitionProcessor.CompleteRequest: speech request already completed, ignoring this request."); }