public async Task Test_Queue_Performance(IMpScQueue <IWorkItem> queueWorkItem) { _TestOutputHelper.WriteLine(queueWorkItem.GetType().Name); var fiber = GetSafeFiber(queueWorkItem); var reset = new AutoResetEvent(false); const int max = 5000000; Action <int> @do = (count) => { if (count == max) { reset.Set(); } }; using (GetPerfTimer(max)) { for (var i = 0; i <= max; i++) { var i1 = i; fiber.Dispatch(() => @do(i1)); } reset.WaitOne(30000, false).Should().BeTrue(); } await fiber.DisposeAsync(); }
public async Task Test_Queue_Performance(IMpScQueue <IWorkItem> queueWorkItem) { Output(queueWorkItem.GetType().Name); var fiber = new MonoThreadedFiber(null, queueWorkItem); var factory = _FactoryBuilder.GetFactoryForFiber(fiber); await TestNoTask(factory); await fiber.DisposeAsync(); }
public MonoThreadedFiber(Action <Thread> onCreate = null, IMpScQueue <IWorkItem> queue = null) { _TaskQueue = queue ?? new BlockingMpscQueue <IWorkItem>(); _Current = new Thread(Consume) { IsBackground = true, Name = $"MonoThreadedQueue-{_Count++}" }; onCreate?.Invoke(_Current); _Current.Start(); }
protected IMonoThreadFiber GetSafeFiber(IMpScQueue <IWorkItem> queue) { var fiber = GetFiber(queue); return(_Disposables.Add(fiber)); }
protected abstract IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue);
protected override IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue) => new MonoThreadedFiber(null, queue);
protected override IMonoThreadFiber GetFiber(IMpScQueue <IWorkItem> queue) => new ThreadPoolFiber(queue);
public ThreadPoolFiber(IMpScQueue <IWorkItem> queue = null) { _TaskQueue = queue ?? new BlockingMpscQueue <IWorkItem>(); ThreadPool.QueueUserWorkItem(_ => Consume()); }