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(); }
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; }
protected ScheduledAsyncTask(AbstractScheduledEventExecutor executor, PreciseDeadline deadline, TaskCompletionSource promise, CancellationToken cancellationToken) : base(executor, deadline, promise) { _cancellationToken = cancellationToken; _cancellationTokenRegistration = cancellationToken.Register(CancellationAction, this); }
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); }
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); }
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(); }
public ActionScheduledAsyncTask(AbstractScheduledEventExecutor executor, Action action, PreciseDeadline deadline, CancellationToken cancellationToken) : base(executor, deadline, new TaskCompletionSource(), cancellationToken) { _action = action; }
public ActionScheduledTask(AbstractScheduledEventExecutor executor, Action action, PreciseDeadline deadline) : base(executor, deadline, new TaskCompletionSource()) { _action = action; }
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; }
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; }