Showing the changes to Source/Applications/GEPLoadTest/Program.cs (1 of 5 files). Show all
Unified · Split
| @@ -0,0 +1,178 @@ | ||
| 1 | +//****************************************************************************************************** | |
| 2 | +// Program.cs - Gbtc | |
| 3 | +// | |
| 4 | +// Copyright © 2020, Grid Protection Alliance. All Rights Reserved. | |
| 5 | +// | |
| 6 | +// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See | |
| 7 | +// the NOTICE file distributed with this work for additional information regarding copyright ownership. | |
| 8 | +// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may | |
| 9 | +// not use this file except in compliance with the License. You may obtain a copy of the License at: | |
| 10 | +// | |
| 11 | +// http://www.opensource.org/licenses/MIT | |
| 12 | +// | |
| 13 | +// Unless agreed to in writing, the subject software distributed under the License is distributed on an | |
| 14 | +// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the | |
| 15 | +// License for the specific language governing permissions and limitations. | |
| 16 | +// | |
| 17 | +// Code Modification History: | |
| 18 | +// ---------------------------------------------------------------------------------------------------- | |
| 19 | +// 05/13/2020 - C. Lackner | |
| 20 | +// Generated original version of source code. | |
| 21 | +// | |
| 22 | +//****************************************************************************************************** | |
| 23 | + | |
| 24 | +using System; | |
| 25 | +using System.Collections.Generic; | |
| 26 | +using System.Data; | |
| 27 | +using System.Text; | |
| 28 | +using System.Timers; | |
| 29 | +using GSF; | |
| 30 | +using GSF.Configuration; | |
| 31 | +using GSF.IO; | |
| 32 | +using GSF.TimeSeries; | |
| 33 | +using GSF.TimeSeries.Transport; | |
| 34 | +using Random = GSF.Security.Cryptography.Random; | |
| 35 | + | |
| 36 | +namespace GEPLoadTest | |
| 37 | +{ | |
| 38 | + class Program | |
| 39 | + { | |
| 40 | + // Define subscription modes for testing | |
| 41 | + | |
| 42 | + static readonly UnsynchronizedSubscriptionInfo unsynchronizedInfo = new UnsynchronizedSubscriptionInfo(false); | |
| 43 | + | |
| 44 | + static readonly DataSubscriber subscriber = new DataSubscriber(); | |
| 45 | + static long dataCount; | |
| 46 | + static readonly object displayLock = new object(); | |
| 47 | + | |
| 48 | + static int nSubscribed = 0; | |
| 49 | + | |
| 50 | + static void Main(string[] args) | |
| 51 | + { | |
| 52 | + // Attach to subscriber events | |
| 53 | + subscriber.StatusMessage += subscriber_StatusMessage; | |
| 54 | + subscriber.ProcessException += subscriber_ProcessException; | |
| 55 | + subscriber.ConnectionEstablished += subscriber_ConnectionEstablished; | |
| 56 | + subscriber.ConnectionTerminated += subscriber_ConnectionTerminated; | |
| 57 | + subscriber.NewMeasurements += subscriber_NewMeasurements; | |
| 58 | + subscriber.MetaDataReceived += subscriber_MetaDataReceived; | |
| 59 | + | |
| 60 | + nSubscribed = 0; | |
| 61 | + | |
| 62 | + | |
| 63 | + // Initialize subscriber | |
| 64 | + //subscriber.ConnectionString = "server=tcp://127.0.0.1:9898; useZeroMQChannel=true"; | |
| 65 | + | |
| 66 | + // Access needed settings from specified categories in configuration file | |
| 67 | + CategorizedSettingsElementCollection reportSettings = ConfigurationFile.Current.Settings["systemSettings"]; | |
| 68 | + reportSettings.Add("server", "localhost:6165", "Server and Port to Load Test"); | |
| 69 | + string server = reportSettings["server"].ValueAs("PPA"); | |
| 70 | + | |
| 71 | + subscriber.ConnectionString = $"server={server}"; | |
| 72 | + subscriber.OperationalModes |= OperationalModes.UseCommonSerializationFormat | OperationalModes.CompressMetadata | OperationalModes.CompressSignalIndexCache | OperationalModes.CompressPayloadData; | |
| 73 | + //subscriber.CompressionModes = CompressionModes.TSSC | CompressionModes.GZip; | |
| 74 | + subscriber.Initialize(); | |
| 75 | + | |
| 76 | + // Start subscriber connection cycle | |
| 77 | + subscriber.Start(); | |
| 78 | + | |
| 79 | + Console.ReadLine(); | |
| 80 | + | |
| 81 | + subscriber.Unsubscribe(); | |
| 82 | + | |
| 83 | + subscriber.StatusMessage -= subscriber_StatusMessage; | |
| 84 | + subscriber.ProcessException -= subscriber_ProcessException; | |
| 85 | + subscriber.ConnectionEstablished -= subscriber_ConnectionEstablished; | |
| 86 | + subscriber.ConnectionTerminated -= subscriber_ConnectionTerminated; | |
| 87 | + subscriber.NewMeasurements -= subscriber_NewMeasurements; | |
| 88 | + | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + static void subscriber_MetaDataReceived(object sender, EventArgs<System.Data.DataSet> e) | |
| 93 | + { | |
| 94 | + DataSet dataSet = e.Argument; | |
| 95 | + dataSet.WriteXml(FilePath.GetAbsolutePath("Metadata.xml"), XmlWriteMode.WriteSchema); | |
| 96 | + Console.WriteLine("Data set serialized with {0} tables...", dataSet.Tables.Count); | |
| 97 | + DataTable measurementTbl = e.Argument.Tables["MeasurementDetail"]; | |
| 98 | + int nMeas = measurementTbl.Rows.Count; | |
| 99 | + | |
| 100 | + if (nMeas != nSubscribed) | |
| 101 | + { | |
| 102 | + StringBuilder connectionString = new StringBuilder(); | |
| 103 | + | |
| 104 | + // Define connection string | |
| 105 | + foreach (DataRow row in measurementTbl.Rows) | |
| 106 | + { | |
| 107 | + connectionString.AppendFormat("{0};", row["ID"]); | |
| 108 | + } | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + Console.WriteLine("Attempt to Subscribe to {0} Points", nMeas); | |
| 113 | + unsynchronizedInfo.FilterExpression = connectionString.ToString(); | |
| 114 | + subscriber.UnsynchronizedSubscribe(unsynchronizedInfo); | |
| 115 | + nSubscribed = nMeas; | |
| 116 | + } | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + } | |
| 122 | + | |
| 123 | + static void subscriber_NewMeasurements(object sender, EventArgs<ICollection<IMeasurement>> e) | |
| 124 | + { | |
| 125 | + // Check to see if total number of added points will exceed process interval used to show periodic | |
| 126 | + // messages of how many points have been archived so far... | |
| 127 | + int interval = 30*nSubscribed; | |
| 128 | + | |
| 129 | + bool showMessage = dataCount + e.Argument.Count >= (dataCount / interval + 1) * interval; | |
| 130 | + | |
| 131 | + dataCount += e.Argument.Count; | |
| 132 | + | |
| 133 | + if (showMessage) | |
| 134 | + { | |
| 135 | + lock (displayLock) | |
| 136 | + { | |
| 137 | + Console.WriteLine(string.Format("{0:N0} measurements have been processed so far...", dataCount)); | |
| 138 | + } | |
| 139 | + | |
| 140 | + } | |
| 141 | + } | |
| 142 | + | |
| 143 | + static void subscriber_ConnectionEstablished(object sender, EventArgs e) | |
| 144 | + { | |
| 145 | + | |
| 146 | + subscriber.SendServerCommand(ServerCommand.MetaDataRefresh); | |
| 147 | + | |
| 148 | + } | |
| 149 | + | |
| 150 | + static void subscriber_ConnectionTerminated(object sender, EventArgs e) | |
| 151 | + { | |
| 152 | + subscriber.Start(); | |
| 153 | + | |
| 154 | + lock (displayLock) | |
| 155 | + { | |
| 156 | + Console.WriteLine("Connection to publisher was terminated, restarting connection cycle..."); | |
| 157 | + } | |
| 158 | + } | |
| 159 | + | |
| 160 | + static void subscriber_ProcessException(object sender, EventArgs<Exception> e) | |
| 161 | + { | |
| 162 | + lock (displayLock) | |
| 163 | + { | |
| 164 | + Console.ForegroundColor = ConsoleColor.Red; | |
| 165 | + Console.WriteLine("EXCEPTION: " + e.Argument.Message); | |
| 166 | + Console.ResetColor(); | |
| 167 | + } | |
| 168 | + } | |
| 169 | + | |
| 170 | + static void subscriber_StatusMessage(object sender, EventArgs<string> e) | |
| 171 | + { | |
| 172 | + lock (displayLock) | |
| 173 | + { | |
| 174 | + Console.WriteLine(e.Argument); | |
| 175 | + } | |
| 176 | + } | |
| 177 | + } | |
| 178 | +} | |