public void TcpServerSocketChannel_horizontal_scale_stress_test(BenchmarkContext context)
        {
            _clientConnectedCounter.Increment(); // for the initial client
            var totalRunSeconds = TotalRunSeconds;

            Console.WriteLine("Running benchmark for {0} minutes", totalRunSeconds.TotalMinutes);
            var deadline    = new PreciseDeadline(totalRunSeconds);
            var due         = DateTime.Now + totalRunSeconds;
            var lastMeasure = due;
            var task        = Task.Factory.StartNew(_eventLoop); // start writing
            var runCount    = 1;

            while (!deadline.IsOverdue)
            {
                // add a new client
                _clientChannels.Add(ClientBootstrap.ConnectAsync(_serverChannel.LocalAddress).Result);
                _clientConnectedCounter.Increment();
                Thread.Sleep(SleepInterval);
                if (++runCount % 10 == 0)
                {
                    Console.WriteLine("{0} minutes remaining [{1} connections active].",
                                      (due - DateTime.Now).TotalMinutes, runCount);
                    var saturation = (DateTime.Now - lastMeasure);
                    if (saturation > SaturationThreshold)
                    {
                        Console.WriteLine(
                            "Took {0} to create 10 connections; exceeded pre-defined saturation threshold of {1}. Ending stress test.",
                            saturation, SaturationThreshold);
                        break;
                    }
                    lastMeasure = DateTime.Now;
                }
            }
            _shutdownBenchmark.Cancel();
        }
예제 #2
0
 protected ScheduledTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline,
     TaskCompletionSource promise)
 {
     Executor = executor;
     Deadline = deadline;
     Promise = promise;
 }
 public ActionWithStateAndContextScheduledTask(AbstractScheduledEventExecutor executor,
     Action<object, object> action, object context, object state, PreciseDeadline deadline)
     : base(executor, deadline, new TaskCompletionSource(state))
 {
     _action = action;
     _context = context;
 }
예제 #4
0
 protected ScheduledAsyncTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline,
                              TaskCompletionSource promise, CancellationToken cancellationToken)
     : base(executor, deadline, promise)
 {
     _cancellationToken             = cancellationToken;
     _cancellationTokenRegistration = cancellationToken.Register(CancellationAction, this);
 }
예제 #5
0
 protected ScheduledAsyncTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline,
     TaskCompletionSource promise, CancellationToken cancellationToken)
     : base(executor, deadline, promise)
 {
     _cancellationToken = cancellationToken;
     _cancellationTokenRegistration = cancellationToken.Register(CancellationAction, this);
 }
예제 #6
0
 protected ScheduledTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline,
                         TaskCompletionSource promise)
 {
     Executor = executor;
     Deadline = deadline;
     Promise  = promise;
 }
예제 #7
0
        public void PreciseDeadline_should_correctly_report_overdue_time()
        {
            var deadline = new PreciseDeadline(TimeSpan.FromMilliseconds(20));

            Task.Delay(TimeSpan.FromMilliseconds(50)).Wait();
            Assert.True(deadline.IsOverdue);
        }
예제 #8
0
        public override Task GracefulShutdownAsync(TimeSpan quietPeriod, TimeSpan timeout)
        {
            Contract.Requires(quietPeriod >= TimeSpan.Zero);
            Contract.Requires(timeout >= quietPeriod);

            if (IsShuttingDown)
            {
                return(TerminationTask);
            }

            int  oldState;
            var  inEventLoop = InEventLoop;
            bool wakeup;

            while (true)
            {
                if (IsShuttingDown)
                {
                    return(TerminationTask);
                }
                int newState;
                wakeup   = true;
                oldState = _runningState;
                if (inEventLoop)
                {
                    newState = ST_SHUTTING_DOWN;
                }
                else
                {
                    switch (oldState)
                    {
                    case ST_NOT_STARTED:
                    case ST_STARTED:
                        newState = ST_SHUTTING_DOWN;
                        break;

                    default:
                        newState = oldState;
                        wakeup   = false;
                        break;
                    }
                }
                if (Interlocked.CompareExchange(ref _runningState, newState, oldState) == oldState)
                {
                    break;
                }
            }

            _gracefulShutdownQuietPeriod = MonotonicClock.ElapsedHighRes + quietPeriod;
            _gracefulShutdownTimeout     = PreciseDeadline.Now + timeout;

            if (wakeup)
            {
                Wakeup(inEventLoop);
            }

            return(TerminationTask);
        }
예제 #9
0
 public ActionWithStateScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action <object> action,
                                          object state, PreciseDeadline deadline, CancellationToken cancellationToken)
     : base(executor, deadline, new TaskCompletionSource(state), cancellationToken)
 {
     _action = action;
 }
 public void TcpServerSocketChannel_horizontal_scale_stress_test(BenchmarkContext context)
 {
     _clientConnectedCounter.Increment(); // for the initial client
     var totalRunSeconds = TotalRunSeconds;
     Console.WriteLine("Running benchmark for {0} minutes", totalRunSeconds.TotalMinutes);
     var deadline = new PreciseDeadline(totalRunSeconds);
     var due = DateTime.Now + totalRunSeconds;
     var lastMeasure = due;
     var task = Task.Factory.StartNew(_eventLoop); // start writing
     var runCount = 1;
     while (!deadline.IsOverdue)
     {
         // add a new client
         _clientChannels.Add(ClientBootstrap.ConnectAsync(_serverChannel.LocalAddress).Result);
         _clientConnectedCounter.Increment();
         Thread.Sleep(SleepInterval);
         if (++runCount%10 == 0)
         {
             Console.WriteLine("{0} minutes remaining [{1} connections active].",
                 (due - DateTime.Now).TotalMinutes, runCount);
             var saturation = (DateTime.Now - lastMeasure);
             if (saturation > SaturationThreshold)
             {
                 Console.WriteLine(
                     "Took {0} to create 10 connections; exceeded pre-defined saturation threshold of {1}. Ending stress test.",
                     saturation, SaturationThreshold);
                 break;
             }
             lastMeasure = DateTime.Now;
         }
     }
     _shutdownBenchmark.Cancel();
 }
예제 #11
0
 public ActionScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, PreciseDeadline deadline,
                                 CancellationToken cancellationToken)
     : base(executor, deadline, new TaskCompletionSource(), cancellationToken)
 {
     _action = action;
 }
예제 #12
0
 public ActionScheduledTask(AbstractScheduledEventExecutor executor, Action action, PreciseDeadline deadline)
     : base(executor, deadline, new TaskCompletionSource())
 {
     _action = action;
 }
예제 #13
0
        public override Task GracefulShutdownAsync(TimeSpan quietPeriod, TimeSpan timeout)
        {
            Contract.Requires(quietPeriod >= TimeSpan.Zero);
            Contract.Requires(timeout >= quietPeriod);

            if (IsShuttingDown)
                return TerminationTask;

            int oldState;
            var inEventLoop = InEventLoop;
            bool wakeup;
            while (true)
            {
                if (IsShuttingDown)
                    return TerminationTask;
                int newState;
                wakeup = true;
                oldState = _runningState;
                if (inEventLoop)
                {
                    newState = ST_SHUTTING_DOWN;
                }
                else
                {
                    switch (oldState)
                    {
                        case ST_NOT_STARTED:
                        case ST_STARTED:
                            newState = ST_SHUTTING_DOWN;
                            break;
                        default:
                            newState = oldState;
                            wakeup = false;
                            break;
                    }
                }
                if (Interlocked.CompareExchange(ref _runningState, newState, oldState) == oldState)
                {
                    break;
                }
            }

            _gracefulShutdownQuietPeriod = MonotonicClock.ElapsedHighRes + quietPeriod;
            _gracefulShutdownTimeout = PreciseDeadline.Now + timeout;

            if (wakeup)
            {
                Wakeup(inEventLoop);
            }

            return TerminationTask;
        }
예제 #14
0
 public ActionScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, PreciseDeadline deadline,
     CancellationToken cancellationToken)
     : base(executor, deadline, new TaskCompletionSource(), cancellationToken)
 {
     _action = action;
 }
 public ActionWithStateScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action<object> action,
     object state, PreciseDeadline deadline, CancellationToken cancellationToken)
     : base(executor, deadline, new TaskCompletionSource(state), cancellationToken)
 {
     _action = action;
 }
 public ActionWithStateAndContextScheduledTask(AbstractScheduledEventExecutor executor,
                                               Action <object, object> action, object context, object state, PreciseDeadline deadline)
     : base(executor, deadline, new TaskCompletionSource(state))
 {
     _action  = action;
     _context = context;
 }
예제 #17
0
 public void PreciseDeadline_should_correctly_report_overdue_time()
 {
     var deadline = new PreciseDeadline(TimeSpan.FromMilliseconds(20));
     Task.Delay(TimeSpan.FromMilliseconds(50)).Wait();
     Assert.True(deadline.IsOverdue);
 }