Ejemplo n.º 1
0
        private void CreateArchiveFile <TKey, TValue>(SubFileName fileName, EncodingDefinition storageMethod, int maxSortedTreeBlockSize)
            where TKey : SnapTypeBase <TKey>, new()
            where TValue : SnapTypeBase <TValue>, new()
        {
            if (maxSortedTreeBlockSize < 1024)
            {
                throw new ArgumentOutOfRangeException(nameof(maxSortedTreeBlockSize), "Must be greater than 1024");
            }
            if ((object)storageMethod == null)
            {
                throw new ArgumentNullException("storageMethod");
            }

            using (TransactionalEdit trans = m_fileStructure.BeginEdit())
            {
                using (SubFileStream fs = trans.CreateFile(fileName))
                    using (BinaryStream bs = new BinaryStream(fs))
                    {
                        int blockSize = m_fileStructure.Snapshot.Header.DataBlockSize;

                        while (blockSize > maxSortedTreeBlockSize)
                        {
                            blockSize >>= 2;
                        }

                        SortedTree <TKey, TValue> tree = SortedTree <TKey, TValue> .Create(bs, blockSize, storageMethod);

                        tree.Flush();
                    }
                trans.ArchiveType = FileType;
                trans.CommitAndDispose();
            }
        }
Ejemplo n.º 2
0
        public void BenchmarkOld(int pointCount)
        {
            SortedPointBuffer <HistorianKey, HistorianValue> points = new SortedPointBuffer <HistorianKey, HistorianValue>(pointCount, true);

            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            for (int x = 0; x < pointCount; x++)
            {
                key.PointID = (ulong)x;
                points.TryEnqueue(key, value);
            }

            points.IsReadingMode = true;

            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (BinaryStream bs = new BinaryStream(true))
            {
                SortedTree <HistorianKey, HistorianValue> st = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096, HistorianFileEncodingDefinition.TypeGuid);

                st.TryAddRange(points);
                //SequentialSortedTreeWriter<HistorianKey, HistorianValue>.Create(bs, 4096, SortedTree.FixedSizeNode, points);
            }
            sw.Stop();

            System.Console.WriteLine("Points {0}: {1}MPPS", pointCount, (pointCount / sw.Elapsed.TotalSeconds / 1000000).ToString("0.0"));
        }
Ejemplo n.º 3
0
        private TestResults TestRandomBinaryStream(int pageSize, uint count)
        {
            //StringBuilder sb = new StringBuilder();
            Random         R     = new Random(1);
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            DiskIoSession.ReadCount     = 0;
            DiskIoSession.WriteCount    = 0;
            Stats.ChecksumCount         = 0;
            DiskIoSession.Lookups       = 0;
            DiskIoSession.CachedLookups = 0;

            Stopwatch sw = new Stopwatch();

            sw.Start();

            using (BinaryStream bs = new BinaryStream(allocatesOwnMemory: true))
            {
                var table = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096);

                for (ulong x = 0; x < count; x++)
                {
                    key.Timestamp = (uint)R.Next();
                    key.PointID   = 2 * x;
                    value.Value3  = 3 * x;
                    value.Value1  = 4 * x;
                    //if ((x % 100) == 0)
                    //    sb.AppendLine(x + "," + DiskIoSession.ReadCount + "," + DiskIoSession.WriteCount);
                    //if (x == 1000)
                    //    DiskIoSession.BreakOnIO = true;
                    table.TryAdd(key, value);
                    //edit.AddPoint(uint.MaxValue - x, 2 * x, 3 * x, 4 * x);
                }
            }

            sw.Stop();

            //File.WriteAllText(@"C:\temp\" + pageSize + ".csv",sb.ToString());


            return(new TestResults()
            {
                PageSize = pageSize,
                Rate = (float)(count / sw.Elapsed.TotalSeconds / 1000000),
                ReadCount = DiskIoSession.ReadCount,
                WriteCount = DiskIoSession.WriteCount,
                ChecksumCount = Stats.ChecksumCount,
                Lookups = DiskIoSession.Lookups,
                CachedLookups = DiskIoSession.CachedLookups
            });
        }
        public void TestCompressCases()
        {
            using (BinaryStream bs = new BinaryStream())
            {
                SortedTree <HistorianKey, HistorianValue> tree = SortedTree <HistorianKey, HistorianValue> .Create(bs, 4096, HistorianFileEncodingDefinition.TypeGuid);

                HistorianKey   key   = new HistorianKey();
                HistorianKey   key1  = new HistorianKey();
                HistorianValue value = new HistorianValue();

                key.Timestamp   = 0;
                key.PointID     = 0;
                key.EntryNumber = 0;

                value.Value1 = 0;
                value.Value2 = 0;
                value.Value3 = 0;

                tree.Add(key, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID = 1;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID  = 2;
                value.Value1 = 1;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(1ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.PointID  = 3;
                value.Value1 = 561230651435234523ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID  = 35602353232;
                value.Value1 = 561230651435234523ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID++;
                value.Value1 = 561230651435234523ul;
                value.Value2 = 561230651435234524ul;
                value.Value3 = 561230651435234525ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(561230651435234524ul, value.Value2);
                Assert.AreEqual(561230651435234525ul, value.Value3);

                key.EntryNumber = 1;
                value.Value1    = 561230651435234523ul;
                value.Value2    = 561230651435234524ul;
                value.Value3    = 561230651435234525ul;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(561230651435234523ul, value.Value1);
                Assert.AreEqual(561230651435234524ul, value.Value2);
                Assert.AreEqual(561230651435234525ul, value.Value3);

                key.PointID++;
                key.EntryNumber = 0;
                value.AsSingle  = 60.1f;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(60.1f, value.AsSingle);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);


                key.PointID++;
                key.EntryNumber = 0;
                value.AsSingle  = -60.1f;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(-60.1f, value.AsSingle);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);

                key.Timestamp++;
                key.EntryNumber = 0;
                value.Value1    = 0;
                value.Value2    = 0;
                value.Value3    = 0;
                tree.Add(key, value);
                tree.Get(key1, value);
                tree.Get(key, value);
                Assert.AreEqual(0ul, value.Value1);
                Assert.AreEqual(0ul, value.Value2);
                Assert.AreEqual(0ul, value.Value3);
            }
        }