public static void NoGrowth_TRow(bool speed, int durationSec, int countMin, int countMax) { using (var pile = new DefaultPile()) { pile.AllocMode = speed ? AllocationMode.FavorSpeed : AllocationMode.ReuseSpace; pile.Start(); var startTime = DateTime.UtcNow; var tasks = new List <Task>(); for (var t = 0; t < (System.Environment.ProcessorCount - 1); t++) { tasks.Add(Task.Factory.StartNew(() => { var list = new List <CheckTRow>(); bool put = true; while (true) { if ((DateTime.UtcNow - startTime).TotalSeconds >= durationSec) { return; } if (put) { var cnt = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(countMin, countMax); for (int j = 0; j < cnt; j++) { var val = PersonRow.MakeFake(new GDID()); var ptr = pile.Put(val); var element = new CheckTRow(ptr, val.ID, val.Address1); list.Add(element); } Console.WriteLine("Thread {0} put {1} objects".Args(Thread.CurrentThread.ManagedThreadId, list.Count)); put = false; } else { Console.WriteLine("Thread {0} deleted {1} objects".Args(Thread.CurrentThread.ManagedThreadId, list.Count)); for (var j = 0; j < list.Count; j++) { var element = list[j]; var buf = pile.Get(element.Ptr) as PersonRow; Aver.AreEqual(element.Id, buf.ID); Aver.AreEqual(element.Address, buf.Address1); pile.Delete(element.Ptr); } list.Clear(); put = true; } } }, TaskCreationOptions.LongRunning)); } Task.WaitAll(tasks.ToArray()); } Console.WriteLine("Test finished."); }
public static void DeleteSeveral_TRow(bool speed, int durationSec, int putMin, int putMax, int delFactor, bool isParallel) { using (var pile = new DefaultPile()) { pile.AllocMode = speed ? AllocationMode.FavorSpeed : AllocationMode.ReuseSpace; pile.Start(); var startTime = DateTime.UtcNow; var tasks = new List <Task>(); for (var t = 0; t < (isParallel ? (System.Environment.ProcessorCount - 1) : 1); t++) { tasks.Add(Task.Factory.StartNew(() => { var list = new List <CheckTRow>(); var wlc = 0; while (true) { if ((DateTime.UtcNow - startTime).TotalSeconds >= durationSec) { break; } var putCount = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(putMin, putMax); for (int i = 0; i < putCount; i++) { var val = PersonRow.MakeFake(new GDID()); var ptr = pile.Put(val); list.Add(new CheckTRow(ptr, val.ID, val.Address1)); } // delete several random elements int delCount = putCount / delFactor; for (int i = 0; i < delCount; i++) { var idx = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, list.Count - 1); var ptr = list[idx].Ptr; pile.Delete(ptr); list.RemoveAt(idx); } // get several random elements if (list.Count > 64 && NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 100) > 98) { var toRead = NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(8, 64); wlc++; if (wlc % 125 == 0) { Console.WriteLine("Thread {0} is reading {1} elements, total {2}" .Args(Thread.CurrentThread.ManagedThreadId, toRead, list.Count)); } for (var k = 0; k < toRead; k++) { var element = list[NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, list.Count - 1)]; var buf = pile.Get(element.Ptr) as PersonRow; Aver.IsTrue(element.Id.Equals(buf.ID)); Aver.IsTrue(element.Address.Equals(buf.Address1)); } } } // total check Console.WriteLine("Thread {0} is doing final read of {1} elements, objectCount {2}" .Args(Thread.CurrentThread.ManagedThreadId, list.Count, pile.ObjectCount)); foreach (var element in list) { var buf = pile.Get(element.Ptr) as PersonRow; Aver.IsTrue(element.Id.Equals(buf.ID)); Aver.IsTrue(element.Address.Equals(buf.Address1)); } return; }, TaskCreationOptions.LongRunning)); } Task.WaitAll(tasks.ToArray()); } }