Пример #1
0
 public static long Count(this SortedTreeTable <HistorianKey, HistorianValue> stream)
 {
     using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> read = stream.BeginRead())
     {
         SortedTreeScannerBase <HistorianKey, HistorianValue> scan = read.GetTreeScanner();
         scan.SeekToStart();
         return(scan.Count());
     }
 }
Пример #2
0
        public void TestFixed()
        {
            int       count = 10000000;
            Stopwatch sw    = new Stopwatch();

            using (SortedTreeFile af = SortedTreeFile.CreateInMemory())
                using (SortedTreeTable <AmiKey, AmiKey> table = af.OpenOrCreateTable <AmiKey, AmiKey>(EncodingDefinition.FixedSizeCombinedEncoding))
                {
                    AmiKey key   = new AmiKey();
                    AmiKey value = new AmiKey();
                    using (SortedTreeTableEditor <AmiKey, AmiKey> 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 (SortedTreeTableReadSnapshot <AmiKey, AmiKey> read = table.BeginRead())
                        using (SortedTreeScannerBase <AmiKey, AmiKey> scan = read.GetTreeScanner())
                        {
                            scan.SeekToStart();
                            while (scan.Read(key, value))
                            {
                                count--;
                            }
                        }
                    Console.WriteLine(count);
                }
        }
Пример #3
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);
                                }
                            }
                        }
                    }
                }
        }
Пример #4
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());
                        }
                }
        }
Пример #5
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());
        }
Пример #6
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());
        }
Пример #7
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))
                            {
                                ;
                            }
                        }
        }
        public void TestTwoFiles()
        {
            MemoryPoolTest.TestMemoryLeak();
            ArchiveList <HistorianKey, HistorianValue> list = new ArchiveList <HistorianKey, HistorianValue>(null);

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

            SortedTreeTable <HistorianKey, HistorianValue> master = CreateTable();
            SortedTreeTable <HistorianKey, HistorianValue> table1 = CreateTable();
            SortedTreeTable <HistorianKey, HistorianValue> table2 = CreateTable();

            AddData(master, 100, 100, 100);
            AddData(table1, 100, 100, 100);
            AddData(master, 101, 100, 100);
            AddData(table2, 101, 100, 100);
            using (ArchiveListEditor <HistorianKey, HistorianValue> editor = list.AcquireEditLock())
            {
                editor.Add(table1);
                editor.Add(table2);
            }

            using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> masterRead = master.BeginRead())
            {
                SortedTreeScannerBase <HistorianKey, HistorianValue> masterScan = masterRead.GetTreeScanner();
                masterScan.SeekToStart();
                TreeStreamSequential <HistorianKey, HistorianValue> masterScanSequential = masterScan.TestSequential();

                using (SequentialReaderStream <HistorianKey, HistorianValue> sequencer = new SequentialReaderStream <HistorianKey, HistorianValue>(list))
                {
                    TreeStreamSequential <HistorianKey, HistorianValue> scanner = sequencer.TestSequential();

                    while (scanner.Read(key1, value1))
                    {
                        if (!masterScanSequential.Read(key2, value2))
                        {
                            throw new Exception();
                        }

                        if (!key1.IsEqualTo(key2))
                        {
                            throw new Exception();
                        }

                        if (!value1.IsEqualTo(value2))
                        {
                            throw new Exception();
                        }
                    }
                    if (masterScan.Read(key2, value2))
                    {
                        throw new Exception();
                    }
                }
            }
            master.Dispose();
            list.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }
        public void BenchmarkRawFile()
        {
            MemoryPoolTest.TestMemoryLeak();
            const int Max = 1000000;

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

            SortedTreeTable <HistorianKey, HistorianValue> master = CreateTable();

            AddData(master, 100, 100, Max);


            DebugStopwatch sw = new DebugStopwatch();

            using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> masterRead = master.BeginRead())
            {
                double sec = sw.TimeEvent(() =>
                {
                    SortedTreeScannerBase <HistorianKey, HistorianValue> scanner = masterRead.GetTreeScanner();
                    scanner.SeekToStart();
                    while (scanner.Read(key, value))
                    {
                    }
                });
                System.Console.WriteLine(Max / sec / 1000000);
            }
            master.Dispose();
            MemoryPoolTest.TestMemoryLeak();
        }
Пример #10
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);
                        }
                    }
        }
Пример #11
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();
        }
Пример #12
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 (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();
                        HistorianKey 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);
                        }
                    }
        }
Пример #13
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))
            {
                SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>();

                time = sw.TimeEvent(() =>
                {
                    count = 0;
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> scan = table.BeginRead())
                    {
                        SortedTreeScannerBase <HistorianKey, HistorianValue> 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());
            //}
        }
Пример #14
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 (SortedTreeFile 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 (SortedTreeTable <HistorianKey, HistorianValue> table = file.OpenTable <HistorianKey, HistorianValue>())
                    using (SortedTreeTableReadSnapshot <HistorianKey, HistorianValue> reader = table.BeginRead())
                    {
                        SortedTreeScannerBase <HistorianKey, HistorianValue> 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();
                    }
        }