public void A_cluster_must_startup_with_one_dispatcher_thread() { // This test failed before fixing https://github.com/akkadotnet/akka.net/issues/1959 when adding a sleep before the // Await of GetClusterCoreRef in the Cluster extension constructor. // The reason was that other cluster actors were started too early and // they also tried to get the Cluster extension and thereby blocking // dispatcher threads. // Note that the Cluster extension is started via ClusterActorRefProvider // before ActorSystem.apply returns, i.e. in the constructor of AkkaSpec. var totalStartupTime = TimeSpan.FromTicks(MonotonicClock.GetTicks() - _startTime).TotalMilliseconds; Assert.True(totalStartupTime < (Sys.Settings.CreationTimeout - TimeSpan.FromSeconds(2)).TotalMilliseconds); Sys.ActorOf(TestProps).Tell("hello"); Sys.ActorOf(TestProps).Tell("hello"); Sys.ActorOf(TestProps).Tell("hello"); var cluster = Cluster.Get(Sys); totalStartupTime = TimeSpan.FromTicks(MonotonicClock.GetTicks() - _startTime).TotalMilliseconds; Assert.True(totalStartupTime < (Sys.Settings.CreationTimeout - TimeSpan.FromSeconds(2)).TotalMilliseconds); ExpectMsg("hello"); ExpectMsg("hello"); ExpectMsg("hello"); }
private DefaultChannelId() { unchecked { _hashCode = (int)(MonotonicClock.GetTicks() & 0xFFFFFFFF); _hashCode *= _hashCode ^ ThreadLocalRandom.Current.Next(); } }
private void FetchFromScheduledTaskQueue() { if (HasScheduledTasks()) { var tickCount = MonotonicClock.GetTicks(); while (true) { var scheduledTask = PollScheduledTask(tickCount); if (scheduledTask == null) { break; } _taskQueue.Enqueue(scheduledTask); } } }
protected static long GetTicks() { return(MonotonicClock.GetTicks()); }
private void ProcessMailbox(int left, long deadlineTicks) { while (ShouldProcessMessage()) { if (!TryDequeue(out var next)) { return; } DebugPrint("{0} processing message {1}", Actor.Self, next); // not going to bother catching ThreadAbortExceptions here, since they'll get rethrown anyway Actor.Invoke(next); ProcessAllSystemMessages(); if (left > 1 && (Dispatcher.ThroughputDeadlineTime.HasValue == false || (MonotonicClock.GetTicks() - deadlineTicks) < 0)) { left = left - 1; continue; } break; } }
public StartupWithOneThreadSpec() : base(Configuration) { _startTime = MonotonicClock.GetTicks(); }
public PreciseDeadline(TimeSpan timespan) : this(timespan.Ticks + MonotonicClock.GetTicks()) { }
private IRunnable PollTask() { Contract.Assert(InEventLoop); IRunnable task; if (!_taskQueue.TryDequeue(out task)) { _emptyQueueEvent.Reset(); if (!_taskQueue.TryDequeue(out task) && !IsShuttingDown) // revisit queue as producer might have put a task in meanwhile { var nextScheduledTask = ScheduledTaskQueue.Peek(); if (nextScheduledTask != null) { var wakeupTimeout = new TimeSpan(nextScheduledTask.Deadline.When - MonotonicClock.GetTicks()); if (wakeupTimeout.Ticks > 0) { if (_emptyQueueEvent.Wait(wakeupTimeout)) { // woken up before the next scheduled task was due _taskQueue.TryDequeue(out task); } } } else { _emptyQueueEvent.Wait(); // wait until work is put into the queue _taskQueue.TryDequeue(out task); } } } return(task); }