private void CalculateRequestTest(ObjectSize size, int loops, double addSeconds) { Console.WriteLine(@"ClearCache!"); Common.Util.CacheClear(); string result1 = string.Empty; string result2 = string.Empty; string result3 = string.Empty; Console.WriteLine(@"Step 1: The clients loads {0} objects with an appox. size of {1} kb", loops, size.ToString()); List<TestSizeObject> testObjectList = new List<TestSizeObject>(); for (int i = 0; i < loops; ++i) { if (i % 10 == 0) Console.Write(". "); testObjectList.Add(new TestSizeObject(size)); } Console.WriteLine(); Console.WriteLine(@"Client is done to load the data"); Console.WriteLine("Step 2: Adding all items into cache"); DateTime start = DateTime.Now; foreach (TestSizeObject o in testObjectList) { Common.Util.CacheAdd(o.Id, o, DateTime.Now.AddSeconds(addSeconds)); } TimeSpan span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); result1 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine(result1); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.WriteLine(@"Step 3: Retrieve each item from cache"); List<string> keyList = Common.Util.CacheGetAllKeys(); int success = 0; int failed = 0; TestSizeObject o2 = null ; start = DateTime.Now; foreach (string key in keyList) { o2 = Common.Util.CacheGet<TestSizeObject>(key); if (o2 != null) ++success; else ++failed; o2 = null; } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); result2 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi / success {4} - failed {5}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds, success, failed); Console.WriteLine(result2); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.WriteLine(); Console.WriteLine(@"Step 4: Remove each item by key... NOT ALL AT ONCE!"); start = DateTime.Now; foreach (string key in keyList) { Common.Util.CacheRemove(key); } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); result3 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine(result3); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.Clear(); Console.WriteLine(); Console.WriteLine("Using {0} roundtrips with an amount of approx.: {1}", loops, size.ToString()); Console.WriteLine("- - - - - - - - - - - - - - - - - - - - - - - - - - -"); // Console.WriteLine(@"Overview {0}:", lastSelectMenuOption); Console.WriteLine(@"Result 1:" + result1); Console.WriteLine(@"Result 2:" + result2); Console.WriteLine(@"Result 3:" + result3); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(@"Free Memory"); for (int i = 0; i < testObjectList.Count; ++i) { testObjectList[i] = null; } testObjectList = null; Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.Clear(); GC.Collect(); }
private void MultiOperation(ObjectSize objectSize, int p) { Console.Clear(); Console.WriteLine(@"Adding {0} items to cache with apporx. {1} kb. Please ensure you have defined more then 1 server node!!", p, objectSize.ToString()); List<string> keys = new List<string>(); string keyPrefix = string.Format("ThreadID-{0}-MultiGet:", System.Threading.Thread.CurrentThread.ManagedThreadId); Dictionary<string, byte[]> multiDataToAdd = new Dictionary<string, byte[]>(); for (int i = 0; i < p; i++) { if(i%10 == 0) Console.Write(". "); multiDataToAdd.Add(keyPrefix + i.ToString(), COM.Formatters.Serialization.BinarySerialize( new TestSizeObject(objectSize) ) ); keys.Add(keyPrefix + i.ToString()); } Console.WriteLine(); System.Diagnostics.Stopwatch sp = new System.Diagnostics.Stopwatch(); sp.Start(); Common.Util.CacheMultiAdd(multiDataToAdd); sp.Stop(); Console.WriteLine(@"Multi Add: {0} ms", sp.ElapsedMilliseconds); sp.Start(); IDictionary<string, byte[]> data = Common.Util.CacheMultiGet(keys); sp.Stop(); Console.WriteLine(@"Multi Get: {0} ms - received items: {1}", sp.ElapsedMilliseconds, data != null ? data.Count.ToString() : "0"); #region Commented //if (data != null) //{ // Console.WriteLine("Total amount of received items: {0}", data.Count); // foreach (KeyValuePair<string, byte[]> item in data) // { // Console.WriteLine("Item with key {0} was available", item.Key); // } //} //else //{ // Console.WriteLine("no data received !!!"); //} #endregion sp.Start(); Common.Util.CacheMultiDelete(keys); sp.Stop(); Console.WriteLine(@"Multi Del: {0} ms", sp.ElapsedMilliseconds); Console.WriteLine(); Console.WriteLine(@"Operation Done"); Console.WriteLine(@"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); Console.WriteLine(); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.Clear(); }
private void CompareObjectWithAndWithoutList(ObjectSize size, int loops) { Console.Clear(); Console.WriteLine(@"Clear Cache"); Console.WriteLine(); Common.Util.CacheClear(); string result1 = string.Empty; string result2 = string.Empty; string result3 = string.Empty; Console.WriteLine(@"Step 1: The clients loads {0} objects with an appox. size of {1} kb", loops, size.ToString()); List<string> without = new List<string>(); List<string> with = new List<string>(); List<TestSizeObject> testObjectList = new List<TestSizeObject>(); List<TestSizeObjectWithList> testObjectListWithList = new List<TestSizeObjectWithList>(); for (int i = 0; i < loops; ++i) { testObjectList.Add(new TestSizeObject(size)); testObjectListWithList.Add(new TestSizeObjectWithList(size)); } Console.WriteLine(@"Client is done to load the data"); Console.WriteLine("Object Comparsion: \nwithout: {0, 7} bytes \nwith: {1, 10} bytes", COM.Formatters.Serialization.BinarySerialize(testObjectList[0]).Length, COM.Formatters.Serialization.BinarySerialize(testObjectListWithList[0]).Length ); Console.WriteLine("Step 2a: Adding all items into cache (without list)"); DateTime start = DateTime.Now; foreach (TestSizeObject o in testObjectList) { Common.Util.CacheAdd(o.Id, o); without.Add(o.Id); } TimeSpan span = DateTime.Now.Subtract(start); Console.WriteLine(); result1 = string.Format(@"without list taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine("Step 2b: Adding all items into cache (with list)"); start = DateTime.Now; foreach (TestSizeObjectWithList o in testObjectListWithList) { Common.Util.CacheAdd(o.Id, o); with.Add(o.Id); } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); Console.WriteLine(result1); result1 = string.Format(@"with taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine(result1); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.WriteLine(@"Step 3a: Retrieve each item from cache (without list)"); int success = 0; int failed = 0; TestSizeObject o2 = null; start = DateTime.Now; foreach (string key in without) { o2 = Common.Util.CacheGet<TestSizeObject>(key); if (o2 != null) ++success; else ++failed; o2 = null; } span = DateTime.Now.Subtract(start); result2 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi / success {4} - failed {5}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds, success, failed); Console.WriteLine(result2); Console.WriteLine(@"Step 3b: Retrieve each item from cache (with list)"); success = 0; failed = 0; TestSizeObjectWithList o3 = null; start = DateTime.Now; foreach (string key in with) { o3 = Common.Util.CacheGet<TestSizeObjectWithList>(key); if (o3 != null) ++success; else ++failed; o3 = null; } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); result2 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi / success {4} - failed {5}", span.Hours, span.Minutes, span.Seconds, span.Milliseconds, success, failed); Console.WriteLine(result2); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.WriteLine(); Console.WriteLine(@"Step 4a: Remove each item by key without list... NOT ALL AT ONCE!"); start = DateTime.Now; foreach (string key in with) { Common.Util.CacheRemove(key); } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(); result3 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine(); Console.WriteLine(@"Step 4b: Remove each item by key with list... NOT ALL AT ONCE!"); start = DateTime.Now; foreach (string key in without) { Common.Util.CacheRemove(key); } span = DateTime.Now.Subtract(start); Console.WriteLine(); Console.WriteLine(Common.Util.CacheGetStats()); Console.WriteLine(); Console.WriteLine(result3); result3 = string.Format(@"taken time: {0}h {1}m {2}s {3}mi", span.Hours, span.Minutes, span.Seconds, span.Milliseconds); Console.WriteLine(result3); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(); Console.WriteLine(@"Operation Done"); Console.WriteLine(@"- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - "); Console.WriteLine(); Console.WriteLine(@"Press enter to go on."); Console.ReadLine(); Console.Clear(); }