コード例 #1
0
            public long GetTotalCallVolume()
            {
                DecayRpcScheduler scheduler = delegate_.Get();

                if (scheduler == null)
                {
                    return(-1);
                }
                else
                {
                    return(scheduler.GetTotalCallVolume());
                }
            }
コード例 #2
0
            public string GetCallVolumeSummary()
            {
                DecayRpcScheduler scheduler = delegate_.Get();

                if (scheduler == null)
                {
                    return("No Active Scheduler");
                }
                else
                {
                    return(scheduler.GetCallVolumeSummary());
                }
            }
コード例 #3
0
            public int GetUniqueIdentityCount()
            {
                DecayRpcScheduler scheduler = delegate_.Get();

                if (scheduler == null)
                {
                    return(-1);
                }
                else
                {
                    return(scheduler.GetUniqueIdentityCount());
                }
            }
コード例 #4
0
        public virtual void TestParsePeriod()
        {
            // By default
            scheduler = new DecayRpcScheduler(1, string.Empty, new Configuration());
            Assert.Equal(DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodDefault
                         , scheduler.GetDecayPeriodMillis());
            // Custom
            Configuration conf = new Configuration();

            conf.SetLong("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodKey, 1058);
            scheduler = new DecayRpcScheduler(1, "ns", conf);
            Assert.Equal(1058L, scheduler.GetDecayPeriodMillis());
        }
コード例 #5
0
        public virtual void TestParseFactor()
        {
            // Default
            scheduler = new DecayRpcScheduler(1, string.Empty, new Configuration());
            Assert.Equal(DecayRpcScheduler.IpcCallqueueDecayschedulerFactorDefault
                         , scheduler.GetDecayFactor(), 0.00001);
            // Custom
            Configuration conf = new Configuration();

            conf.Set("prefix." + DecayRpcScheduler.IpcCallqueueDecayschedulerFactorKey, "0.125"
                     );
            scheduler = new DecayRpcScheduler(1, "prefix", conf);
            Assert.Equal(0.125, scheduler.GetDecayFactor(), 0.00001);
        }
コード例 #6
0
 public DecayTask(DecayRpcScheduler scheduler, Timer timer)
 {
     // Specifies the identity to use when the IdentityProvider cannot handle
     // a schedulable.
     // Track the number of calls for each schedulable identity
     // Should be the sum of all AtomicLongs in callCounts
     // Pre-computed scheduling decisions during the decay sweep are
     // atomically swapped in as a read-only map
     // Tune the behavior of the scheduler
     // How long between each tick
     // nextCount = currentCount / decayFactor
     // affects scheduling decisions, from 0 to numQueues - 1
     this.schedulerRef = new WeakReference <DecayRpcScheduler>(scheduler);
     this.timer        = timer;
 }
コード例 #7
0
            public override void Run()
            {
                DecayRpcScheduler sched = schedulerRef.Get();

                if (sched != null)
                {
                    sched.DecayCurrentCounts();
                }
                else
                {
                    // Our scheduler was garbage collected since it is no longer in use,
                    // so we should terminate the timer as well
                    timer.Cancel();
                    timer.Purge();
                }
            }
コード例 #8
0
        public virtual void TestAccumulate()
        {
            Configuration conf = new Configuration();

            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodKey, "99999999"
                     );
            // Never flush
            scheduler = new DecayRpcScheduler(1, "ns", conf);
            Assert.Equal(0, scheduler.GetCallCountSnapshot().Count);
            // empty first
            scheduler.GetPriorityLevel(MockCall("A"));
            Assert.Equal(1, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(1, scheduler.GetCallCountSnapshot()["A"]);
            scheduler.GetPriorityLevel(MockCall("A"));
            scheduler.GetPriorityLevel(MockCall("B"));
            scheduler.GetPriorityLevel(MockCall("A"));
            Assert.Equal(3, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(1, scheduler.GetCallCountSnapshot()["B"]);
        }
コード例 #9
0
        /// <exception cref="System.Exception"/>
        public virtual void TestPeriodic()
        {
            Configuration conf = new Configuration();

            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodKey, "10");
            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerFactorKey, "0.5");
            scheduler = new DecayRpcScheduler(1, "ns", conf);
            Assert.Equal(10, scheduler.GetDecayPeriodMillis());
            Assert.Equal(0, scheduler.GetTotalCallSnapshot());
            for (int i = 0; i < 64; i++)
            {
                scheduler.GetPriorityLevel(MockCall("A"));
            }
            // It should eventually decay to zero
            while (scheduler.GetTotalCallSnapshot() > 0)
            {
                Thread.Sleep(10);
            }
        }
コード例 #10
0
        public virtual void TestPriority()
        {
            Configuration conf = new Configuration();

            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodKey, "99999999"
                     );
            // Never flush
            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerThresholdsKey, "25, 50, 75"
                     );
            scheduler = new DecayRpcScheduler(4, "ns", conf);
            Assert.Equal(0, scheduler.GetPriorityLevel(MockCall("A")));
            Assert.Equal(2, scheduler.GetPriorityLevel(MockCall("A")));
            Assert.Equal(0, scheduler.GetPriorityLevel(MockCall("B")));
            Assert.Equal(1, scheduler.GetPriorityLevel(MockCall("B")));
            Assert.Equal(0, scheduler.GetPriorityLevel(MockCall("C")));
            Assert.Equal(0, scheduler.GetPriorityLevel(MockCall("C")));
            Assert.Equal(1, scheduler.GetPriorityLevel(MockCall("A")));
            Assert.Equal(1, scheduler.GetPriorityLevel(MockCall("A")));
            Assert.Equal(1, scheduler.GetPriorityLevel(MockCall("A")));
            Assert.Equal(2, scheduler.GetPriorityLevel(MockCall("A")));
        }
コード例 #11
0
        public virtual void TestParseThresholds()
        {
            // Defaults vary by number of queues
            Configuration conf = new Configuration();

            scheduler = new DecayRpcScheduler(1, string.Empty, conf);
            AssertEqualDecimalArrays(new double[] {  }, scheduler.GetThresholds());
            scheduler = new DecayRpcScheduler(2, string.Empty, conf);
            AssertEqualDecimalArrays(new double[] { 0.5 }, scheduler.GetThresholds());
            scheduler = new DecayRpcScheduler(3, string.Empty, conf);
            AssertEqualDecimalArrays(new double[] { 0.25, 0.5 }, scheduler.GetThresholds());
            scheduler = new DecayRpcScheduler(4, string.Empty, conf);
            AssertEqualDecimalArrays(new double[] { 0.125, 0.25, 0.5 }, scheduler.GetThresholds
                                         ());
            // Custom
            conf = new Configuration();
            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerThresholdsKey, "1, 10, 20, 50, 85"
                     );
            scheduler = new DecayRpcScheduler(6, "ns", conf);
            AssertEqualDecimalArrays(new double[] { 0.01, 0.1, 0.2, 0.5, 0.85 }, scheduler.GetThresholds
                                         ());
        }
コード例 #12
0
        public virtual void TestDecay()
        {
            Configuration conf = new Configuration();

            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerPeriodKey, "999999999"
                     );
            // Never
            conf.Set("ns." + DecayRpcScheduler.IpcCallqueueDecayschedulerFactorKey, "0.5");
            scheduler = new DecayRpcScheduler(1, "ns", conf);
            Assert.Equal(0, scheduler.GetTotalCallSnapshot());
            for (int i = 0; i < 4; i++)
            {
                scheduler.GetPriorityLevel(MockCall("A"));
            }
            for (int i_1 = 0; i_1 < 8; i_1++)
            {
                scheduler.GetPriorityLevel(MockCall("B"));
            }
            Assert.Equal(12, scheduler.GetTotalCallSnapshot());
            Assert.Equal(4, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(8, scheduler.GetCallCountSnapshot()["B"]);
            scheduler.ForceDecay();
            Assert.Equal(6, scheduler.GetTotalCallSnapshot());
            Assert.Equal(2, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(4, scheduler.GetCallCountSnapshot()["B"]);
            scheduler.ForceDecay();
            Assert.Equal(3, scheduler.GetTotalCallSnapshot());
            Assert.Equal(1, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(2, scheduler.GetCallCountSnapshot()["B"]);
            scheduler.ForceDecay();
            Assert.Equal(1, scheduler.GetTotalCallSnapshot());
            Assert.Equal(null, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(1, scheduler.GetCallCountSnapshot()["B"]);
            scheduler.ForceDecay();
            Assert.Equal(0, scheduler.GetTotalCallSnapshot());
            Assert.Equal(null, scheduler.GetCallCountSnapshot()["A"]);
            Assert.Equal(null, scheduler.GetCallCountSnapshot()["B"]);
        }
コード例 #13
0
 public void SetDelegate(DecayRpcScheduler obj)
 {
     this.delegate_ = new WeakReference <DecayRpcScheduler>(obj);
 }
コード例 #14
0
 public virtual void TestZeroScheduler()
 {
     scheduler = new DecayRpcScheduler(0, string.Empty, new Configuration());
 }
コード例 #15
0
 public virtual void TestNegativeScheduler()
 {
     scheduler = new DecayRpcScheduler(-1, string.Empty, new Configuration());
 }