Exemplo n.º 1
0
        public void SchedulingStepDown()
        {
            ResponseLimitedConcurrencyTaskConfiguration config = new ResponseLimitedConcurrencyTaskConfiguration();

            config.MinimumSampleCount       = 2;
            config.SamplingRateMilliseconds = 250;
            config.AverageSampleCount       = 5;

            ResponseLimitedConcurrencyTaskScheduler rlcts = new ResponseLimitedConcurrencyTaskScheduler(GetSchedulerInit(), config);
            ParallelOptions options = new ParallelOptions();

            options.TaskScheduler = rlcts;

            // Should start with 5 threads and switch down to 3
            Parallel.For(
                0,
                50,
                options,
                (i) =>
            {
                Thread.Sleep(1000);
                Console.WriteLine("Finish Thread={0}, i={1}", Thread.CurrentThread.ManagedThreadId, i);
            }
                );

            rlcts.Dispose();
        }
Exemplo n.º 2
0
        public void SchedulingStepDownDirect()
        {
            ResponseLimitedConcurrencyTaskConfiguration config = new ResponseLimitedConcurrencyTaskConfiguration();

            config.MinimumSampleCount       = 2;
            config.SamplingRateMilliseconds = 250;
            config.AverageSampleCount       = 5;

            ResponseLimitedConcurrencyTaskScheduler rlcts = new ResponseLimitedConcurrencyTaskScheduler(GetSchedulerInit(), config);
            TaskFactory factory = new TaskFactory(rlcts);

            Task[] tasks = new Task[50];

            // Should start with 5 threads and switch down to 3
            for (int idx = 0; idx < 50; idx++)
            {
                int i = idx;
                tasks[i] = factory.StartNew(() =>
                {
                    Thread.Sleep(1000);
                    Console.WriteLine("Finish Thread={0}, i={1}", Thread.CurrentThread.ManagedThreadId, i);
                }
                                            );
            }

            Task.WaitAll(tasks);
            rlcts.Dispose();
        }
Exemplo n.º 3
0
        public void SchedulingLoaderLongRunningTest()
        {
            ResponseLimitedConcurrencyTaskConfiguration config = new ResponseLimitedConcurrencyTaskConfiguration();

            config.MinimumSampleCount       = 5;
            config.SamplingRateMilliseconds = 2000;
            config.AverageSampleCount       = 10;

            ResponseLimitedConcurrencyTaskScheduler rlcts  = new ResponseLimitedConcurrencyTaskScheduler(GetSchedulerInit(), config);
            ResponseLimitedConcurrencyActionLoader  loader = new ResponseLimitedConcurrencyActionLoader(rlcts);

            Action action = () =>
            {
                Thread.Sleep(1000);
                Console.WriteLine("Finish Thread={0}", Thread.CurrentThread.ManagedThreadId);
            };

            loader.Start(action);
            Thread.Sleep(5000);
            loader.StopAndWait();
        }