Hosts all of the components of a SortedTreeStore.
A centralized server hosting model for a SortedTreeStore. This class contains all of the databases, client connections, sockets, user authentication, and core settings for the SortedTreeStore.
Inheritance: GSF.Diagnostics.DisposableLoggingClassBase
 /// <summary>
 /// Creates a <see cref="Client"/>
 /// </summary>
 /// <param name="server">the collection to wrap</param>
 public Client(SnapServer server)
 {
     if (server is null)
     {
         throw new ArgumentNullException("server");
     }
     m_syncRoot           = new object();
     m_connectedDatabases = new Dictionary <string, ClientDatabaseBase>();
     m_server             = server;
     server.RegisterClient(this);
 }
 /// <summary>
 /// Creates a new <see cref="HistorianServer"/> instance.
 /// </summary>
 public HistorianServer(int? port)
 {
     var server = new ServerSettings();
     if (port.HasValue)
     {
         var settings = new SnapSocketListenerSettings() { LocalTcpPort = port.Value };
         settings.DefaultUserCanRead = true;
         settings.DefaultUserCanWrite = true;
         settings.DefaultUserIsAdmin = true;
         server.Listeners.Add(settings);
     }
     // Maintain a member level list of all established archive database engines
     m_host = new SnapServer(server);
 }
        public void VerifyDB()
        {
            //Logger.ReportToConsole(VerboseLevel.All ^ VerboseLevel.DebugLow);
            //Logger.ConsoleSubscriber.AddIgnored(Logger.LookupType("GSF.SortedTreeStore"));
            Globals.MemoryPool.SetMaximumBufferSize(1000 * 1024 * 1024);
            Globals.MemoryPool.SetTargetUtilizationLevel(TargetUtilizationLevels.Low);

            var settings = new HistorianServerDatabaseConfig("DB", "c:\\temp\\benchmark\\", true);
            using (var engine = new SnapServer(settings))
            using (var client = SnapClient.Connect(engine))
            using (var db = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
            using (var scan = db.Read(null, null, null))
            {
                var key = new HistorianKey();
                var value = new HistorianValue();

                Stopwatch sw = new Stopwatch();
                sw.Start();

                for (int x = 0; x < PointsToArchive; x++)
                {
                    if (!scan.Read(key, value))
                        throw new Exception("Missing points");
                    if (key.PointID != (ulong)x)
                        throw new Exception("Corrupt");
                    if (key.Timestamp != 0)
                        throw new Exception("Corrupt");
                    if (key.EntryNumber != 0)
                        throw new Exception("Corrupt");
                    if (value.Value1 != 0)
                        throw new Exception("Corrupt");
                    if (value.Value1 != 0)
                        throw new Exception("Corrupt");
                    if (value.Value1 != 0)
                        throw new Exception("Corrupt");
                }

                double totalTime = sw.Elapsed.TotalSeconds;
                Console.WriteLine("Completed read test in {0:#,##0.00} seconds at {1:#,##0.00} points per second", totalTime, PointsToArchive / totalTime);

                if (scan.Read(key, value))
                    throw new Exception("too many points");
            }
        }
 protected override void Dispose(bool disposing)
 {
     if (!m_disposed)
     {
         if (disposing)
         {
             lock (m_syncRoot)
             {
                 //Must include .ToArray because calling dispose will remove the item
                 //from the m_coonectionDatabase via a callback.
                 foreach (ClientDatabaseBase db in m_connectedDatabases.Values.ToArray())
                 {
                     db.Dispose();
                 }
             }
             m_server.UnRegisterClient(this);
             m_server   = null;
             m_disposed = true;
         }
     }
     base.Dispose(disposing);
 }
Example #5
0
 /// <summary>
 /// Connects to a local <see cref="SnapServer"/>.
 /// </summary>
 /// <param name="host"></param>
 /// <returns></returns>
 public static SnapClient Connect(SnapServer host)
 {
     return(new SnapServer.Client(host));
 }
 /// <summary>
 /// Creates a new <see cref="HistorianServer"/>
 /// </summary>
 public HistorianServer()
 {
     m_host = new SnapServer();
 }
 public SnapServer CreateServer()
 {
     var settings = new HistorianServerDatabaseConfig("PPA", @"C:\Temp\Synchrophasor", true);
     var server = new SnapServer(settings);
     return server;
 }
        public void TestRollover()
        {
            Logger.Console.Verbose = VerboseLevel.All;

            Globals.MemoryPool.SetMaximumBufferSize(4000 * 1024 * 1024L);

            foreach (var file in Directory.GetFiles("c:\\temp\\Test\\", "*.*", SearchOption.AllDirectories))
                File.Delete(file);

            PointCount = 0;

            var settings = new HistorianServerDatabaseConfig("DB", "c:\\temp\\Test\\Main\\", true);
            settings.FinalWritePaths.Add("c:\\temp\\Test\\Rollover\\");

            ulong time = (ulong)DateTime.Now.Ticks;

            using (var engine = new SnapServer(settings))
            using (var client = SnapClient.Connect(engine))
            using (var db = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
            {
                Thread.Sleep(100);
                var key = new HistorianKey();
                var value = new HistorianValue();
                for (int x = 0; x < 100000000; x++)
                {
                    if (x % 100 == 0)
                        Thread.Sleep(10);
                    key.Timestamp = (ulong)time;
                    time += TimeSpan.TicksPerMinute;
                    db.Write(key, value);
                }
            }

            GC.Collect();
            GC.WaitForPendingFinalizers();
            Thread.Sleep(100);
        }
        public void TestWriteSpeedRandom()
        {

            Logger.Console.Verbose = VerboseLevel.All;

            Random r = new Random(1);
            Thread th = new Thread(WriteSpeed);
            th.IsBackground = true;
            th.Start();

            Quit = false;
            foreach (var file in Directory.GetFiles("c:\\temp\\benchmark\\"))
                File.Delete(file);

            PointCount = 0;

            var settings = new HistorianServerDatabaseConfig("DB", "c:\\temp\\benchmark\\", true);

            using (var engine = new SnapServer(settings))
            using (var client = SnapClient.Connect(engine))
            using (var db = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
            {
                Thread.Sleep(100);
                var key = new HistorianKey();
                var value = new HistorianValue();
                for (int x = 0; x < 10000000; x++)
                {
                    key.Timestamp = (ulong)r.Next();
                    key.PointID = (ulong)x;
                    PointCount = x;
                    db.Write(key, value);
                }
            }
            Quit = true;
            th.Join();
            Console.WriteLine("Time (sec)\tPoints");
            foreach (var kvp in PointSamples)
            {
                Console.WriteLine(kvp.Key.ToString() + "\t" + kvp.Value.ToString());
            }
        }
        public void TestWriteSpeed()
        {
            //Logger.ReportToConsole(VerboseLevel.All ^ VerboseLevel.DebugLow);
            //Logger.SetLoggingPath("c:\\temp\\");

            Globals.MemoryPool.SetMaximumBufferSize(4000 * 1024 * 1024L);

            //Thread th = new Thread(WriteSpeed);
            //th.IsBackground = true;
            //th.Start();

            //Quit = false;
            foreach (var file in Directory.GetFiles("c:\\temp\\benchmark\\", "*.*", SearchOption.AllDirectories))
                File.Delete(file);

            //PointCount = 0;

            var settings = new HistorianServerDatabaseConfig("DB", "c:\\temp\\benchmark\\", true);

            using (var engine = new SnapServer(settings))
            using (var client = SnapClient.Connect(engine))
            using (var db = client.GetDatabase<HistorianKey, HistorianValue>("DB"))
            {
                Thread.Sleep(100);
                var key = new HistorianKey();
                var value = new HistorianValue();

                Stopwatch sw = new Stopwatch();
                sw.Start();

                for (int x = 0; x < PointsToArchive; x++)
                {
                    key.PointID = (ulong)x;
                    //PointCount = x;
                    db.Write(key, value);
                }

                double totalTime = sw.Elapsed.TotalSeconds;
                Console.WriteLine("Completed write test in {0:#,##0.00} seconds at {1:#,##0.00} points per second", totalTime, PointsToArchive / totalTime);
            }
            //Quit = true;
            //th.Join();

            //Console.WriteLine("Time (sec)\tPoints");
            //foreach (var kvp in PointSamples)
            //{
            //    Console.WriteLine(kvp.Key.ToString() + "\t" + kvp.Value.ToString());
            //}

            GC.Collect();
            GC.WaitForPendingFinalizers();
            Thread.Sleep(100);
        }