Пример #1
0
        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.");
        }
Пример #2
0
        public static PersonRow MakeFake(GDID parentGdid)
        {
            var age = (int)(parentGdid.ID % 99);

            var tags = NFX.ExternalRandomGenerator.Instance.NextRandomInteger > 0 ? new string[NFX.ExternalRandomGenerator.Instance.NextScaledRandomInteger(1, 20)] : null;

            if (tags != null)
            {
                for (int i = 0; i < tags.Length; i++)
                {
                    tags[i] = ((char)('a' + i)) + "tag";
                }
            }

            var pers = new PersonRow()
            {
                ID          = parentGdid,
                Name        = NFX.Parsing.NaturalTextGenerator.Generate(30),
                Age         = age,
                DOB         = DateTime.Now.AddYears(-age),
                Sex         = (parentGdid.ID % 2) == 0 ? Sex.Male : Sex.Female,
                Income      = (parentGdid.ID % 79) * 1000,
                Debt        = (parentGdid.ID % 11) * 1000,
                Rating      = (parentGdid.ID % 2) == 0 ? (double?)null : 3.25,
                Notes       = parentGdid.ToString(),
                Voter       = (parentGdid.ID % 2) == 0 ? (bool?)null : true,
                MilitarySvc = (parentGdid.ID % 2) == 0 ? (bool?)null : false,
                Address1    = NFX.Parsing.NaturalTextGenerator.Generate(50),
                Address2    = (parentGdid.ID % 7) == 0 ? NFX.Parsing.NaturalTextGenerator.Generate(50) : null,
                City        = (parentGdid.ID % 2) == 0 ? "Magdaburg" : "Odessa On Don",
                State       = "OH",
                Zip         = "44000" + (parentGdid.ID % 999),
                Phone1      = "(555) 222-3222",
                Phone2      = (parentGdid.ID % 3) == 0 ? "(555) 737-9789" : null,
                Email1      = "*****@*****.**",
                Email2      = (parentGdid.ID % 5) == 0 ? "*****@*****.**" : null,
                URL         = (parentGdid.ID % 2) == 0 ? "https://ibm.com/products/" + parentGdid.ID : null,
                Tags        = tags
            };

            return(pers);
        }
Пример #3
0
        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());
            }
        }