Пример #1
0
        internal void Setup()
        {
            RedisClientManager manager = REDIS_VERSION_DB.RedisManager;

            using (RedisClient client = manager.GetClient(REDIS_DB_INDEX, 0))
            {
                client.FlushDb();
            }
            Console.WriteLine("Flushed the database");

            int count = 0, redisInstances = REDIS_VERSION_DB.RedisManager.RedisInstanceCount;

            foreach (Worker worker in workers)
            {
                int partition = (worker.WorkerId - 1) % REDIS_VERSION_DB.RedisManager.RedisInstanceCount;

                // non-pipeline mode
                if (!this.pipelineMode)
                {
                    for (int i = 0; i < this.taskCountPerWorker; i++)
                    {
                        worker.EnqueueTxTask(new TxTask(ACTION, Tuple.Create(mockRedisWorkload(), partition)));
                    }
                }
                // pipeline mode
                else
                {
                    int             batchs    = this.taskCountPerWorker / this.pipelineSize;
                    RedisWorkload[] workloads = new RedisWorkload[this.pipelineSize];
                    for (int i = 0; i < batchs; i++)
                    {
                        for (int j = 0; j < this.pipelineSize; j++)
                        {
                            workloads[j] = mockRedisWorkload(3);
                        }
                        worker.EnqueueTxTask(new TxTask(PIPELINE_ACTION, Tuple.Create(workloads, partition)));
                    }
                }
                Console.WriteLine("Setup {0} workers", ++count);
            }

            for (int redisIndex = 0; redisIndex < redisInstances; redisIndex++)
            {
                Console.WriteLine("Redis Instance: {0} has {1} workers", redisIndex, this.workerCount / redisInstances);
            }
            Console.WriteLine("Filled the workers' queue");
        }
Пример #2
0
        private static RedisWorkload mockRedisWorkload(int type = -1)
        {
            RedisWorkload workload = new RedisWorkload();

            workload.hashId = RandomString(10);
            workload.key    = BitConverter.GetBytes(RAND.Next(0, int.MaxValue));
            workload.type   = (RedisWorkloadType)(type == -1 ? RAND.Next(0, 6) : type);
            if (workload.type == RedisWorkloadType.HGet ||
                workload.type == RedisWorkloadType.HGetAll ||
                workload.type == RedisWorkloadType.HMGet)
            {
                workload.value = null;
            }
            else
            {
                workload.value = RandomBytes(32);
            }
            return(workload);
        }