Exemple #1
0
        private static void FillSeqMultipleTransaction(Stopwatch sw, FlushMode flushMode)
        {
            var memoryMapPager = new MemoryMapPager(Path, flushMode);

            using (var env = new StorageEnvironment(memoryMapPager))
            {
                var value = new byte[100];
                new Random().NextBytes(value);
                var ms = new MemoryStream(value);

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    memoryMapPager.AllocateMorePages(tx, 1024 * 1024 * 768);
                    tx.Commit();
                }

                sw.Start();
                int counter = 0;
                for (int x = 0; x < Transactions; x++)
                {
                    using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                    {
                        for (long i = 0; i < ItemsPerTransaction; i++)
                        {
                            ms.Position = 0;
                            env.Root.Add(tx, (counter++).ToString("0000000000000000"), ms);
                        }

                        tx.Commit();
                    }
                }
                sw.Stop();
            }
        }
Exemple #2
0
        private static void ReadAndWriteOneTransaction(Stopwatch sw, int concurrency)
        {
            var memoryMapPager = new MemoryMapPager(Path, FlushMode.None);

            using (var env = new StorageEnvironment(memoryMapPager))
            {
                var value = new byte[100];
                new Random().NextBytes(value);

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    memoryMapPager.AllocateMorePages(tx, 1024 * 1024 * 768);
                    tx.Commit();
                }

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    var ms = new MemoryStream(value);
                    for (long i = 0; i < Transactions * ItemsPerTransaction; i++)
                    {
                        ms.Position = 0;
                        env.Root.Add(tx, i.ToString("0000000000000000"), ms);
                    }

                    tx.Commit();
                }

                var countdownEvent = new CountdownEvent(concurrency);

                sw.Start();
                for (int i = 0; i < concurrency; i++)
                {
                    var currentBase = i;
                    ThreadPool.QueueUserWorkItem(state =>
                    {
                        using (var tx = env.NewTransaction(TransactionFlags.Read))
                        {
                            var ms = new byte[100];
                            for (int j = 0; j < ((ItemsPerTransaction * Transactions) / concurrency); j++)
                            {
                                var current = j * currentBase;
                                var key     = current.ToString("0000000000000000");
                                using (var stream = env.Root.Read(tx, key))
                                {
                                    while (stream.Read(ms, 0, ms.Length) != 0)
                                    {
                                    }
                                }
                            }

                            tx.Commit();
                        }

                        countdownEvent.Signal();
                    });
                }
                countdownEvent.Wait();
                sw.Stop();
            }
        }
Exemple #3
0
        private static void FillRandomOneTransaction(Stopwatch sw, FlushMode flushMode)
        {
            var memoryMapPager = new MemoryMapPager(Path, flushMode);

            using (var env = new StorageEnvironment(memoryMapPager))
            {
                var value = new byte[100];
                new Random().NextBytes(value);
                var ms = new MemoryStream(value);

                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    memoryMapPager.AllocateMorePages(tx, 1024 * 1024 * 768);
                    tx.Commit();
                }

                sw.Start();
                using (var tx = env.NewTransaction(TransactionFlags.ReadWrite))
                {
                    foreach (var l in _randomNumbers)
                    {
                        ms.Position = 0;
                        env.Root.Add(tx, l.ToString("0000000000000000"), ms);
                    }

                    tx.Commit();
                }
                sw.Stop();
            }
        }