Beispiel #1
0
        public void ProfilingMD_Ex2()
        {
            using (var c = Create())
            {
                ConnectionMultiplexer conn = c;
                var profiler = new ToyProfiler();

                conn.RegisterProfiler(profiler);

                var threads = new List <Thread>();

                var perThreadTimings = new ConcurrentDictionary <Thread, List <IProfiledCommand> >();

                for (var i = 0; i < 16; i++)
                {
                    var db = conn.GetDatabase(i);

                    var thread =
                        new Thread(
                            delegate()
                    {
                        var threadTasks = new List <Task>();

                        conn.BeginProfiling(Thread.CurrentThread);

                        for (var j = 0; j < 1000; j++)
                        {
                            var task = db.StringSetAsync("" + j, "" + j);
                            threadTasks.Add(task);
                        }

                        Task.WaitAll(threadTasks.ToArray());

                        perThreadTimings[Thread.CurrentThread] = conn.FinishProfiling(Thread.CurrentThread).ToList();
                    }
                            );

                    profiler.Contexts[thread] = thread;

                    threads.Add(thread);
                }

                threads.ForEach(thread => thread.Start());
                threads.ForEach(thread => thread.Join());

                Assert.AreEqual(16, perThreadTimings.Count);
                Assert.IsTrue(perThreadTimings.All(kv => kv.Value.Count == 1000));
            }
        }
Beispiel #2
0
        public void ProfilingMD_Ex1()
        {
            using (var c = Create())
            {
                ConnectionMultiplexer conn = c;
                var profiler         = new ToyProfiler();
                var thisGroupContext = new object();

                conn.RegisterProfiler(profiler);

                var threads = new List <Thread>();

                for (var i = 0; i < 16; i++)
                {
                    var db = conn.GetDatabase(i);

                    var thread =
                        new Thread(
                            delegate()
                    {
                        var threadTasks = new List <Task>();

                        for (var j = 0; j < 1000; j++)
                        {
                            var task = db.StringSetAsync("" + j, "" + j);
                            threadTasks.Add(task);
                        }

                        Task.WaitAll(threadTasks.ToArray());
                    }
                            );

                    profiler.Contexts[thread] = thisGroupContext;

                    threads.Add(thread);
                }

                conn.BeginProfiling(thisGroupContext);

                threads.ForEach(thread => thread.Start());
                threads.ForEach(thread => thread.Join());

                IEnumerable <IProfiledCommand> timings = conn.FinishProfiling(thisGroupContext);

                Assert.AreEqual(16000, timings.Count());
            }
        }
Beispiel #3
0
        public static void TestProfiling()
        {
            var profiler = new AsyncLocalProfiler();

            _redis.RegisterProfiler(profiler.GetSession);
            //var commands = profiler.GetSession().FinishProfiling();
            //Console.WriteLine(string.Join(",", commands.Select(p => p.ElapsedTime)));

            var toyProfiler = new ToyProfiler();

            //var sharedSession = new ProfilingSession();
            _redis.RegisterProfiler(() => toyProfiler.PerThreadSession);
            var threads          = new List <Thread>();
            var perThreadTimings = new ConcurrentDictionary <Thread, List <IProfiledCommand> >();

            for (int i = 0; i < 16; i++)
            {
                var db     = _redis.GetDatabase(i);
                var thread = new Thread(
                    delegate()
                {
                    //set each thread to share a session
                    //toyProfiler.PerThreadSession = sharedSession;
                    var threadTasks = new List <Task>();
                    toyProfiler.PerThreadSession = new ProfilingSession();
                    for (int j = 0; j < 1000; j++)
                    {
                        var task = db.StringSetAsync("" + j, "" + j);
                        threadTasks.Add(task);
                    }
                    Task.WaitAll(threadTasks.ToArray());
                    perThreadTimings[Thread.CurrentThread] = toyProfiler.PerThreadSession.FinishProfiling().ToList();
                });
                threads.Add(thread);
            }
            threads.ForEach(thread => thread.Start());
            threads.ForEach(thread => thread.Join());
            //var timings = sharedSession.FinishProfiling();
            Console.WriteLine(perThreadTimings.Count);
        }
Beispiel #4
0
        private void AssociateCommandsIssuedFromManyDifferentThreadsTogether1()
        {
            var toyProfiler1 = new ToyProfiler();
            var thisGroupContext = new object();
            Redis.RegisterProfiler(toyProfiler1);

            var threads = new List<Thread>();

            for (var i = 0; i < 16; i++)
            {
                var db = Redis.GetDatabase(i);

                var thread =
                    new Thread(
                        delegate ()
                        {
                            var threadTasks = new List<Task>();

                            for (var j = 0; j < 1000; j++)
                            {
                                var task = db.StringSetAsync("" + j, "" + j);
                                threadTasks.Add(task);
                            }

                            Task.WaitAll(threadTasks.ToArray());
                        });

                toyProfiler1.Contexts[thread] = thisGroupContext;

                threads.Add(thread);
            }

            Redis.BeginProfiling(thisGroupContext);

            threads.ForEach(thread => thread.Start());
            threads.ForEach(thread => thread.Join());

            IEnumerable<IProfiledCommand> timings = Redis.FinishProfiling(thisGroupContext);
        }
Beispiel #5
0
        private void AssociateCommandsIssuedFromManyDifferentThreadsTogether2()
        {
            var toyProfiler2 = new ToyProfiler();

            Redis.RegisterProfiler(toyProfiler2);

            var threads = new List<Thread>();

            var perThreadTimings = new ConcurrentDictionary<Thread, List<IProfiledCommand>>();

            for (var i = 0; i < 16; i++)
            {
                var db = Redis.GetDatabase(i);

                var thread =
                    new Thread(
                        delegate ()
                        {
                            var threadTasks = new List<Task>();

                            Redis.BeginProfiling(Thread.CurrentThread);

                            for (var j = 0; j < 1000; j++)
                            {
                                var task = db.StringSetAsync("" + j, "" + j);
                                threadTasks.Add(task);
                            }

                            Task.WaitAll(threadTasks.ToArray());

                            perThreadTimings[Thread.CurrentThread] = Redis.FinishProfiling(Thread.CurrentThread).ToList();
                        });

                toyProfiler2.Contexts[thread] = thread;

                threads.Add(thread);
            }
        }
        public void ProfilingMD_Ex2()
        {
            using (var c = Create())
            {
                ConnectionMultiplexer conn = c;
                var profiler = new ToyProfiler();

                conn.RegisterProfiler(profiler);

                var threads = new List<Thread>();

                var perThreadTimings = new ConcurrentDictionary<Thread, List<IProfiledCommand>>();

                for (var i = 0; i < 16; i++)
                {
                    var db = conn.GetDatabase(i);

                    var thread =
                        new Thread(
                            delegate()
                            {
                                var threadTasks = new List<Task>();

                                conn.BeginProfiling(Thread.CurrentThread);

                                for (var j = 0; j < 1000; j++)
                                {
                                    var task = db.StringSetAsync("" + j, "" + j);
                                    threadTasks.Add(task);
                                }

                                Task.WaitAll(threadTasks.ToArray());

                                perThreadTimings[Thread.CurrentThread] = conn.FinishProfiling(Thread.CurrentThread).ToList();
                            }
                        );

                    profiler.Contexts[thread] = thread;

                    threads.Add(thread);
                }
                
                threads.ForEach(thread => thread.Start());
                threads.ForEach(thread => thread.Join());

                Assert.AreEqual(16, perThreadTimings.Count);
                Assert.IsTrue(perThreadTimings.All(kv => kv.Value.Count == 1000));
            }
        }
        public void ProfilingMD_Ex1()
        {
            using (var c = Create())
            {
                ConnectionMultiplexer conn = c;
                var profiler = new ToyProfiler();
                var thisGroupContext = new object();

                conn.RegisterProfiler(profiler);

                var threads = new List<Thread>();

                for (var i = 0; i < 16; i++)
                {
                    var db = conn.GetDatabase(i);

                    var thread =
                        new Thread(
                            delegate()
                            {
                                var threadTasks = new List<Task>();

                                for (var j = 0; j < 1000; j++)
                                {
                                    var task = db.StringSetAsync("" + j, "" + j);
                                    threadTasks.Add(task);
                                }

                                Task.WaitAll(threadTasks.ToArray());
                            }
                        );

                    profiler.Contexts[thread] = thisGroupContext;

                    threads.Add(thread);
                }

                conn.BeginProfiling(thisGroupContext);

                threads.ForEach(thread => thread.Start());
                threads.ForEach(thread => thread.Join());

                IEnumerable<IProfiledCommand> timings = conn.FinishProfiling(thisGroupContext);

                Assert.AreEqual(16000, timings.Count());
            }
        }