Esempio n. 1
0
        public void PutGetTwo()
        {
            using (var pile = new DefaultPile())
            {
                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);

                Assert.AreEqual(2, ipile.ObjectCount);
                Assert.AreEqual(DefaultPile.SEG_SIZE_DFLT, ipile.AllocatedMemoryBytes);
                Assert.AreEqual(1, ipile.SegmentCount);

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

                Assert.AreEqual(rowIn1, rowOut1);
                Assert.AreEqual(rowIn2, rowOut2);
            }
        }
Esempio n. 2
0
        public void PutGetOne()
        {
            using (var pile = new DefaultPile())
            {
                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;

                Assert.AreEqual(rowIn, rowOut);
            }
        }
Esempio n. 3
0
        public void PutOne()
        {
            using (var pile = new DefaultPile())
            {
                pile.Start();

                var ipile = pile as IPile;

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

                var pp = ipile.Put(row);

                Assert.AreEqual(1, ipile.ObjectCount);
                Assert.AreEqual(DefaultPile.SEG_SIZE_DFLT, ipile.AllocatedMemoryBytes);
                Assert.AreEqual(1, ipile.SegmentCount);
            }
        }
Esempio n. 4
0
        public void ManyRow_PutThenRead()
        {
            using (var pile = new DefaultPile())
            {
                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);
                }
            }
        }
Esempio n. 5
0
        public void ManyRow_PutReadDeleteRead()
        {
            using (var pile = new DefaultPile())
            {
                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 = ExternalRandomGenerator.Instance.NextRandomInteger > 1000000000; //periodically delete
                    if (!chance)
                    {
                        continue;
                    }

                    var idx = ExternalRandomGenerator.Instance.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);
                }
            }
        }
Esempio n. 6
0
        public void Parallel_ManyMixed_PutReadDeleteRead(int tcount)
        {
            using (var pile = new DefaultPile())
            {
                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 = ExternalRandomGenerator.Instance.NextRandomInteger > 0;
                            if (chance)
                            {
                                var fakeBuf = new byte[ExternalRandomGenerator.Instance.NextScaledRandomInteger(0, 128 * 1024)];
                                Interlocked.Increment(ref totalBuff);
                                Interlocked.Add(ref totalBuffSz, fakeBuf.Length);
                                if (pBuff.Valid && ExternalRandomGenerator.Instance.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 = ExternalRandomGenerator.Instance.NextRandomInteger > 1000000000; //periodically delete rows
                            if (!chance)
                            {
                                continue;
                            }

                            var idx = ExternalRandomGenerator.Instance.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);
                });
            }
        }