示例#1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void shouldBeAbleToProgressUnderStressfulProcessorChanges(int orderingGuarantees) throws Exception
        private void ShouldBeAbleToProgressUnderStressfulProcessorChanges(int orderingGuarantees)
        {
            // given
            int            batches    = 100;
            int            processors = Runtime.Runtime.availableProcessors() * 10;
            Configuration  config     = new Configuration_OverriddenAnonymousInnerClass(this, Configuration.DEFAULT, processors);
            Stage          stage      = new StressStage(config, orderingGuarantees, batches);
            StageExecution execution  = stage.Execute();
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: java.util.List<Step<?>> steps = asList(execution.steps());
            IList <Step <object> > steps = new IList <Step <object> > {
                execution.Steps()
            };

            steps[1].Processors(processors / 3);

            // when
            ThreadLocalRandom random = ThreadLocalRandom.current();

            while (execution.StillExecuting())
            {
                steps[2].Processors(random.Next(-2, 5));
                Thread.Sleep(1);
            }
            execution.AssertHealthy();

            // then
            assertEquals(batches, steps[steps.Count - 1].Stats().stat(Keys.done_batches).asLong());
        }
示例#2
0
 public override void Check(StageExecution execution)
 {
     if (execution.StillExecuting())
     {
         int permits = _availableProcessors - CountActiveProcessors(execution);
         if (permits > 0)
         {
             // Be swift at assigning processors to slow steps, i.e. potentially multiple per round
             AssignProcessorsToPotentialBottleNeck(execution, permits);
         }
         // Be a little more conservative removing processors from too fast steps
         RemoveProcessorFromPotentialIdleStep(execution);
     }
 }
示例#3
0
        /// <summary>
        /// Supervises <seealso cref="StageExecution"/>, provides continuous information to the <seealso cref="ExecutionMonitor"/>
        /// and returns when the execution is done or an error occurs, in which case an exception is thrown.
        ///
        /// Made synchronized to ensure that only one set of executions take place at any given time
        /// and also to make sure the calling thread goes through a memory barrier (useful both before and after execution).
        /// </summary>
        /// <param name="execution"> <seealso cref="StageExecution"/> instances to supervise simultaneously. </param>
        public virtual void Supervise(StageExecution execution)
        {
            lock (this)
            {
                long startTime = CurrentTimeMillis();
                Start(execution);

                while (execution.StillExecuting())
                {
                    FinishAwareSleep(execution);
                    _monitor.check(execution);
                }
                End(execution, CurrentTimeMillis() - startTime);
            }
        }
示例#4
0
        private int CountActiveProcessors(StageExecution execution)
        {
            float processors = 0;

            if (execution.StillExecuting())
            {
                long highestAverage = Avg(execution.StepsOrderedBy(Keys.avg_processing_time, false).GetEnumerator().next().first());
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: for (Step<?> step : execution.steps())
                foreach (Step <object> step in execution.Steps())
                {
                    // Calculate how active each step is so that a step that is very cheap
                    // and idles a lot counts for less than 1 processor, so that bottlenecks can
                    // "steal" some of its processing power.
                    long  avg    = avg(step);
                    float factor = ( float )avg / ( float )highestAverage;
                    processors += factor * step.Processors(0);
                }
            }
            return(( int )Math.Round(processors, MidpointRounding.AwayFromZero));
        }
示例#5
0
        private void FinishAwareSleep(StageExecution execution)
        {
            long endTime = _monitor.nextCheckTime();

            while (CurrentTimeMillis() < endTime)
            {
                if (!execution.StillExecuting())
                {
                    break;
                }

                try
                {
                    sleep(min(10, max(0, endTime - CurrentTimeMillis())));
                }
                catch (InterruptedException e)
                {
                    execution.Panic(e);
                    break;
                }
            }
        }