public AgentLocalRunner( long id, uint queueSize, TContext context) { this.Id = id; this.queue = new MpmcRingBuffer <IAgentAsyncNode>(queueSize); this.context = context; }
public void AFillTest() { var buffer = new MpmcRingBuffer <ClassTest>(0x10); var value = new ClassTest(); for (long i = 0; i < 0x10; i++) { Assert.IsTrue(buffer.Offer(value)); } Assert.IsFalse(buffer.Offer(value)); }
public IncomingMessageProcessor( IMessageStore <TPayloadType, TBody, TMsgCtx> messageStore, IMessageRouter <TPayloadType, TBody, TMsgCtx> messageRouter, IOutgoingConnection <TPayloadType, TBody> outgoingConnection, IMessageResultFactory <TBody> messageResultFactory) { this.buffer = new MpmcRingBuffer <Message <TPayloadType, TBody> >(0x1000); this.outgoingConnection = outgoingConnection; this.messageResultFactory = messageResultFactory; this.messageStore = messageStore; this.messageRouter = messageRouter; this.semaphore = new FastSemaphore(100); }
static void Main(string[] args) { var buffer = new MpmcRingBuffer <MyTestClass>(0x4000000); var goThrough = 100_000_000; var threadCount = 2; var writeThreads = new Thread[threadCount]; var readThreads = new Thread[threadCount]; var value = new MyTestClass(); var stopWatch = new Stopwatch(); for (var i = 0; i < threadCount; i++) { writeThreads[i] = new Thread((obj) => { for (var j = 0; j < goThrough; j++) { buffer.Offer(value); } }); readThreads[i] = new Thread((obj) => { for (var j = 0; j < goThrough; j++) { buffer.TryPoll(out MyTestClass ignore); } }); } for (var i = 0; i < threadCount; i++) { writeThreads[i].Start(); readThreads[i].Start(); } stopWatch.Start(); for (var i = 0; i < threadCount; i++) { writeThreads[i].Join(); readThreads[i].Join(); } var time = stopWatch.ElapsedMilliseconds; File.WriteAllText(@"D:\Ran.txt", $"Ran in {time}"); }
public void DrainTest() { var buffer = new MpmcRingBuffer <ClassTest>(0x100); var goThrough = 10000; var threadCount = 5; var writeThreads = new Thread[threadCount]; var readThreads = new Thread[threadCount]; var value = new ClassTest(); for (var i = 0; i < threadCount; i++) { writeThreads[i] = new Thread((obj) => { for (var j = 0; j < goThrough; j++) { buffer.Offer(value); } }); readThreads[i] = new Thread((obj) => { for (var j = 0; j < goThrough; j++) { buffer.Drain((me) => { }, 100); } }); } for (var i = 0; i < threadCount; i++) { writeThreads[i].Start(); readThreads[i].Start(); } for (var i = 0; i < threadCount; i++) { writeThreads[i].Join(); readThreads[i].Join(); } }
public SkipQueue(uint size = 32) { this.primary = new MpmcRingBuffer <TNode>(size); this.defer = new MpmcRingBuffer <TNode>(size / 2); this.currentQueue = CurrentQueue.NormalQueue; }