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; Assert.AreEqual(element.Id, buf.ID); Assert.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 PurchaseRow MakeFake(GDID gdid) { var purch = new PurchaseRow() { ID = gdid, Customer = PersonRow.MakeFake(gdid), Date = DateTime.Now, Amount = new Amount("usd", gdid.ID % 1897), SalesPerson = (gdid.ID % 2) == 0 ? null : PersonRow.MakeFake(gdid), G_Product = new GDID(0, gdid.ID + 157) }; return(purch); }
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; Assert.IsTrue(element.Id.Equals(buf.ID)); Assert.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; Assert.IsTrue(element.Id.Equals(buf.ID)); Assert.IsTrue(element.Address.Equals(buf.Address1)); } return; }, TaskCreationOptions.LongRunning)); } Task.WaitAll(tasks.ToArray()); } }
public static void Chessboard_TRow(bool speed, int durationSec, 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 i = 0; var wlc = 0; while (true) { if ((DateTime.UtcNow - startTime).TotalSeconds >= durationSec) break; var val = PersonRow.MakeFake(new GDID(0, (ulong)i)); var ptr = pile.Put(val); var element = new CheckTRow(ptr, val.ID, val.Address1); list.Add(element); // delete previous element if (list.Count > 1 && i % 2 == 0) { ptr = list[list.Count - 2].Ptr; pile.Delete(ptr); list.RemoveAt(list.Count - 2); } // 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}, Pile objects {3}, Pile segments {4} Pile Bytes {5}" .Args(Thread.CurrentThread.ManagedThreadId, toRead, list.Count, pile.ObjectCount, pile.SegmentCount, pile.AllocatedMemoryBytes)); for (var k = 0; k < toRead; k++) { element = list[NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, list.Count - 1)]; var buf = pile.Get(element.Ptr) as PersonRow; Assert.IsTrue(element.Id.Equals(buf.ID)); Assert.IsTrue(element.Address.Equals(buf.Address1)); } } if (i == Int32.MaxValue) i = 0; else i++; if (list.Count == Int32.MaxValue) list = new List<CheckTRow>(); } // 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; Assert.IsTrue(element.Id.Equals(buf.ID)); Assert.IsTrue(element.Address.Equals(buf.Address1)); } return; }, TaskCreationOptions.LongRunning)); Task.WaitAll(tasks.ToArray()); } }