Example #1
0
        private void TestMassivePublishWithWithoutFlush(RedisConnection conn, string caption)
        {
            const int loop = 100000;

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            var tasks = new Task[loop];
            var withFlush = Stopwatch.StartNew();
            for (int i = 0; i < loop; i++)
                tasks[i] = conn.Publish("foo", "bar");
            conn.WaitAll(tasks);
            withFlush.Stop();

            GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced);
            GC.WaitForPendingFinalizers();

            conn.SuspendFlush();
            var withoutFlush = Stopwatch.StartNew();
            for (int i = 0; i < loop; i++)
                tasks[i] = conn.Publish("foo", "bar");
            conn.ResumeFlush();
            conn.WaitAll(tasks);
            withoutFlush.Stop();

            Assert.Less(1, 2, "sanity check");
            Assert.Less(withoutFlush.ElapsedMilliseconds, withFlush.ElapsedMilliseconds, caption);
            Console.WriteLine("{2}: {0}ms (eager-flush) vs {1}ms (suspend-flush)",
                withFlush.ElapsedMilliseconds, withoutFlush.ElapsedMilliseconds, caption);
        }