public void MassiveBulkOpsSync(bool preserveOrder, int threads) { int workPerThread = SyncOpsQty / threads; using (var muxer = Create()) { muxer.PreserveAsyncOrder = preserveOrder; RedisKey key = "MBOS"; var conn = muxer.GetDatabase(); conn.KeyDelete(key); #if DEBUG long oldAlloc = ConnectionMultiplexer.GetResultBoxAllocationCount(); long oldWorkerCount = ConnectionMultiplexer.GetAsyncCompletionWorkerCount(); #endif var timeTaken = RunConcurrent(delegate { for (int i = 0; i < workPerThread; i++) { conn.StringIncrement(key); } }, threads); int val = (int)conn.StringGet(key); Assert.AreEqual(workPerThread * threads, val); Console.WriteLine("{2}: Time for {0} ops on {4} threads: {1}ms ({3}); ops/s: {5}", threads * workPerThread, timeTaken.TotalMilliseconds, Me() , preserveOrder ? "preserve order" : "any order", threads, (workPerThread * threads) / timeTaken.TotalSeconds); #if DEBUG long newAlloc = ConnectionMultiplexer.GetResultBoxAllocationCount(); long newWorkerCount = ConnectionMultiplexer.GetAsyncCompletionWorkerCount(); Console.WriteLine("ResultBox allocations: {0}; workers {1}", newAlloc - oldAlloc, newWorkerCount - oldWorkerCount); Assert.IsTrue(newAlloc - oldAlloc <= 2 * threads, "number of box allocations"); #endif } }
public void MassiveBulkOpsAsync(bool preserveOrder, bool withContinuation) { #if DEBUG var oldAsyncCompletionCount = ConnectionMultiplexer.GetAsyncCompletionWorkerCount(); #endif using (var muxer = Create()) { muxer.PreserveAsyncOrder = preserveOrder; RedisKey key = "MBOA"; var conn = muxer.GetDatabase(); muxer.Wait(conn.PingAsync()); Action<Task> nonTrivial = delegate { Thread.SpinWait(5); }; var watch = Stopwatch.StartNew(); for (int i = 0; i <= AsyncOpsQty; i++) { var t = conn.StringSetAsync(key, i); if (withContinuation) t.ContinueWith(nonTrivial); } int val = (int)muxer.Wait(conn.StringGetAsync(key)); Assert.AreEqual(AsyncOpsQty, val); watch.Stop(); Console.WriteLine("{2}: Time for {0} ops: {1}ms ({3}, {4}); ops/s: {5}", AsyncOpsQty, watch.ElapsedMilliseconds, Me(), withContinuation ? "with continuation" : "no continuation", preserveOrder ? "preserve order" : "any order", AsyncOpsQty / watch.Elapsed.TotalSeconds); #if DEBUG Console.WriteLine("Async completion workers: " + (ConnectionMultiplexer.GetAsyncCompletionWorkerCount() - oldAsyncCompletionCount)); #endif } }
public async Task MassiveBulkOpsAsync(bool preserveOrder, bool withContinuation) { #if DEBUG var oldAsyncCompletionCount = ConnectionMultiplexer.GetAsyncCompletionWorkerCount(); #endif using (var muxer = Create()) { muxer.PreserveAsyncOrder = preserveOrder; RedisKey key = "MBOA"; var conn = muxer.GetDatabase(); await conn.PingAsync().ForAwait(); #if NETCOREAPP1_0 int number = 0; #endif Action <Task> nonTrivial = delegate { #if NETCOREAPP1_0 for (int i = 0; i < 50; i++) { number++; } #else Thread.SpinWait(5); #endif }; var watch = Stopwatch.StartNew(); for (int i = 0; i <= AsyncOpsQty; i++) { var t = conn.StringSetAsync(key, i); #pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed if (withContinuation) { t.ContinueWith(nonTrivial); } #pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed } Assert.Equal(AsyncOpsQty, await conn.StringGetAsync(key).ForAwait()); watch.Stop(); Output.WriteLine("{2}: Time for {0} ops: {1}ms ({3}, {4}); ops/s: {5}", AsyncOpsQty, watch.ElapsedMilliseconds, Me(), withContinuation ? "with continuation" : "no continuation", preserveOrder ? "preserve order" : "any order", AsyncOpsQty / watch.Elapsed.TotalSeconds); #if DEBUG Output.WriteLine("Async completion workers: " + (ConnectionMultiplexer.GetAsyncCompletionWorkerCount() - oldAsyncCompletionCount)); #endif } }