Пример #1
0
        public void RollbackChangesToAFile()
        {
            string         fileName = @"C:\Temp\ArchiveFile.d2";
            HistorianKey   key      = new HistorianKey();
            HistorianValue value    = new HistorianValue();

            using (SortedTreeFile file = SortedTreeFile.OpenFile(fileName, isReadOnly: false))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> editor = table.BeginEdit())
                    {
                        key.TimestampAsDate = DateTime.Now.AddDays(-1);
                        key.PointID         = 234;
                        value.AsString      = "Add Me";
                        editor.AddPoint(key, value);
                        editor.Commit();
                    }

                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> editor = table.BeginEdit())
                    {
                        key.Timestamp  = 31;
                        value.AsString = "But Not Me";
                        editor.AddPoint(key, value);
                        editor.Rollback(); //These changes will not be written to the disk
                    }
                }
            ReadDataFromAFile();
        }
Пример #2
0
        public void EnduranceTest()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (SortedTreeTable <HistorianKey, HistorianValue> target = SortedTreeFile.CreateInMemory().OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
            {
                for (uint x = 0; x < 100; x++)
                {
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> fileEditor = target.BeginEdit())
                    {
                        for (int y = 0; y < 10; y++)
                        {
                            key.Timestamp = x;
                            key.PointID   = x;
                            value.Value1  = x;
                            value.Value3  = x;
                            fileEditor.AddPoint(key, value);
                            x++;
                        }
                        fileEditor.Commit();
                    }
                    Assert.AreEqual(target.FirstKey.Timestamp, 0);
                    Assert.AreEqual(target.LastKey.Timestamp, x - 1);
                }
            }
        }
Пример #3
0
        public void WriteFile()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            if (File.Exists("c:\\temp\\ArchiveTestFileBig.d2"))
            {
                File.Delete("c:\\temp\\ArchiveTestFileBig.d2");
            }
            //using (var af = ArchiveFile.CreateInMemory(CompressionMethod.TimeSeriesEncoded))
            using (SortedTreeFile af = SortedTreeFile.CreateFile("c:\\temp\\ArchiveTestFileBig.d2"))
                using (SortedTreeTable <HistorianKey, HistorianValue> af2 = af.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    Random r = new Random(3);

                    for (ulong v1 = 1; v1 < 36; v1++)
                    {
                        using (var edit = af2.BeginEdit())
                        {
                            for (ulong v2 = 1; v2 < 86000; v2++)
                            {
                                key.Timestamp = v1 * 2342523;
                                key.PointID   = v2;
                                value.Value1  = (ulong)r.Next();
                                value.Value3  = 0;

                                edit.AddPoint(key, value);
                            }
                            edit.Commit();
                        }
                        af2.Count();
                    }
                    af2.Count();
                }
        }
Пример #4
0
        public void GetDifference()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("Bucket Number, Count");
            using (SortedTreeFile file = SortedTreeFile.OpenFile(@"C:\Unison\GPA\Codeplex\openHistorian\Main\Build\Output\Release\Applications\openHistorian\Archive\635293583194231435-Stage2-0ef36dcc-4264-498f-b194-01b2043a9231.d2", true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader = table.BeginRead())
                        using (SortedTreeScannerBase <HistorianKey, HistorianValue> scan = reader.GetTreeScanner())
                        {
                            HistorianKey   key1  = new HistorianKey();
                            HistorianKey   key2  = new HistorianKey();
                            HistorianValue value = new HistorianValue();

                            int count = 0;
                            scan.SeekToStart();
                            while (scan.Read(key1, value))
                            {
                                count++;
                            }



                            int[] bucket = new int[130];
                            scan.SeekToStart();

                            while (true)
                            {
                                if (!scan.Read(key1, value))
                                {
                                    break;
                                }

                                if (key1.Timestamp == key2.Timestamp)
                                {
                                    int diff = Math.Abs((int)(key1.PointID - key2.PointID));
                                    diff = Math.Min(129, diff);
                                    bucket[diff]++;
                                }

                                if (!scan.Read(key2, value))
                                {
                                    break;
                                }

                                if (key1.Timestamp == key2.Timestamp)
                                {
                                    int diff = Math.Abs((int)(key1.PointID - key2.PointID));
                                    diff = Math.Min(129, diff);
                                    bucket[diff]++;
                                }
                            }

                            for (uint x = 0; x < bucket.Length; x++)
                            {
                                sb.AppendLine(x.ToString() + "," + (bucket[x] / (double)count * 100.0).ToString("0.00"));
                            }
                        }
            Console.WriteLine(sb.ToString());
        }
Пример #5
0
        public void TestSmall()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (SortedTreeFile af = SortedTreeFile.CreateInMemory())
                using (SortedTreeTable <HistorianKey, HistorianValue> file = af.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> edit = file.BeginEdit())
                    {
                        for (int x = 0; x < 10000000; x++)
                        {
                            key.Timestamp = (ulong)x;
                            edit.AddPoint(key, value);
                        }
                        edit.Commit();
                    }

                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> read = file.BeginRead())
                        using (SortedTreeScannerBase <HistorianKey, HistorianValue> scan = read.GetTreeScanner())
                        {
                            int count = 0;
                            scan.SeekToStart();
                            while (scan.Read(key, value))
                            {
                                count++;
                            }
                            System.Console.WriteLine(count.ToString());
                        }
                }
        }
        SortedTreeTable <HistorianKey, HistorianValue> CreateTable()
        {
            SortedTreeFile file = SortedTreeFile.CreateInMemory();
            SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding);

            return(table);
        }
Пример #7
0
        public void TestBulkRolloverFile()
        {
            Stats.LookupKeys            = 0;
            DiskIoSession.ReadCount     = 0;
            DiskIoSession.WriteCount    = 0;
            Stats.ChecksumCount         = 0;
            DiskIoSession.Lookups       = 0;
            DiskIoSession.CachedLookups = 0;
            long      cnt;
            Stopwatch sw = new Stopwatch();

            sw.Start();
            //using (SortedTreeTable<HistorianKey, HistorianValue> af = SortedTreeFile.CreateInMemory(4096).OpenOrCreateTable<HistorianKey, HistorianValue>(SortedTree.FixedSizeNode))
            using (SortedTreeTable <HistorianKey, HistorianValue> af = SortedTreeFile.CreateInMemory(blockSize: 4096).OpenOrCreateTable <HistorianKey, HistorianValue>(HistorianFileEncodingDefinition.TypeGuid))
            {
                using (SortedTreeTableEditor <HistorianKey, HistorianValue> edit = af.BeginEdit())
                {
                    edit.AddPoints(new PointStreamSequentialPoints(1, 20000000));
                    edit.Commit();
                }
                sw.Stop();

                cnt = af.Count();
                System.Console.WriteLine(cnt);
            }

            System.Console.WriteLine((float)(20 / sw.Elapsed.TotalSeconds));
        }
Пример #8
0
        public void GetBits()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();
            StringBuilder  sb    = new StringBuilder();

            sb.AppendLine("Higher Bits, Bucket Number, Count, FloatValue");
            using (SortedTreeFile file = SortedTreeFile.OpenFile(@"C:\Archive\635184227258021940-Stage2-8b835d6a-8299-45bb-9624-d4a470e4abe1.d2", true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader = table.BeginRead())
                        using (SortedTreeScannerBase <HistorianKey, HistorianValue> scan = reader.GetTreeScanner())
                        {
                            int count = 0;
                            scan.SeekToStart();
                            while (scan.Read(key, value))
                            {
                                count++;
                            }

                            for (int x = 1; x < 24; x++)
                            {
                                scan.SeekToStart();
                                int[] bucket = MeasureBits(scan, x);
                                Write(sb, bucket, x, count);
                            }
                        }

            Console.WriteLine(sb.ToString());
        }
Пример #9
0
        public void ReadDataFromAFile()
        {
            string   fileName = @"c:\temp\Tulsa Bank 1 LTC 1.d2";
            DateTime start    = DateTime.Parse("4/17/2013 10:38 AM");
            DateTime stop     = DateTime.Parse("4/17/2013 10:38 AM");

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

            using (var file = SortedTreeFile.OpenFile(fileName, isReadOnly: true))
                using (var table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (var snapshot = table.BeginRead())
                    {
                        var scanner = snapshot.GetTreeScanner();
                        var seekKey = new HistorianKey();
                        seekKey.TimestampAsDate = start;
                        seekKey.PointID         = 3142023;
                        scanner.SeekToKey(seekKey);
                        while (scanner.Read(key, value) && key.TimestampAsDate <= stop)
                        {
                            Console.WriteLine("{0}, {1}, {2}",
                                              key.TimestampAsDate.ToString(), key.PointID, value.AsString);
                        }
                    }
        }
Пример #10
0
        public void TestFile()
        {
            //		FilePath	"C:\\Temp\\Historian\\635287587300536177-Stage1-d559e63e-d938-46a9-8d57-268f7c8ba194.d2"	string
            //635329017197429979-Stage1-38887e11-4097-4937-b269-ce4037157691.d2
            //using (var file = SortedTreeFile.OpenFile(@"C:\Temp\Historian\635287587300536177-Stage1-d559e63e-d938-46a9-8d57-268f7c8ba194.d2", true))
            using (var file = SortedTreeFile.OpenFile(@"C:\Archive\635329017197429979-Stage1-38887e11-4097-4937-b269-ce4037157691.d2", true))
                //using (var file = SortedTreeFile.OpenFile(@"C:\Temp\Historian\635255664136496199-Stage2-6e758046-b2af-40ff-ae4e-85cd0c0e4501.d2", true))
                using (var table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (var reader = table.BeginRead())
                    {
                        var scanner = reader.GetTreeScanner();
                        scanner.SeekToStart();
                        scanner.TestSequential().Count();

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

                        int x = 0;
                        scanner.Peek(key, value);

                        while (scanner.Read(key, value) && x < 10000)
                        {
                            System.Console.WriteLine(key.PointID);
                            x++;

                            scanner.Peek(key, value);
                        }

                        scanner.Count();
                    }
        }
Пример #11
0
        private void StartStream(object args)
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (HistorianClient client = new HistorianClient("127.0.0.1", 54996))
                using (ClientDatabaseBase <HistorianKey, HistorianValue> database = client.GetDatabase <HistorianKey, HistorianValue>(string.Empty))
                {
                    using (SortedTreeTable <HistorianKey, HistorianValue> file = SortedTreeFile.OpenFile(@"H:\OGE 2009.d2", isReadOnly: true).OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                    {
                        using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> read = file.BeginRead())
                        {
                            SortedTreeScannerBase <HistorianKey, HistorianValue> scan = read.GetTreeScanner();
                            scan.SeekToStart();
                            long count = 0;
                            while (scan.Read(key, value))
                            {
                                count++;
                                database.Write(key, value);
                                if ((count % 10) == 1)
                                {
                                    Thread.Sleep(1);
                                }
                            }
                        }
                    }
                }
        }
Пример #12
0
        public void ReadFromAFileWhileWritingToIt()
        {
            HistorianKey   key      = new HistorianKey();
            HistorianValue value    = new HistorianValue();
            string         fileName = @"C:\Temp\ArchiveFile.d2";

            using (SortedTreeFile file = SortedTreeFile.OpenFile(fileName, isReadOnly: false))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                {
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> writer = table.BeginEdit())
                        using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader = table.BeginRead())
                        {
                            SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = reader.GetTreeScanner();
                            scanner.SeekToStart();
                            while (scanner.Read(key, value))
                            {
                                key.Timestamp++;
                                value.Value1++;
                                writer.AddPoint(key, value);
                            }

                            writer.Commit();
                        }
                }
            ReadDataFromAFile();
        }
Пример #13
0
        private void TestFile(int pageSize, string fileName)
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            key.Timestamp = 1;

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            Stopwatch sw = new Stopwatch();

            sw.Start();
            using (SortedTreeTable <HistorianKey, HistorianValue> af = SortedTreeFile.CreateFile(fileName, blockSize: pageSize).OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                using (SortedTreeTableEditor <HistorianKey, HistorianValue> edit = af.BeginEdit())
                {
                    for (uint x = 0; x < 1000000; x++)
                    {
                        key.PointID = x;
                        edit.AddPoint(key, value);
                    }
                    edit.Commit();
                }
            sw.Stop();
            System.Console.WriteLine("Size: " + pageSize + " Rate: " + (1 / sw.Elapsed.TotalSeconds).ToString());
        }
Пример #14
0
        public void TestCompressed()
        {
            int       count = 10000000;
            Stopwatch sw    = new Stopwatch();

            using (SortedTreeFile af = SortedTreeFile.CreateInMemory())
                using (SortedTreeTable <AmiKey, AmiValue> table = af.OpenOrCreateTable <AmiKey, AmiValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableEditor <AmiKey, AmiValue> edit = table.BeginEdit())
                    {
                        sw.Start();
                        AmiKey   key   = new AmiKey();
                        AmiValue value = new AmiValue();

                        for (int x = 0; x < count; x++)
                        {
                            key.Timestamp = (uint)x;
                            edit.AddPoint(key, value);
                        }

                        edit.Commit();
                        sw.Stop();

                        Console.WriteLine(af.ArchiveSize / 1024.0 / 1024.0);
                        Console.WriteLine(count / sw.Elapsed.TotalSeconds / 1000000);
                    }
                }
        }
Пример #15
0
        private TestResults TestRandom(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 (SortedTreeFile af = SortedTreeFile.CreateInMemory(blockSize: pageSize))
                using (SortedTreeTable <HistorianKey, HistorianValue> af2 = af.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    uint pointPairs = count / 5000;
                    for (uint i = 0; i < pointPairs; i++)
                    {
                        uint max = i * 5000 + 5000;
                        using (var edit = af2.BeginEdit())
                        {
                            for (ulong x = i * 5000; x < max; 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;
                                edit.AddPoint(key, value);
                                //edit.AddPoint(uint.MaxValue - x, 2 * x, 3 * x, 4 * x);
                            }
                            edit.Commit();
                        }
                    }
                    //long cnt = af.Count();
                }

            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
            });
        }
Пример #16
0
 public void AddPointTest()
 {
     using (SortedTreeTable <HistorianKey, HistorianValue> target = SortedTreeFile.CreateInMemory().OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
     {
         using (SortedTreeTableEditor <HistorianKey, HistorianValue> fileEditor = target.BeginEdit())
         {
             fileEditor.AddPoint(new HistorianKey(), new HistorianValue());
             fileEditor.Commit();
         }
     }
 }
Пример #17
0
        /// <summary>
        /// Creates a new <see cref="SortedTreeTable{TKey,TValue}"/> based on the settings passed to this class.
        /// Once created, it is up to he caller to make sure that this class is properly disposed of.
        /// </summary>
        /// <param name="startKey">the first key in the archive file</param>
        /// <param name="endKey">the last key in the archive file</param>
        /// <param name="estimatedSize">The estimated size of the file. -1 to ignore this feature and write to the first available directory.</param>
        /// <param name="archiveIdCallback">the archiveId to assign to the new file.</param>
        /// <returns></returns>
        public SortedTreeTable <TKey, TValue> CreateArchiveFile(TKey startKey, TKey endKey, long estimatedSize, TreeStream <TKey, TValue> data, Action <Guid> archiveIdCallback)
        {
            SimplifiedArchiveInitializerSettings settings = m_settings;

            string pendingFile = CreateArchiveName(GetPathWithEnoughSpace(estimatedSize), startKey, endKey);
            string finalFile   = Path.ChangeExtension(pendingFile, settings.FinalExtension);

            SortedTreeFileSimpleWriter <TKey, TValue> .Create(pendingFile, finalFile, 4096, archiveIdCallback, settings.EncodingMethod, data, settings.Flags.ToArray());

            return(SortedTreeFile.OpenFile(finalFile, true).OpenTable <TKey, TValue>());
        }
Пример #18
0
        public void Test()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (SortedTreeFile file = SortedTreeFile.OpenFile(@"C:\Unison\GPA\Codeplex\openHistorian\Main\Build\Output\Release\Applications\openHistorian\Archive\635293583194231435-Stage2-0ef36dcc-4264-498f-b194-01b2043a9231.d2", true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader = table.BeginRead())
                        using (SortedTreeScannerBase <HistorianKey, HistorianValue> scan = reader.GetTreeScanner())
                        {
                            scan.SeekToStart();
                            while (scan.Read(key, value))
                            {
                                ;
                            }
                        }
        }
Пример #19
0
        public void CreateSnapshotTest()
        {
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            key.Timestamp = 1;
            key.PointID   = 2;
            value.Value1  = 3;
            value.Value2  = 4;
            using (SortedTreeTable <HistorianKey, HistorianValue> target = SortedTreeFile.CreateInMemory().OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
            {
                ulong date    = 1;
                ulong pointId = 2;
                ulong value1  = 3;
                ulong value2  = 4;
                SortedTreeTableSnapshotInfo <HistorianKey, HistorianValue> snap1;
                using (SortedTreeTableEditor <HistorianKey, HistorianValue> fileEditor = target.BeginEdit())
                {
                    fileEditor.AddPoint(key, value);
                    key.Timestamp++;
                    fileEditor.AddPoint(key, value);
                    snap1 = target.AcquireReadSnapshot();
                    fileEditor.Commit();
                }
                SortedTreeTableSnapshotInfo <HistorianKey, HistorianValue> snap2 = target.AcquireReadSnapshot();

                using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> instance = snap1.CreateReadSnapshot())
                {
                    SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = instance.GetTreeScanner();
                    scanner.SeekToStart();
                    Assert.AreEqual(false, scanner.Read(key, value));
                }
                using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> instance = snap2.CreateReadSnapshot())
                {
                    SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = instance.GetTreeScanner();
                    scanner.SeekToStart();
                    Assert.AreEqual(true, scanner.Read(key, value));
                    Assert.AreEqual(1uL, key.Timestamp);
                    Assert.AreEqual(2uL, key.PointID);
                    Assert.AreEqual(3uL, value.Value1);
                    Assert.AreEqual(4uL, value.Value2);
                }
                Assert.AreEqual(1uL, target.FirstKey.Timestamp);
                Assert.AreEqual(2uL, target.LastKey.Timestamp);
            }
        }
 /// <summary>
 /// Creates a new <see cref="SortedTreeTable{TKey,TValue}"/> based on the settings passed to this class.
 /// Once created, it is up to he caller to make sure that this class is properly disposed of.
 /// </summary>
 /// <param name="estimatedSize">The estimated size of the file. -1 to ignore this feature and write to the first available directory.</param>
 /// <returns></returns>
 public SortedTreeTable <TKey, TValue> CreateArchiveFile(long estimatedSize = -1)
 {
     using (m_lock.EnterReadLock())
     {
         if (m_settings.IsMemoryArchive)
         {
             SortedTreeFile af = SortedTreeFile.CreateInMemory(blockSize: 4096, flags: m_settings.Flags.ToArray());
             return(af.OpenOrCreateTable <TKey, TValue>(m_settings.EncodingMethod));
         }
         else
         {
             string         fileName = CreateArchiveName(GetPathWithEnoughSpace(estimatedSize));
             SortedTreeFile af       = SortedTreeFile.CreateFile(fileName, blockSize: 4096, flags: m_settings.Flags.ToArray());
             return(af.OpenOrCreateTable <TKey, TValue>(m_settings.EncodingMethod));
         }
     }
 }
Пример #21
0
        public void AppendDataToAnExistingFile()
        {
            string         fileName = @"C:\Temp\ArchiveFile.d2";
            HistorianKey   key      = new HistorianKey();
            HistorianValue value    = new HistorianValue();

            using (SortedTreeFile file = SortedTreeFile.OpenFile(fileName, isReadOnly: false))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> editor = table.BeginEdit())
                    {
                        key.TimestampAsDate = DateTime.Now;
                        key.PointID         = 2;
                        value.AsString      = "Test Append";
                        editor.AddPoint(key, value);
                        editor.Commit();
                    }
            ReadDataFromAFile();
        }
Пример #22
0
        public void BenchmarkWriteSpeed()
        {
            DebugStopwatch sw = new DebugStopwatch();

            double time;
            double count = 0;

            using (SortedTreeFile file = SortedTreeFile.CreateInMemory())
            {
                var            table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(HistorianFileEncodingDefinition.TypeGuid);
                HistorianKey   key   = new HistorianKey();
                HistorianValue value = new HistorianValue();

                time = sw.TimeEvent(() =>
                {
                    //TreeKeyMethodsBase<HistorianKey>.ClearStats();
                    //TreeValueMethodsBase<HistorianKey>.ClearStats();
                    count = 0;
                    using (var scan = table.BeginEdit())
                    {
                        for (uint x = 0; x < 10000000; x++)
                        {
                            key.PointID = x;
                            scan.AddPoint(key, value);
                            count++;
                        }
                        scan.Rollback();
                    }
                });
            }

            Console.WriteLine((count / 1000000 / time).ToString() + " Million PPS");

            //Console.WriteLine("KeyMethodsBase calls");
            //for (int x = 0; x < 23; x++)
            //{
            //    Console.WriteLine(TreeKeyMethodsBase<HistorianKey>.CallMethods[x] + "\t" + ((TreeKeyMethodsBase<HistorianKey>.Method)(x)).ToString());
            //}
            //Console.WriteLine("ValueMethodsBase calls");
            //for (int x = 0; x < 5; x++)
            //{
            //    Console.WriteLine(TreeValueMethodsBase<HistorianValue>.CallMethods[x] + "\t" + ((TreeValueMethodsBase<HistorianValue>.Method)(x)).ToString());
            //}
        }
Пример #23
0
        public void ConcurrentReadingFromAFile()
        {
            string fileName = @"C:\Temp\ArchiveFile.d2";

            HistorianKey   key1   = new HistorianKey();
            HistorianKey   key2   = new HistorianKey();
            HistorianValue value1 = new HistorianValue();
            HistorianValue value2 = new HistorianValue();

            using (SortedTreeFile file = SortedTreeFile.OpenFile(fileName, isReadOnly: true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                {
                    SortedTreeTableSnapshotInfo <HistorianKey, HistorianValue> snapshotInfo = table.AcquireReadSnapshot();


                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader1 = snapshotInfo.CreateReadSnapshot())
                        using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader2 = snapshotInfo.CreateReadSnapshot())
                        {
                            SortedTreeScannerBase <HistorianKey, HistorianValue> scanner1 = reader1.GetTreeScanner();
                            SortedTreeScannerBase <HistorianKey, HistorianValue> scanner2 = reader2.GetTreeScanner();

                            scanner1.SeekToStart();
                            scanner2.SeekToStart();

                            bool scanner1Read = scanner1.Read(key1, value1);
                            bool scanner2Read = scanner2.Read(key2, value2);

                            while (scanner1Read && scanner2Read)
                            {
                                Assert.AreEqual(key1.Timestamp, key2.Timestamp);
                                Assert.AreEqual(key1.PointID, key2.PointID);
                                Assert.AreEqual(key1.EntryNumber, key2.EntryNumber);
                                Assert.AreEqual(value1.Value1, value2.Value1);
                                Assert.AreEqual(value1.Value2, value2.Value2);
                                Assert.AreEqual(value1.Value3, value2.Value3);

                                scanner1Read = scanner1.Read(key1, value1);
                                scanner2Read = scanner2.Read(key2, value2);
                            }
                        }
                }
            ReadDataFromAFile();
        }
Пример #24
0
        public void TestRollover()
        {
            int       count = 1000000;
            Stopwatch sw    = new Stopwatch();

            using (SortedTreeFile af = SortedTreeFile.CreateInMemory())
                using (SortedTreeTable <AmiKey, AmiKey> table = af.OpenOrCreateTable <AmiKey, AmiKey>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    using (SortedTreeTableEditor <AmiKey, AmiKey> edit = table.BeginEdit())
                    {
                        sw.Start();
                        AmiKey key   = new AmiKey();
                        AmiKey value = new AmiKey();

                        for (int x = 0; x < count; x++)
                        {
                            key.Timestamp = (uint)x;
                            edit.AddPoint(key, value);
                        }

                        edit.Commit();
                        sw.Stop();

                        Console.WriteLine(af.ArchiveSize / 1024.0 / 1024.0);
                        Console.WriteLine(count / sw.Elapsed.TotalSeconds / 1000000);
                    }

                    using (SortedTreeFile af2 = SortedTreeFile.CreateInMemory())
                        using (SortedTreeTable <AmiKey, AmiKey> table2 = af2.OpenOrCreateTable <AmiKey, AmiKey>(new EncodingDefinition(EncodingDefinition.FixedSizeCombinedEncoding.KeyValueEncodingMethod, EncodingDefinition.FixedSizeCombinedEncoding.KeyValueEncodingMethod)))
                            using (SortedTreeTableEditor <AmiKey, AmiKey> edit = table2.BeginEdit())
                            {
                                using (SortedTreeTableReadSnapshot <AmiKey, AmiKey> read = table.BeginRead())
                                    using (SortedTreeScannerBase <AmiKey, AmiKey> scan = read.GetTreeScanner())
                                    {
                                        scan.SeekToStart();
                                        edit.AddPoints(scan);
                                    }
                            }

                    Console.WriteLine(count);
                }
        }
Пример #25
0
        public void ReadDataFromAFile()
        {
            string fileName = @"C:\Temp\ArchiveFile.d2";

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

            using (SortedTreeFile file = SortedTreeFile.OpenFile(fileName, isReadOnly: true))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> snapshot = table.BeginRead())
                    {
                        SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = snapshot.GetTreeScanner();
                        scanner.SeekToStart();
                        while (scanner.Read(key, value))
                        {
                            Console.WriteLine("{0}, {1}, {2}",
                                              key.TimestampAsDate.ToString(), key.PointID, value.AsString);
                        }
                    }
        }
Пример #26
0
        public void TestReadDataFromArchive()
        {
            DebugStopwatch sw    = new DebugStopwatch();
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            string path = Directory.GetFiles(@"c:\temp\Scada\", "*.d2")[0];
            double time;
            double count = 0;

            using (SortedTreeFile file = SortedTreeFile.OpenFile(path, true))
            {
                var table = file.OpenTable <HistorianKey, HistorianValue>();

                time = sw.TimeEvent(() =>
                {
                    count = 0;
                    using (var scan = table.BeginRead())
                    {
                        var t = scan.GetTreeScanner();
                        t.SeekToStart();
                        while (t.Read(key, value))
                        {
                            count++;
                        }
                    }
                });
            }
            Console.WriteLine((count / 1000000 / time).ToString() + " Million PPS");

            //Console.WriteLine("KeyMethodsBase calls");
            //for (int x = 0; x < 23; x++)
            //{
            //    Console.WriteLine(TreeKeyMethodsBase<HistorianKey>.CallMethods[x] + "\t" + ((TreeKeyMethodsBase<HistorianKey>.Method)(x)).ToString());
            //}
            //Console.WriteLine("ValueMethodsBase calls");
            //for (int x = 0; x < 5; x++)
            //{
            //    Console.WriteLine(TreeValueMethodsBase<HistorianValue>.CallMethods[x] + "\t" + ((TreeValueMethodsBase<HistorianValue>.Method)(x)).ToString());
            //}
        }
Пример #27
0
        private TestResults Test(int pageSize)
        {
            Stats.LookupKeys            = 0;
            DiskIoSession.ReadCount     = 0;
            DiskIoSession.WriteCount    = 0;
            Stats.ChecksumCount         = 0;
            DiskIoSession.Lookups       = 0;
            DiskIoSession.CachedLookups = 0;
            long      cnt;
            Stopwatch sw  = new Stopwatch();
            Stopwatch sw2 = new Stopwatch();

            sw.Start();
            using (SortedTreeTable <HistorianKey, HistorianValue> af = SortedTreeFile.CreateInMemory(blockSize: pageSize).OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
            {
                using (SortedTreeTableEditor <HistorianKey, HistorianValue> edit = af.BeginEdit())
                {
                    for (int x = 0; x < 100; x++)
                    {
                        edit.AddPoints(new PointStreamSequential(x * 10000, 10000));
                    }
                    edit.Commit();
                }
                sw.Stop();
                sw2.Start();
                cnt = af.Count();
                sw2.Stop();
            }
            return(new TestResults()
            {
                Count = cnt,
                PageSize = pageSize,
                RateWrite = (float)(1 / sw.Elapsed.TotalSeconds),
                RateRead = (float)(1 / sw2.Elapsed.TotalSeconds),
                ReadCount = DiskIoSession.ReadCount,
                WriteCount = DiskIoSession.WriteCount,
                ChecksumCount = Stats.ChecksumCount,
                Lookups = DiskIoSession.Lookups,
                CachedLookups = DiskIoSession.CachedLookups
            });
        }
Пример #28
0
        public void TestFixed()
        {
            int       count = 10000000;
            Stopwatch sw    = new Stopwatch();

            using (var af = SortedTreeFile.CreateInMemory())
                using (var table = af.OpenOrCreateTable <AmiKey, AmiKey>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    var key   = new AmiKey();
                    var value = new AmiKey();
                    using (var edit = table.BeginEdit())
                    {
                        sw.Start();


                        for (int x = 0; x < count; x++)
                        {
                            key.Timestamp = (uint)x;
                            edit.AddPoint(key, value);
                        }

                        edit.Commit();
                        sw.Stop();

                        Console.WriteLine(af.ArchiveSize / 1024.0 / 1024.0);
                        Console.WriteLine(count / sw.Elapsed.TotalSeconds / 1000000);
                    }

                    using (var read = table.BeginRead())
                        using (var scan = read.GetTreeScanner())
                        {
                            scan.SeekToStart();
                            while (scan.Read(key, value))
                            {
                                count--;
                            }
                        }
                    Console.WriteLine(count);
                }
        }
Пример #29
0
        public void WriteDataToAFile()
        {
            Logger.Console.Verbose = VerboseLevel.All;
            string fileName = @"C:\Temp\ArchiveFile.d2";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            HistorianKey   key   = new HistorianKey();
            HistorianValue value = new HistorianValue();

            using (SortedTreeFile file = SortedTreeFile.CreateFile(fileName))
                using (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding))
                    using (SortedTreeTableEditor <HistorianKey, HistorianValue> editor = table.BeginEdit())
                    {
                        key.TimestampAsDate = DateTime.Now;
                        key.PointID         = 1;
                        value.AsString      = "Test Write";
                        editor.AddPoint(key, value);
                        editor.Commit();
                    }
        }
Пример #30
0
        SortedTreeTable <HistorianKey, HistorianValue> CreateTable()
        {
            var r     = new Random(seed++);
            var key   = new HistorianKey();
            var value = new HistorianValue();
            var file  = SortedTreeFile.CreateInMemory();
            var table = file.OpenOrCreateTable <HistorianKey, HistorianValue>(EncodingDefinition.FixedSizeCombinedEncoding);

            using (var edit = table.BeginEdit())
            {
                for (int x = 0; x < 1000; x++)
                {
                    key.Timestamp   = (ulong)r.Next();
                    key.PointID     = (ulong)r.Next();
                    key.EntryNumber = (ulong)r.Next();
                    edit.AddPoint(key, value);
                }
                edit.Commit();
            }



            return(table);
        }