Ejemplo n.º 1
0
        public void PutGetTwo()
        {
            using (var pile = MakeMMFPile())
            {
                pile.Start();

                var ipile = pile as IPile;

                var rowIn1 = CheckoutRow.MakeFake(new GDID(0, 1));
                var rowIn2 = CheckoutRow.MakeFake(new GDID(0, 2));

                var pp1 = ipile.Put(rowIn1);
                var pp2 = ipile.Put(rowIn2);

                Aver.IsTrue(2 == ipile.ObjectCount);
                Aver.AreEqual(DefaultPile.SEG_SIZE_DFLT, ipile.AllocatedMemoryBytes);
                Aver.AreEqual(1, ipile.SegmentCount);

                var rowOut1 = pile.Get(pp1) as CheckoutRow;
                var rowOut2 = pile.Get(pp2) as CheckoutRow;

                Aver.AreObjectsEqual(rowIn1, rowOut1);
                Aver.AreObjectsEqual(rowIn2, rowOut2);
            }
        }
Ejemplo n.º 2
0
        public static CheckoutRow MakeFake(GDID gdid)
        {
            var ch = new CheckoutRow()
            {
                ID          = gdid,
                Customer    = PersonRow.MakeFake(gdid),
                FileName    = "myface_" + gdid.ID.ToString(),
                Date        = DateTime.Now,
                StartOffset = gdid.ID * 20,
                G_Block     = gdid,

                Address1 = Text.NaturalTextGenerator.GenerateAddressLine(),
                Address2 = (gdid.ID % 7) == 0 ? Text.NaturalTextGenerator.GenerateAddressLine() : null
            };

            var chCnt = (int)(gdid.ID % 10);

            ch.Charges = new ChargeRow[chCnt];

            for (int i = 0; i < chCnt; i++)
            {
                ch.Charges[i] = ChargeRow.MakeFake(gdid);
            }

            return(ch);
        }
Ejemplo n.º 3
0
        public void PutGetOne()
        {
            using (var pile = MakeMMFPile())
            {
                pile.Start();
                var ipile = pile as IPile;

                var rowIn = CheckoutRow.MakeFake(new GDID(0, 1));

                var pp = ipile.Put(rowIn);

                var rowOut = ipile.Get(pp) as CheckoutRow;

                Aver.AreObjectsEqual(rowIn, rowOut);
            }
        }
Ejemplo n.º 4
0
        public void PutGetOne()
        {
            using (var pile = new DefaultPile(NOPApplication.Instance))
            {
                pile.Start();
                var ipile = pile as IPile;

                var rowIn = CheckoutRow.MakeFake(new GDID(0, 1));

                var pp = ipile.Put(rowIn);

                var rowOut = ipile.Get(pp) as CheckoutRow;

                Aver.AreObjectsEqual(rowIn, rowOut);
            }
        }
Ejemplo n.º 5
0
        public void PutOne()
        {
            using (var pile = MakeMMFPile())
            {
                pile.Start();

                var ipile = pile as IPile;

                var row = CheckoutRow.MakeFake(new GDID(0, 1));

                var pp = ipile.Put(row);

                Aver.AreEqual(1, ipile.ObjectCount);
                Aver.AreEqual(DefaultPile.SEG_SIZE_DFLT, ipile.AllocatedMemoryBytes);
                Aver.AreEqual(1, ipile.SegmentCount);
            }
        }
Ejemplo n.º 6
0
        public void ManyRow_PutThenRead()
        {
            using (var pile = new DefaultPile(NOPApplication.Instance))
            {
                pile.SegmentSize = DefaultPile.SEG_SIZE_MIN;
                pile.Start();
                var ipile = pile as IPile;

                var lst = new List <KeyValuePair <PilePointer, CheckoutRow> >();

                var sw = Stopwatch.StartNew();
                while (ipile.SegmentCount < 2)
                {
                    var rowIn = CheckoutRow.MakeFake(new GDID(0, (ulong)lst.Count));
                    var pp    = ipile.Put(rowIn);
                    lst.Add(new KeyValuePair <PilePointer, CheckoutRow>(pp, rowIn));
                }

                var wms = sw.ElapsedMilliseconds;


                Console.WriteLine("Created {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(lst.Count, wms, lst.Count / (wms / 1000d)));
                Console.WriteLine("Occupied bytes {0:n0}".Args(pile.AllocatedMemoryBytes));


                sw.Restart();
                foreach (var kvp in lst)
                {
                    Aver.IsNotNull(ipile.Get(kvp.Key));
                }
                var rms = sw.ElapsedMilliseconds;
                Console.WriteLine("Read {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(lst.Count, rms, lst.Count / (rms / 1000d)));

                foreach (var kvp in lst)
                {
                    var rowIn  = kvp.Value;
                    var rowOut = ipile.Get(kvp.Key) as CheckoutRow;
                    Aver.AreObjectsEqual(rowIn, rowOut);
                }
            }
        }
Ejemplo n.º 7
0
        public void ManyRow_PutReadDeleteRead()
        {
            using (var pile = new DefaultPile(NOPApplication.Instance))
            {
                pile.SegmentSize = DefaultPile.SEG_SIZE_MIN;
                pile.Start();
                var ipile = pile as IPile;

                var lst = new List <KeyValuePair <PilePointer, CheckoutRow> >();

                int totalPut    = 0;
                int totalDelete = 0;

                var sw = Stopwatch.StartNew();
                while (ipile.SegmentCount < 4)
                {
                    var rowIn = CheckoutRow.MakeFake(new GDID(0, (ulong)lst.Count));
                    var pp    = ipile.Put(rowIn);
                    totalPut++;
                    lst.Add(new KeyValuePair <PilePointer, CheckoutRow>(pp, rowIn));

                    var chance = Ambient.Random.NextRandomInteger > 1000000000; //periodically delete
                    if (!chance)
                    {
                        continue;
                    }

                    var idx = Ambient.Random.NextScaledRandomInteger(0, lst.Count - 1);
                    var kvp = lst[idx];
                    lst.RemoveAt(idx);
                    Aver.AreObjectsEqual(kvp.Value, ipile.Get(kvp.Key));

                    Aver.IsTrue(ipile.Delete(kvp.Key));
                    totalDelete++;
                }

                var wms = sw.ElapsedMilliseconds;


                Console.WriteLine("Created {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(totalPut, wms, totalPut / (wms / 1000d)));
                Console.WriteLine("Read and deleted {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(totalDelete, wms, totalDelete / (wms / 1000d)));
                Console.WriteLine("Left {0:n0}".Args(lst.Count));
                Console.WriteLine("Occupied bytes {0:n0}".Args(pile.AllocatedMemoryBytes));


                sw.Restart();
                foreach (var kvp in lst)
                {
                    Aver.IsNotNull(ipile.Get(kvp.Key));
                }
                var rms = sw.ElapsedMilliseconds;
                Console.WriteLine("Read {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(lst.Count, rms, lst.Count / (rms / 1000d)));


                Console.WriteLine("Will verify all rows...");
                foreach (var kvp in lst)
                {
                    var rowIn  = kvp.Value;
                    var rowOut = ipile.Get(kvp.Key) as CheckoutRow;
                    Aver.AreObjectsEqual(rowIn, rowOut);
                }
            }
        }
Ejemplo n.º 8
0
        public void Parallel_ManyMixed_PutReadDeleteRead(int tcount)
        {
            using (var pile = new DefaultPile(NOPApplication.Instance))
            {
                pile.SegmentSize = DefaultPile.SEG_SIZE_MIN;
                pile.Start();
                var ipile = pile as IPile;

                var lst = new List <KeyValuePair <PilePointer, CheckoutRow> >();

                int  totalBuff   = 0;
                long totalBuffSz = 0;
                int  totalPut    = 0;
                int  totalDelete = 0;


                var sw = Stopwatch.StartNew();

                var tasks = new List <Task>();

                while (tasks.Count < tcount)
                {
                    var task = Task.Factory.StartNew(() =>
                    {
                        var llst  = new List <KeyValuePair <PilePointer, CheckoutRow> >();
                        var pBuff = PilePointer.Invalid;

                        while (ipile.SegmentCount < 64)
                        {
                            var chance = Ambient.Random.NextRandomInteger > 0;
                            if (chance)
                            {
                                var fakeBuf = new byte[Ambient.Random.NextScaledRandomInteger(0, 128 * 1024)];
                                Interlocked.Increment(ref totalBuff);
                                Interlocked.Add(ref totalBuffSz, fakeBuf.Length);
                                if (pBuff.Valid && Ambient.Random.NextRandomInteger > 0)
                                {
                                    ipile.Delete(pBuff);                                                  //periodically delete buffers
                                }
                                pBuff = ipile.Put(fakeBuf);
                            }

                            var rowIn = CheckoutRow.MakeFake(new GDID(0, (ulong)llst.Count));
                            var pp    = ipile.Put(rowIn);
                            Interlocked.Increment(ref totalPut);
                            llst.Add(new KeyValuePair <PilePointer, CheckoutRow>(pp, rowIn));

                            chance = Ambient.Random.NextRandomInteger > 1000000000; //periodically delete rows
                            if (!chance)
                            {
                                continue;
                            }

                            var idx = Ambient.Random.NextScaledRandomInteger(0, llst.Count - 1);
                            var kvp = llst[idx];
                            llst.RemoveAt(idx);
                            Aver.AreObjectsEqual(kvp.Value, ipile.Get(kvp.Key));

                            Aver.IsTrue(ipile.Delete(kvp.Key));
                            Interlocked.Increment(ref totalDelete);
                        }
                        lock (lst)
                            lst.AddRange(llst);
                    });
                    tasks.Add(task);
                }
                Task.WaitAll(tasks.ToArray());

                var wms = sw.ElapsedMilliseconds;

                Console.WriteLine("Buff Created {0:n0} size {1:n0} bytes".Args(totalBuff, totalBuffSz));
                Console.WriteLine("Row Created {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(totalPut, wms, totalPut / (wms / 1000d)));
                Console.WriteLine("Read and deleted {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(totalDelete, wms, totalDelete / (wms / 1000d)));
                Console.WriteLine("Left {0:n0}".Args(lst.Count));
                Console.WriteLine("Occupied bytes {0:n0}".Args(pile.AllocatedMemoryBytes));
                Console.WriteLine("Utilized bytes {0:n0}".Args(pile.UtilizedBytes));
                Console.WriteLine("Objects {0:n0}".Args(pile.ObjectCount));


                sw.Restart();
                foreach (var kvp in lst)
                {
                    Aver.IsNotNull(ipile.Get(kvp.Key));
                }
                var rms = sw.ElapsedMilliseconds;
                Console.WriteLine("Read {0:n0} in {1:n0} ms at {2:n0} ops/sec".Args(lst.Count, rms, lst.Count / (rms / 1000d)));


                Console.WriteLine("Will verify all rows...");
                Parallel.ForEach(lst, kvp =>
                {
                    var rowIn  = kvp.Value;
                    var rowOut = ipile.Get(kvp.Key) as CheckoutRow;
                    Aver.AreObjectsEqual(rowIn, rowOut);
                });
            }
        }