Ejemplo n.º 1
0
 protected void HandleCostHandleRelease(CostHandle costHandle)
 {
     lock (this.instanceLock)
     {
         this.CalculateElapsedTime(costHandle);
         this.myActions.Remove(costHandle.Key);
         if (costHandle == this.localCostHandle)
         {
             this.localCostHandle = null;
         }
     }
 }
Ejemplo n.º 2
0
 // Token: 0x06007471 RID: 29809 RVA: 0x00180084 File Offset: 0x0017E284
 protected override void AccountForCostHandle(CostHandle costHandle)
 {
     if (costHandle.CostType != CostType.Connection)
     {
         base.AccountForCostHandle(costHandle);
         return;
     }
     if (this.connections <= 0)
     {
         throw new InvalidOperationException("[StandardBudget.AccountForCostHandle] End for Connections was called, but there are no outstanding Connections.");
     }
     this.connections--;
     ThrottlingPerfCounterWrapper.DecrementBudgetsAtMaxConcurrency(base.Owner);
 }
Ejemplo n.º 3
0
 // Token: 0x060071E3 RID: 29155 RVA: 0x00179324 File Offset: 0x00177524
 protected virtual void AccountForCostHandle(CostHandle costHandle)
 {
     if (costHandle.CostType == CostType.CAS)
     {
         TimeSpan            timeSpan            = costHandle.PreCharge;
         LocalTimeCostHandle localTimeCostHandle = costHandle as LocalTimeCostHandle;
         bool flag = localTimeCostHandle != null && localTimeCostHandle.ReverseBudgetCharge;
         if (flag)
         {
             ExTraceGlobals.ClientThrottlingTracer.TraceDebug((long)this.GetHashCode(), "[Budget.AccountForCostHandle] Not charging budget for CAS time per protocol's request.");
             timeSpan += TimeProvider.UtcNow - costHandle.StartTime;
         }
         this.casTokenBucket.Decrement(timeSpan, flag);
         this.percentileUsage.AddUsage((int)(TimeProvider.UtcNow - costHandle.StartTime).TotalMilliseconds);
     }
 }
Ejemplo n.º 4
0
        // Token: 0x060071CB RID: 29131 RVA: 0x00178D64 File Offset: 0x00176F64
        internal void End(CostHandle costHandle)
        {
            bool flag = false;

            lock (this.SyncRoot)
            {
                flag = this.outstandingActions.Remove(costHandle.Key);
                if (flag)
                {
                    this.AccountForCostHandle(costHandle);
                }
            }
            if (!flag)
            {
                ExTraceGlobals.ClientThrottlingTracer.TraceError((long)this.GetHashCode(), "[Budget.End] CostHandle was not in outstanding actions collection.  Ignoring.");
            }
        }
Ejemplo n.º 5
0
        // Token: 0x0600746F RID: 29807 RVA: 0x0017FEEC File Offset: 0x0017E0EC
        public CostHandle StartConnection(Action <CostHandle> onRelease, string callerInfo)
        {
            CostHandle result;

            lock (base.SyncRoot)
            {
                int num = this.connections + 1;
                ExTraceGlobals.FaultInjectionTracer.TraceTest <int>(3701878077U, ref num);
                bool flag2 = false;
                ExTraceGlobals.FaultInjectionTracer.TraceTest <bool>(2630233405U, ref flag2);
                if (num > this.maxConcurrency || flag2)
                {
                    ThrottlingPerfCounterWrapper.IncrementBudgetsAtMaxConcurrency(base.Owner);
                    throw base.CreateOverBudgetException("MaxConcurrency", flag2 ? "FaultInjection" : this.maxConcurrency.ToString(), 0);
                }
                this.connections++;
                result = new CostHandle(this, CostType.Connection, onRelease, callerInfo, default(TimeSpan));
            }
            return(result);
        }
        // Token: 0x060073E4 RID: 29668 RVA: 0x0017DDDC File Offset: 0x0017BFDC
        protected override void AccountForCostHandle(CostHandle costHandle)
        {
            ExTraceGlobals.ClientThrottlingTracer.TraceDebug <BudgetKey, CostType, BudgetType>((long)this.GetHashCode(), "[PowerShellBudget.AccountForCostHandle] End called for user {0}, cost type {1}, budget type {2}", base.Owner, costHandle.CostType, base.Owner.BudgetType);
            base.AccountForCostHandle(costHandle);
            switch (costHandle.CostType)
            {
            case CostType.CMDLET:
                ThrottlingPerfCounterWrapper.DecrementExchangeExecutingCmdlets();
                return;

            case CostType.ActiveRunspace:
                Interlocked.Decrement(ref this.activeRunspaces);
                if (this.TrackActiveRunspacePerfCounter)
                {
                    ThrottlingPerfCounterWrapper.DecrementActivePowerShellRunspaces();
                }
                return;

            default:
                return;
            }
        }
Ejemplo n.º 7
0
        private void CalculateElapsedTime(CostHandle costHandle)
        {
            LocalTimeCostHandle localTimeCostHandle = costHandle as LocalTimeCostHandle;

            if (localTimeCostHandle != null)
            {
                TimeSpan unaccountedForTime = localTimeCostHandle.UnaccountedForTime;
                if (unaccountedForTime > TimeSpan.Zero)
                {
                    T t = this.GetInnerBudget();
                    if (t.CasTokenBucket.GetBalance() < 0f)
                    {
                        this.microDelayWorthyWork += unaccountedForTime;
                    }
                    else
                    {
                        this.microDelayWorthyWork = TimeSpan.Zero;
                    }
                    this.allWork += unaccountedForTime;
                    WorkloadManagementLogger.SetBudgetUsage(unaccountedForTime, null, null);
                }
            }
        }
Ejemplo n.º 8
0
        // Token: 0x060071E5 RID: 29157 RVA: 0x001794F8 File Offset: 0x001776F8
        internal void CheckLeakedActions()
        {
            DateTime          utcNow        = TimeProvider.UtcNow;
            StringBuilder     stringBuilder = null;
            List <CostHandle> list          = null;

            if (utcNow - this.lastLeakDetectionUtc >= Budget.LeakDetectionCheckInterval && this.OutstandingActionsCount > 0)
            {
                lock (this.syncRoot)
                {
                    if (utcNow - this.lastLeakDetectionUtc >= Budget.LeakDetectionCheckInterval && this.OutstandingActionsCount > 0)
                    {
                        this.lastLeakDetectionUtc = utcNow;
                        foreach (KeyValuePair <long, CostHandle> keyValuePair in this.outstandingActions)
                        {
                            CostHandle value    = keyValuePair.Value;
                            TimeSpan   timeSpan = utcNow - value.StartTime;
                            if (value.CostType == CostType.CAS && timeSpan > value.MaxLiveTime && !value.LeakLogged)
                            {
                                if (Budget.OnLeakDetectionForTest != null)
                                {
                                    Budget.OnLeakDetectionForTest(this, value, timeSpan, value.MaxLiveTime);
                                }
                                if (Budget.OnLeakDetectionForTest == null || Budget.OnLeakWatsonInfoForTest != null)
                                {
                                    if (stringBuilder == null)
                                    {
                                        stringBuilder = new StringBuilder();
                                    }
                                    stringBuilder.AppendLine(string.Format("CostType: {0}, Key: {1}, Limit: {2}, Elapsed: {3}, Actions: {4}, Description: {5}, Snapshot: {6}", new object[]
                                    {
                                        value.CostType,
                                        keyValuePair.Key,
                                        value.MaxLiveTime,
                                        timeSpan,
                                        this.OutstandingActionsCount,
                                        value.Description,
                                        this
                                    }));
                                }
                                value.LeakLogged = true;
                                if (list == null)
                                {
                                    list = new List <CostHandle>();
                                }
                                list.Add(value);
                            }
                        }
                    }
                }
            }
            if (Budget.OnLeakWatsonInfoForTest != null)
            {
                Budget.OnLeakWatsonInfoForTest(stringBuilder);
            }
            else if (stringBuilder != null)
            {
                try
                {
                    throw new LongRunningCostHandleException();
                }
                catch (LongRunningCostHandleException exception)
                {
                    ExWatson.SendReport(exception, ReportOptions.None, stringBuilder.ToString());
                }
            }
            if (stringBuilder != null)
            {
                string text = stringBuilder.ToString();
                Globals.LogEvent(DirectoryEventLogConstants.Tuple_BudgetActionExceededExpectedTime, text, new object[]
                {
                    "\n" + text
                });
            }
            if (list != null)
            {
                foreach (CostHandle costHandle in list)
                {
                    costHandle.Dispose();
                }
            }
        }