设为首页 加入收藏

TOP

CYQ.Data 对于分布式缓存Redis、MemCache高可用的改进及性能测试(二)
2019-09-17 18:57:21 】 浏览:67
Tags:CYQ.Data 对于 分布式 Redis MemCache 可用 改进 性能 测试
s、Clear。

统一了所有类型并保持最简单的缓存操作接口。

最后,献上测试代码:

 AppConfig.Cache.RedisServers = "127.0.0.1:6379";//,127.0.0.1:6380 - c123456,127.0.0.1:6381 - c123456,127.0.0.1:6382 - c123456,127.0.0.1:6383 - c123456";
            //AppConfig.Cache.RedisServers = "redis.txt";
            //AppConfig.Cache.RedisServersBak = "redis.bak.txt";


            int readCount = 100000, userDBCount = 1;
            ThreadPool.SetMaxThreads(1000, 1000);
           

            new ThreadRun(1, readCount, userDBCount).Start();
            new ThreadRun(4, readCount, userDBCount).Start();
            new ThreadRun(8, readCount, userDBCount).Start();
            new ThreadRun(10, readCount, userDBCount).Start();
            new ThreadRun(20, readCount, userDBCount).Start();
            new ThreadRun(50, readCount, userDBCount).Start();
            new ThreadRun(100, readCount, userDBCount).Start();
            new ThreadRun(200, readCount, userDBCount).Start();
            new ThreadRun(500, readCount, userDBCount).Start();
            new ThreadRun(1000, readCount, userDBCount).Start();
            new ThreadRun(2000, readCount, userDBCount).Start();

            new ThreadRun(5000, readCount, userDBCount).Start();
            new ThreadRun(2000, readCount, userDBCount).Start();
            new ThreadRun(2000, readCount, userDBCount).Start();
            new ThreadRun(500, readCount, userDBCount).Start();
            new ThreadRun(200, readCount, userDBCount).Start();
            new ThreadRun(100, readCount, userDBCount).Start();
            new ThreadRun(50, readCount, userDBCount).Start();
            new ThreadRun(20, readCount, userDBCount).Start();
            new ThreadRun(10, readCount, userDBCount).Start();
            new ThreadRun(8, readCount, userDBCount).Start();
            new ThreadRun(4, readCount, userDBCount).Start();
            new ThreadRun(1, readCount, userDBCount).Start();
            CacheManage.RedisInstance.Clear();//操作对象
            Console.WriteLine("End");
            Console.WriteLine(CacheManage.RedisInstance.WorkInfo);
            Console.WriteLine(CacheManage.RedisInstance.CacheInfo.ToJson(false, false));
----------------------------------------------------------
 public class ThreadRun
    {
        int threadCount, setOrReadCount, useDBCount;
        CacheManage cache;
        public ThreadRun(int threadCount, int setOrReadCount, int useDBCount)
        {
            cache = CacheManage.RedisInstance;//操作对象
            cache.Clear();
            this.threadCount = threadCount;
            this.setOrReadCount = setOrReadCount;
            this.useDBCount = useDBCount;
        }
        System.Diagnostics.Stopwatch gloWatch = new System.Diagnostics.Stopwatch();
        int runEndCount = 0;
        bool isEnd = false;
        public void Start()
        {
            AppConfig.Cache.RedisUseDBCount = useDBCount;
           
            gloWatch.Start();
            for (int i = 0; i < threadCount; i++)
            {
                ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadStart), setOrReadCount / threadCount);
            }
           
            while (!isEnd)
            {
                Thread.Sleep(10);
            }

        }

        public void ThreadStart(object readCount)
        {
            string rndKey = Guid.NewGuid().ToString().Substring(0, 5);
            int max = (int)readCount;
            for (int i = 0; i < max; i++)
            {
                string key = rndKey + "key" + i;
                if(cache.Set(key, Guid.NewGuid().ToString()))
                {

                }
                else
                {
                    Console.WriteLine("Set 失败 key :" + key);
                }

            }

            Interlocked.Increment(ref runEndCount);
            if (runEndCount >= threadCount && !isEnd)
            {
                isEnd = true;
                //gloWatch.Stop();
                //Ng  2000ms
                //x     1000ms
                long t = gloWatch.ElapsedMilliseconds;
                Console.
首页 上一页 1 2 3 下一页 尾页 2/3/3
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇.NET MVC全局异常处理(二) 下一篇MobileForm控件的使用方式-用.NET..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目