Example #1
0
 public void ExecuteInsertsAndReads(string value, int numberOfOperations)
 {
     try
     {
         for (int index = 0; index < numberOfOperations; index += 1)
         {
             CacheProvider.SetItem($"Key-{index}", value);
             CacheProvider.GetItem($"Key-{index}");
         }
     }
     catch (Exception e)
     {
         logger.Error(e);
         throw;
     }
 }
 public void ExecuteInserts(ConcurrentStack <string> keys, string value, int numberOfTimes)
 {
     try
     {
         for (int index = 0; index < numberOfTimes; index += 1)
         {
             keys.TryPop(out string key);
             CacheProvider.SetItem(key, value);
         }
     }
     catch (Exception e)
     {
         logger.Error(e);
         throw;
     }
 }
Example #3
0
        static void Main(string[] args)
        {
            string data;

            using (var sr = new StreamReader(@"D:\Work Related\Redis Stress Test\Redis-Stress-Test\StressTest.App\Sample.json"))
            {
                data = sr.ReadToEnd();
            }

            var logger = new AppLogger();


            var executor = new RedisExecutor(logger);

            int.TryParse(ConfigurationManager.AppSettings["threadsNumber"], out int threadsNumber);
            int.TryParse(ConfigurationManager.AppSettings["operationsNumber"], out int operationsNumber);
            int.TryParse(ConfigurationManager.AppSettings["secondsNumber"], out int secondsToRun);

            Task[] tasks = new Task[threadsNumber];
            executor.InitializeKeys(threadsNumber, operationsNumber);


            logger.Info($"Starting with {threadsNumber} threads and {operationsNumber} operations.");

            var watcher = new Stopwatch();

            watcher.Start();
            do
            {
                //insert data
                for (int index = 0; index < threadsNumber; index += 1)
                {
                    try
                    {
                        tasks[index] =
                            Task.Factory.StartNew(() =>
                                                  executor.ExecuteInserts(executor.InitializeKeys(threadsNumber, operationsNumber), data, operationsNumber));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                        throw;
                    }
                }
                //get data
                for (int index = 0; index < threadsNumber; index += 1)
                {
                    try
                    {
                        tasks[index] =
                            Task.Factory.StartNew(() =>
                                                  executor.ExecuteReads(executor.InitializeKeys(threadsNumber, operationsNumber), operationsNumber));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                        throw;
                    }
                }
                //delete data
                for (int index = 0; index < threadsNumber; index += 1)
                {
                    try
                    {
                        tasks[index] =
                            Task.Factory.StartNew(() =>
                                                  executor.ExecuteDeletes(executor.InitializeKeys(threadsNumber, operationsNumber), operationsNumber));
                    }
                    catch (Exception e)
                    {
                        logger.Error(e);
                        throw;
                    }
                }
            }while (watcher.Elapsed < TimeSpan.FromSeconds(secondsToRun));



            Console.ReadLine();
        }