public DelayInfo GetDelay(ICollection <CostType> consideredCostTypes)
        {
            DelayInfo faultInjectionDelay = this.GetFaultInjectionDelay();

            if (faultInjectionDelay != DelayInfo.NoDelay)
            {
                return(faultInjectionDelay);
            }
            BudgetTypeSetting budgetTypeSetting = BudgetTypeSettings.Get(this.Owner.BudgetType);
            DelayInfo         hardQuotaDelay    = this.GetHardQuotaDelay(consideredCostTypes, budgetTypeSetting);

            if (hardQuotaDelay.Delay == budgetTypeSetting.MaxDelay)
            {
                return(hardQuotaDelay);
            }
            DelayInfo microDelay = this.GetMicroDelay(consideredCostTypes, budgetTypeSetting);

            if (hardQuotaDelay.Delay >= microDelay.Delay)
            {
                ExTraceGlobals.ClientThrottlingTracer.TraceDebug <TimeSpan, TimeSpan>((long)this.GetHashCode(), "[BudgetWrapper.GetDelay] UserQuota delay '{0}' was greater than micro delay '{1}'", hardQuotaDelay.Delay, microDelay.Delay);
                return(hardQuotaDelay);
            }
            ExTraceGlobals.ClientThrottlingTracer.TraceDebug <TimeSpan, TimeSpan>((long)this.GetHashCode(), "[BudgetWrapper.GetDelay] Micro delay '{0}' was greater than user quota delay '{1}'", microDelay.Delay, hardQuotaDelay.Delay);
            return(microDelay);
        }
Beispiel #2
0
        // Token: 0x06007229 RID: 29225 RVA: 0x0017A148 File Offset: 0x00178348
        internal static BudgetTypeSetting GetDefault(BudgetType budgetType)
        {
            if (BudgetTypeSettings.GetSettingsTestHook != null)
            {
                return(BudgetTypeSettings.GetSettingsTestHook(budgetType));
            }
            BudgetTypeSetting result = null;

            if (BudgetTypeSettings.defaultBudgetTypeSettingsMap.TryGetValue(budgetType, out result))
            {
                return(result);
            }
            return(BudgetTypeSetting.OneMinuteSetting);
        }
Beispiel #3
0
 // Token: 0x0600722E RID: 29230 RVA: 0x0017A220 File Offset: 0x00178420
 private static void LoadAppConfigSettings()
 {
     BudgetTypeSettings.budgetTypeSettingsMap = new Dictionary <BudgetType, BudgetTypeSetting>();
     foreach (object obj in Enum.GetValues(typeof(BudgetType)))
     {
         BudgetType               budgetType               = (BudgetType)obj;
         string                   name                     = BudgetTypeSettings.BuildMicroDelayMultiplierKey(budgetType);
         string                   name2                    = BudgetTypeSettings.BuildMaxDelayKey(budgetType);
         string                   name3                    = BudgetTypeSettings.BuildMaxDelayedThreadsKey(budgetType);
         BudgetTypeSetting        @default                 = BudgetTypeSettings.GetDefault(budgetType);
         IntAppSettingsEntry      intAppSettingsEntry      = new IntAppSettingsEntry(name, @default.MaxMicroDelayMultiplier, ExTraceGlobals.BudgetDelayTracer);
         TimeSpanAppSettingsEntry timeSpanAppSettingsEntry = new TimeSpanAppSettingsEntry(name2, TimeSpanUnit.Seconds, @default.MaxDelay, ExTraceGlobals.BudgetDelayTracer);
         IntAppSettingsEntry      intAppSettingsEntry2     = new IntAppSettingsEntry(name3, @default.MaxDelayedThreadPerProcessor, ExTraceGlobals.BudgetDelayTracer);
         BudgetTypeSetting        value                    = new BudgetTypeSetting(timeSpanAppSettingsEntry.Value, intAppSettingsEntry.Value, intAppSettingsEntry2.Value);
         BudgetTypeSettings.budgetTypeSettingsMap[budgetType] = value;
     }
 }
        private DelayInfo GetMicroDelay(ICollection <CostType> consideredCostTypes, BudgetTypeSetting budgetTypeSetting)
        {
            if (this.microDelayWorthyWork == TimeSpan.Zero || !consideredCostTypes.Contains(CostType.CAS))
            {
                return(DelayInfo.NoDelay);
            }
            float balance = this.innerBudget.CasTokenBucket.GetBalance();

            if (balance < 0f)
            {
                SingleComponentThrottlingPolicy throttlingPolicy = this.innerBudget.ThrottlingPolicy;
                int      num       = (int)this.microDelayWorthyWork.TotalMilliseconds;
                int      num2      = num * (int)(3600000U / throttlingPolicy.RechargeRate.Value);
                float    num3      = -balance / throttlingPolicy.RechargeRate.Value;
                TimeSpan timeSpan  = TimeSpan.FromMilliseconds((double)((float)num2 * num3));
                TimeSpan timeSpan2 = (BudgetWrapper <T> .MinimumMicroDelay > timeSpan) ? BudgetWrapper <T> .MinimumMicroDelay : timeSpan;
                TimeSpan timeSpan3 = timeSpan2;
                TimeSpan timeSpan4 = (budgetTypeSetting.MaxMicroDelayMultiplier == int.MaxValue) ? TimeSpan.MaxValue : TimeSpan.FromMilliseconds((double)(num * budgetTypeSetting.MaxMicroDelayMultiplier));
                if (timeSpan3 > timeSpan4)
                {
                    ExTraceGlobals.ClientThrottlingTracer.TraceDebug((long)this.GetHashCode(), "[BudgetWrapper.GetDelay] Budget '{0}' calculated an overBudgetFactor of '{1}', but used registry cap of '{2}' instead.  Budget Snapshot: '{3}'", new object[]
                    {
                        this.Owner,
                        num3,
                        budgetTypeSetting.MaxMicroDelayMultiplier,
                        this
                    });
                    timeSpan3 = timeSpan4;
                }
                if (timeSpan3 > budgetTypeSetting.MaxDelay)
                {
                    ExTraceGlobals.ClientThrottlingTracer.TraceDebug <BudgetKey, TimeSpan, TimeSpan>((long)this.GetHashCode(), "[BudgetWrapper.GetDelay] Budget '{0}' calculated a cappedDelay of '{1}' which was higher than registry MaxDelay of '{2}'.  Using MaxDelay instead.", this.Owner, timeSpan3, budgetTypeSetting.MaxDelay);
                    ThrottlingPerfCounterWrapper.IncrementBudgetsAtMaxDelay(this.Owner);
                    timeSpan3 = budgetTypeSetting.MaxDelay;
                }
                ThrottlingPerfCounterWrapper.IncrementBudgetsMicroDelayed(this.Owner);
                DelayInfo.TraceMicroDelays(this, TimeSpan.FromMilliseconds((double)num), timeSpan3);
                return(new DelayInfo(timeSpan3, false));
            }
            return(DelayInfo.NoDelay);
        }
        private DelayInfo GetHardQuotaDelay(ICollection <CostType> consideredCostTypes, BudgetTypeSetting budgetTypeSetting)
        {
            OverBudgetException ex = null;

            if (this.TryCheckOverBudget(consideredCostTypes, out ex))
            {
                int      backoffTime = ex.BackoffTime;
                TimeSpan timeSpan    = TimeSpan.FromMilliseconds((double)backoffTime);
                TimeSpan delay       = (timeSpan > budgetTypeSetting.MaxDelay) ? budgetTypeSetting.MaxDelay : timeSpan;
                return(new UserQuotaDelayInfo(delay, ex, true));
            }
            return(DelayInfo.NoDelay);
        }