Unified · Split
| @@ -1481,6 +1481,39 @@ namespace PhasorProtocolAdapters · 1480 unmodified lines | ||
| 1481 | 1481 | return statistic; |
| 1482 | 1482 | } |
| 1483 | 1483 | |
| 1484 | + private static double GetInputStreamStatistic_LifetimeMinimumLatency(object source, string arguments) | |
| 1485 | + { | |
| 1486 | + double statistic = 0.0D; | |
| 1487 | + PhasorMeasurementMapper inputStream = source as PhasorMeasurementMapper; | |
| 1488 | + | |
| 1489 | + if ((object)inputStream != null) | |
| 1490 | + statistic = inputStream.LifetimeMinimumLatency; | |
| 1491 | + | |
| 1492 | + return statistic; | |
| 1493 | + } | |
| 1494 | + | |
| 1495 | + private static double GetInputStreamStatistic_LifetimeMaximumLatency(object source, string arguments) | |
| 1496 | + { | |
| 1497 | + double statistic = 0.0D; | |
| 1498 | + PhasorMeasurementMapper inputStream = source as PhasorMeasurementMapper; | |
| 1499 | + | |
| 1500 | + if ((object)inputStream != null) | |
| 1501 | + statistic = inputStream.LifetimeMaximumLatency; | |
| 1502 | + | |
| 1503 | + return statistic; | |
| 1504 | + } | |
| 1505 | + | |
| 1506 | + private static double GetInputStreamStatistic_LifetimeAverageLatency(object source, string arguments) | |
| 1507 | + { | |
| 1508 | + double statistic = 0.0D; | |
| 1509 | + PhasorMeasurementMapper inputStream = source as PhasorMeasurementMapper; | |
| 1510 | + | |
| 1511 | + if ((object)inputStream != null) | |
| 1512 | + statistic = inputStream.LifetimeAverageLatency; | |
| 1513 | + | |
| 1514 | + return statistic; | |
| 1515 | + } | |
| 1516 | + | |
| 1484 | 1517 | #endregion |
| 1485 | 1518 | |
| 1486 | 1519 | #region [ OutputStream Statistic Calculators ] |
| @@ -1823,6 +1856,61 @@ namespace PhasorProtocolAdapters · 336 unmodified lines | ||
| 1823 | 1856 | return statistic; |
| 1824 | 1857 | } |
| 1825 | 1858 | |
| 1859 | + private static double GetOutputStreamStatistic_LifetimeMinimumLatency(object source, string arguments) | |
| 1860 | + { | |
| 1861 | + double statistic = 0.0D; | |
| 1862 | + PhasorDataConcentratorBase outputStream = source as PhasorDataConcentratorBase; | |
| 1863 | + | |
| 1864 | + if ((object)outputStream != null) | |
| 1865 | + statistic = outputStream.LifetimeMinimumLatency; | |
| 1866 | + | |
| 1867 | + return statistic; | |
| 1868 | + } | |
| 1869 | + | |
| 1870 | + private static double GetOutputStreamStatistic_LifetimeMaximumLatency(object source, string arguments) | |
| 1871 | + { | |
| 1872 | + double statistic = 0.0D; | |
| 1873 | + PhasorDataConcentratorBase outputStream = source as PhasorDataConcentratorBase; | |
| 1874 | + | |
| 1875 | + if ((object)outputStream != null) | |
| 1876 | + statistic = outputStream.LifetimeMaximumLatency; | |
| 1877 | + | |
| 1878 | + return statistic; | |
| 1879 | + } | |
| 1880 | + | |
| 1881 | + private static double GetOutputStreamStatistic_LifetimeAverageLatency(object source, string arguments) | |
| 1882 | + { | |
| 1883 | + double statistic = 0.0D; | |
| 1884 | + PhasorDataConcentratorBase outputStream = source as PhasorDataConcentratorBase; | |
| 1885 | + | |
| 1886 | + if ((object)outputStream != null) | |
| 1887 | + statistic = outputStream.LifetimeAverageLatency; | |
| 1888 | + | |
| 1889 | + return statistic; | |
| 1890 | + } | |
| 1891 | + | |
| 1892 | + private static double GetOutputStreamStatistic_LifetimeDiscardedMeasurements(object source, string arguments) | |
| 1893 | + { | |
| 1894 | + double statistic = 0.0D; | |
| 1895 | + PhasorDataConcentratorBase outputStream = source as PhasorDataConcentratorBase; | |
| 1896 | + | |
| 1897 | + if ((object)outputStream != null) | |
| 1898 | + statistic = outputStream.DiscardedMeasurements; | |
| 1899 | + | |
| 1900 | + return statistic; | |
| 1901 | + } | |
| 1902 | + | |
| 1903 | + private static double GetOutputStreamStatistic_LifetimeDownsampledMeasurements(object source, string arguments) | |
| 1904 | + { | |
| 1905 | + double statistic = 0.0D; | |
| 1906 | + PhasorDataConcentratorBase outputStream = source as PhasorDataConcentratorBase; | |
| 1907 | + | |
| 1908 | + if ((object)outputStream != null) | |
| 1909 | + statistic = outputStream.DownsampledMeasurements; | |
| 1910 | + | |
| 1911 | + return statistic; | |
| 1912 | + } | |
| 1913 | + | |
| 1826 | 1914 | #endregion |
| 1827 | 1915 | |
| 1828 | 1916 | #endregion |
| @@ -190,6 +190,10 @@ namespace PhasorProtocolAdapters · 189 unmodified lines | ||
| 190 | 190 | private long m_measurementsPerSecondCount; |
| 191 | 191 | private long m_measurementsInSecond; |
| 192 | 192 | private long m_lastSecondsSinceEpoch; |
| 193 | + private long m_lifetimeTotalLatency; | |
| 194 | + private long m_lifetimeMinimumLatency; | |
| 195 | + private long m_lifetimeMaximumLatency; | |
| 196 | + private long m_lifetimeLatencyMeasurements; | |
| 193 | 197 | |
| 194 | 198 | private bool m_disposed; |
| 195 | 199 | |
| @@ -778,6 +782,42 @@ namespace PhasorProtocolAdapters · 582 unmodified lines | ||
| 778 | 782 | } |
| 779 | 783 | } |
| 780 | 784 | |
| 785 | + /// <summary> | |
| 786 | + /// Gets the minimum latency calculated over the full lifetime of the output stream. | |
| 787 | + /// </summary> | |
| 788 | + public int LifetimeMinimumLatency | |
| 789 | + { | |
| 790 | + get | |
| 791 | + { | |
| 792 | + return (int)Ticks.ToMilliseconds(m_lifetimeMinimumLatency); | |
| 793 | + } | |
| 794 | + } | |
| 795 | + | |
| 796 | + /// <summary> | |
| 797 | + /// Gets the maximum latency calculated over the full lifetime of the output stream. | |
| 798 | + /// </summary> | |
| 799 | + public int LifetimeMaximumLatency | |
| 800 | + { | |
| 801 | + get | |
| 802 | + { | |
| 803 | + return (int)Ticks.ToMilliseconds(m_lifetimeMaximumLatency); | |
| 804 | + } | |
| 805 | + } | |
| 806 | + | |
| 807 | + /// <summary> | |
| 808 | + /// Gets the average latency calculated over the full lifetime of the output stream. | |
| 809 | + /// </summary> | |
| 810 | + public int LifetimeAverageLatency | |
| 811 | + { | |
| 812 | + get | |
| 813 | + { | |
| 814 | + if (m_lifetimeLatencyMeasurements == 0) | |
| 815 | + return -1; | |
| 816 | + | |
| 817 | + return (int)Ticks.ToMilliseconds(m_lifetimeTotalLatency / m_lifetimeLatencyMeasurements); | |
| 818 | + } | |
| 819 | + } | |
| 820 | + | |
| 781 | 821 | #endregion |
| 782 | 822 | |
| 783 | 823 | #region [ Methods ] |
| @@ -1402,6 +1442,10 @@ namespace PhasorProtocolAdapters · 618 unmodified lines | ||
| 1402 | 1442 | { |
| 1403 | 1443 | m_lifetimeMeasurements = 0L; |
| 1404 | 1444 | m_totalBytesSent = 0L; |
| 1445 | + m_lifetimeTotalLatency = 0L; | |
| 1446 | + m_lifetimeMinimumLatency = 0L; | |
| 1447 | + m_lifetimeMaximumLatency = 0L; | |
| 1448 | + m_lifetimeLatencyMeasurements = 0L; | |
| 1405 | 1449 | } |
| 1406 | 1450 | |
| 1407 | 1451 | /// <summary> |
| @@ -1605,6 +1649,15 @@ namespace PhasorProtocolAdapters · 197 unmodified lines | ||
| 1605 | 1649 | m_totalLatency += latency; |
| 1606 | 1650 | m_latencyMeasurements++; |
| 1607 | 1651 | |
| 1652 | + if (m_lifetimeMinimumLatency > latency || m_lifetimeMinimumLatency == 0) | |
| 1653 | + m_lifetimeMinimumLatency = latency; | |
| 1654 | + | |
| 1655 | + if (m_lifetimeMaximumLatency < latency || m_lifetimeMaximumLatency == 0) | |
| 1656 | + m_lifetimeMaximumLatency = latency; | |
| 1657 | + | |
| 1658 | + m_lifetimeTotalLatency += latency; | |
| 1659 | + m_lifetimeLatencyMeasurements++; | |
| 1660 | + | |
| 1608 | 1661 | // Track measurement count and throughput statistics |
| 1609 | 1662 | int measurementCount = frame.Measurements.Count; |
| 1610 | 1663 | m_lifetimeMeasurements += measurementCount; |
| @@ -223,6 +223,10 @@ namespace PhasorProtocolAdapters · 222 unmodified lines | ||
| 223 | 223 | private long m_measurementsPerSecondCount; |
| 224 | 224 | private long m_measurementsInSecond; |
| 225 | 225 | private long m_lastSecondsSinceEpoch; |
| 226 | + private long m_lifetimeTotalLatency; | |
| 227 | + private long m_lifetimeMinimumLatency; | |
| 228 | + private long m_lifetimeMaximumLatency; | |
| 229 | + private long m_lifetimeLatencyMeasurements; | |
| 226 | 230 | |
| 227 | 231 | private bool m_disposed; |
| 228 | 232 | |
| @@ -842,7 +846,7 @@ namespace PhasorProtocolAdapters · 613 unmodified lines | ||
| 842 | 846 | } |
| 843 | 847 | |
| 844 | 848 | /// <summary> |
| 845 | − /// Gets the total number of measurements processed through this data publisher over the lifetime of the publisher. | |
| 849 | + /// Gets the total number of measurements processed through this data publisher over the lifetime of the input stream. | |
| 846 | 850 | /// </summary> |
| 847 | 851 | public long LifetimeMeasurements |
| 848 | 852 | { |
| @@ -888,6 +892,42 @@ namespace PhasorProtocolAdapters · 39 unmodified lines | ||
| 888 | 892 | } |
| 889 | 893 | } |
| 890 | 894 | |
| 895 | + /// <summary> | |
| 896 | + /// Gets the minimum latency calculated over the full lifetime of the input stream. | |
| 897 | + /// </summary> | |
| 898 | + public int LifetimeMinimumLatency | |
| 899 | + { | |
| 900 | + get | |
| 901 | + { | |
| 902 | + return (int)Ticks.ToMilliseconds(m_lifetimeMinimumLatency); | |
| 903 | + } | |
| 904 | + } | |
| 905 | + | |
| 906 | + /// <summary> | |
| 907 | + /// Gets the maximum latency calculated over the full lifetime of the input stream. | |
| 908 | + /// </summary> | |
| 909 | + public int LifetimeMaximumLatency | |
| 910 | + { | |
| 911 | + get | |
| 912 | + { | |
| 913 | + return (int)Ticks.ToMilliseconds(m_lifetimeMaximumLatency); | |
| 914 | + } | |
| 915 | + } | |
| 916 | + | |
| 917 | + /// <summary> | |
| 918 | + /// Gets the average latency calculated over the full lifetime of the input stream. | |
| 919 | + /// </summary> | |
| 920 | + public int LifetimeAverageLatency | |
| 921 | + { | |
| 922 | + get | |
| 923 | + { | |
| 924 | + if (m_lifetimeLatencyMeasurements == 0) | |
| 925 | + return -1; | |
| 926 | + | |
| 927 | + return (int)Ticks.ToMilliseconds(m_lifetimeTotalLatency / m_lifetimeLatencyMeasurements); | |
| 928 | + } | |
| 929 | + } | |
| 930 | + | |
| 891 | 931 | #endregion |
| 892 | 932 | |
| 893 | 933 | #region [ Methods ] |
| @@ -1417,6 +1457,10 @@ namespace PhasorProtocolAdapters · 523 unmodified lines | ||
| 1417 | 1457 | public virtual void ResetLifetimeCounters() |
| 1418 | 1458 | { |
| 1419 | 1459 | m_lifetimeMeasurements = 0L; |
| 1460 | + m_lifetimeTotalLatency = 0L; | |
| 1461 | + m_lifetimeMinimumLatency = 0L; | |
| 1462 | + m_lifetimeMaximumLatency = 0L; | |
| 1463 | + m_lifetimeLatencyMeasurements = 0L; | |
| 1420 | 1464 | |
| 1421 | 1465 | if ((object)m_frameParser != null) |
| 1422 | 1466 | m_frameParser.ResetTotalBytesReceived(); |
| @@ -1731,6 +1775,15 @@ namespace PhasorProtocolAdapters · 308 unmodified lines | ||
| 1731 | 1775 | m_totalLatency += latency; |
| 1732 | 1776 | m_latencyMeasurements++; |
| 1733 | 1777 | |
| 1778 | + if (m_lifetimeMinimumLatency > latency || m_lifetimeMinimumLatency == 0) | |
| 1779 | + m_lifetimeMinimumLatency = latency; | |
| 1780 | + | |
| 1781 | + if (m_lifetimeMaximumLatency < latency || m_lifetimeMaximumLatency == 0) | |
| 1782 | + m_lifetimeMaximumLatency = latency; | |
| 1783 | + | |
| 1784 | + m_lifetimeTotalLatency += latency; | |
| 1785 | + m_lifetimeLatencyMeasurements++; | |
| 1786 | + | |
| 1734 | 1787 | // Loop through each parsed device in the data frame |
| 1735 | 1788 | foreach (IDataCell parsedDevice in frame.Cells) |
| 1736 | 1789 | { |
| @@ -35,6 +35,7 @@ using System.Data; · 34 unmodified lines | ||
| 35 | 35 | using System.Diagnostics; |
| 36 | 36 | using System.Diagnostics.CodeAnalysis; |
| 37 | 37 | using System.IO; |
| 38 | +using System.Linq; | |
| 38 | 39 | using System.Net; |
| 39 | 40 | using System.Reflection; |
| 40 | 41 | using System.Runtime; |
| @@ -511,7 +512,7 @@ namespace GSF.TimeSeries · 470 unmodified lines | ||
| 511 | 512 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Invoke", "Invokes a command for specified adapter", InvokeRequestHandler)); |
| 512 | 513 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ListCommands", "Displays possible commands for specified adapter", ListCommandsRequestHandler)); |
| 513 | 514 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Initialize", "Initializes specified adapter or collection", InitializeRequestHandler)); |
| 514 | − m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadConfig", "Manually reloads the system configuration", ReloadConfigRequstHandler)); | |
| 515 | + m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("ReloadConfig", "Manually reloads the system configuration", ReloadConfigRequestHandler)); | |
| 515 | 516 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("UpdateConfigFile", "Updates an option in the configuration file", UpdateConfigFileRequestHandler)); |
| 516 | 517 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Authenticate", "Authenticates network shares for health and status exports", AuthenticateRequestHandler)); |
| 517 | 518 | m_serviceHelper.ClientRequestHandlers.Add(new ClientRequestHandler("Restart", "Attempts to restart the host service", RestartServiceHandler)); |
| @@ -742,7 +743,7 @@ namespace GSF.TimeSeries · 224 unmodified lines | ||
| 742 | 743 | adapterType = assembly.GetType(adapterTypeName); |
| 743 | 744 | |
| 744 | 745 | connection = (IDbConnection)Activator.CreateInstance(connectionType); |
| 745 | − connection.ConnectionString = m_connectionString; | |
| 746 | + connection.ConnectionString = connectionString; | |
| 746 | 747 | connection.Open(); |
| 747 | 748 | |
| 748 | 749 | DisplayStatusMessage("Database configuration connection opened.", UpdateType.Information); |
| @@ -923,6 +924,191 @@ namespace GSF.TimeSeries · 174 unmodified lines | ||
| 923 | 924 | return configuration; |
| 924 | 925 | } |
| 925 | 926 | |
| 927 | + private DataSet GetAugmentedConfigurationDataSet(ConfigurationType configType, string connectionString, string dataProviderString) | |
| 928 | + { | |
| 929 | + DataSet configuration = null; | |
| 930 | + bool configException = false; | |
| 931 | + Ticks startTime = PrecisionTimer.UtcNow.Ticks; | |
| 932 | + double elapsedTime; | |
| 933 | + | |
| 934 | + IDbConnection connection = null; | |
| 935 | + Dictionary<string, string> settings; | |
| 936 | + string assemblyName, connectionTypeName, adapterTypeName; | |
| 937 | + Assembly assembly; | |
| 938 | + Type connectionType, adapterType; | |
| 939 | + DataTable entities, source, destination; | |
| 940 | + | |
| 941 | + if (configType != ConfigurationType.Database) | |
| 942 | + throw new InvalidOperationException("Configuration augmentation only supported for database configurations."); | |
| 943 | + | |
| 944 | + try | |
| 945 | + { | |
| 946 | + // Attempt to load configuration from a database connection | |
| 947 | + settings = dataProviderString.ParseKeyValuePairs(); | |
| 948 | + assemblyName = settings["AssemblyName"].ToNonNullString(); | |
| 949 | + connectionTypeName = settings["ConnectionType"].ToNonNullString(); | |
| 950 | + adapterTypeName = settings["AdapterType"].ToNonNullString(); | |
| 951 | + | |
| 952 | + if (string.IsNullOrWhiteSpace(connectionTypeName)) | |
| 953 | + throw new InvalidOperationException("Database connection type was not defined."); | |
| 954 | + | |
| 955 | + if (string.IsNullOrWhiteSpace(adapterTypeName)) | |
| 956 | + throw new InvalidOperationException("Database adapter type was not defined."); | |
| 957 | + | |
| 958 | + assembly = Assembly.Load(new AssemblyName(assemblyName)); | |
| 959 | + connectionType = assembly.GetType(connectionTypeName); | |
| 960 | + adapterType = assembly.GetType(adapterTypeName); | |
| 961 | + | |
| 962 | + connection = (IDbConnection)Activator.CreateInstance(connectionType); | |
| 963 | + connection.ConnectionString = connectionString; | |
| 964 | + connection.Open(); | |
| 965 | + | |
| 966 | + DisplayStatusMessage("Database configuration connection opened.", UpdateType.Information); | |
| 967 | + | |
| 968 | + configuration = m_iaonSession.DataSource.Copy(); | |
| 969 | + | |
| 970 | + // Load configuration entities defined in database | |
| 971 | + entities = connection.RetrieveData(adapterType, "SELECT * FROM ConfigurationEntity WHERE Enabled <> 0 ORDER BY LoadOrder"); | |
| 972 | + entities.TableName = "ConfigurationEntity"; | |
| 973 | + | |
| 974 | + // Add configuration entities table to system configuration for reference | |
| 975 | + configuration.Tables.Remove("ConfigurationEntity"); | |
| 976 | + configuration.Tables.Add(entities.Copy()); | |
| 977 | + | |
| 978 | + Ticks operationStartTime; | |
| 979 | + double operationElapsedTime; | |
| 980 | + | |
| 981 | + // Add each configuration entity to the system configuration | |
| 982 | + foreach (DataRow entityRow in entities.Rows) | |
| 983 | + { | |
| 984 | + source = null; | |
| 985 | + destination = null; | |
| 986 | + | |
| 987 | + operationStartTime = PrecisionTimer.UtcNow.Ticks; | |
| 988 | + | |
| 989 | + // Attempt to query for updated | |
| 990 | + if (configuration.Tables.Contains(entityRow["RuntimeName"].ToString())) | |
| 991 | + { | |
| 992 | + destination = configuration.Tables[entityRow["RuntimeName"].ToString()]; | |
| 993 | + | |
| 994 | + if (destination.Columns.Contains("UpdatedOn")) | |
| 995 | + { | |
| 996 | + IEnumerable<object> column = destination.Rows.Cast<DataRow>().Select(row => row["UpdatedOn"]); | |
| 997 | + | |
| 998 | + object maxValue = null; | |
| 999 | + DateTime maxTimeOfLastUpdate = DateTime.MinValue; | |
| 1000 | + DateTime timeOfLastUpdate; | |
| 1001 | + | |
| 1002 | + foreach (object value in column) | |
| 1003 | + { | |
| 1004 | + if (value == null) | |
| 1005 | + continue; | |
| 1006 | + | |
| 1007 | + timeOfLastUpdate = (value as DateTime?) ?? DateTime.Parse(value.ToString()); | |
| 1008 | + | |
| 1009 | + if (maxValue == null || timeOfLastUpdate > maxTimeOfLastUpdate) | |
| 1010 | + { | |
| 1011 | + maxTimeOfLastUpdate = timeOfLastUpdate; | |
| 1012 | + maxValue = value; | |
| 1013 | + } | |
| 1014 | + } | |
| 1015 | + | |
| 1016 | + if (maxValue != null) | |
| 1017 | + { | |
| 1018 | + string param = (adapterType.Name == "OracleDataAdapter") ? ":updatedOn" : "@updatedOn"; | |
| 1019 | + string query = string.Format("SELECT * FROM {0} WHERE NodeID = {1} AND UpdatedOn > {2}", entityRow["SourceName"].ToString(), m_nodeIDQueryString, param); | |
| 1020 | + source = connection.RetrieveData(adapterType, query, DataExtensions.DefaultTimeoutDuration, maxValue); | |
| 1021 | + } | |
| 1022 | + } | |
| 1023 | + } | |
| 1024 | + | |
| 1025 | + if ((object)source == null) | |
| 1026 | + { | |
| 1027 | + // Load configuration entity data filtered by node ID | |
| 1028 | + source = connection.RetrieveData(adapterType, string.Format("SELECT * FROM {0} WHERE NodeID={1}", entityRow["SourceName"].ToString(), m_nodeIDQueryString)); | |
| 1029 | + | |
| 1030 | + // Clone data source | |
| 1031 | + destination = source.Clone(); | |
| 1032 | + | |
| 1033 | + // Update table name as defined in configuration entity | |
| 1034 | + source.TableName = entityRow["RuntimeName"].ToString(); | |
| 1035 | + | |
| 1036 | + // Remove old data table from the system configuration | |
| 1037 | + if (configuration.Tables.Contains(source.TableName)) | |
| 1038 | + configuration.Tables.Remove(source.TableName); | |
| 1039 | + | |
| 1040 | + // Add entity configuration data to system configuration | |
| 1041 | + configuration.Tables.Add(destination); | |
| 1042 | + } | |
| 1043 | + | |
| 1044 | + operationElapsedTime = (PrecisionTimer.UtcNow.Ticks - operationStartTime).ToSeconds(); | |
| 1045 | + DisplayStatusMessage("Loaded {0} row{1} from \"{2}\" in {3}...", UpdateType.Information, source.Rows.Count, source.Rows.Count == 1 ? "" : "s", source.TableName, operationElapsedTime < 0.01D ? "less than a second" : operationElapsedTime.ToString("0.00") + " seconds"); | |
| 1046 | + | |
| 1047 | + operationStartTime = PrecisionTimer.UtcNow.Ticks; | |
| 1048 | + | |
| 1049 | + // Get destination column collection | |
| 1050 | + DataColumnCollection columns = destination.Columns; | |
| 1051 | + | |
| 1052 | + // Remove redundant node ID column | |
| 1053 | + if (columns.Contains("NodeID")) | |
| 1054 | + columns.Remove("NodeID"); | |
| 1055 | + | |
| 1056 | + // Pre-cache column index translation after removal of NodeID column to speed data copy | |
| 1057 | + Dictionary<int, int> columnIndex = new Dictionary<int, int>(); | |
| 1058 | + | |
| 1059 | + foreach (DataColumn column in columns) | |
| 1060 | + { | |
| 1061 | + columnIndex[column.Ordinal] = source.Columns[column.ColumnName].Ordinal; | |
| 1062 | + } | |
| 1063 | + | |
| 1064 | + // Manually copy-in each row into table | |
| 1065 | + foreach (DataRow sourceRow in source.Rows) | |
| 1066 | + { | |
| 1067 | + DataRow newRow = destination.NewRow(); | |
| 1068 | + | |
| 1069 | + // Copy each column of data in the current row | |
| 1070 | + for (int x = 0; x < columns.Count; x++) | |
| 1071 | + { | |
| 1072 | + newRow[x] = sourceRow[columnIndex[x]]; | |
| 1073 | + } | |
| 1074 | + | |
| 1075 | + // Add new row to destination table | |
| 1076 | + destination.Rows.Add(newRow); | |
| 1077 | + } | |
| 1078 | + | |
| 1079 | + operationElapsedTime = (PrecisionTimer.UtcNow.Ticks - operationStartTime).ToSeconds(); | |
| 1080 | + | |
| 1081 | + DisplayStatusMessage("{0} configuration pre-cache completed in {1}.", UpdateType.Information, source.TableName, operationElapsedTime < 0.01D ? "less than a second" : operationElapsedTime.ToString("0.00") + " seconds"); | |
| 1082 | + } | |
| 1083 | + | |
| 1084 | + DisplayStatusMessage("Database configuration successfully loaded.", UpdateType.Information); | |
| 1085 | + | |
| 1086 | + CacheCurrentConfiguration(configuration); | |
| 1087 | + } | |
| 1088 | + catch (Exception ex) | |
| 1089 | + { | |
| 1090 | + configException = true; | |
| 1091 | + DisplayStatusMessage("Failed to load database configuration due to exception: {0} Attempting to use last known good configuration.", UpdateType.Warning, ex.Message); | |
| 1092 | + m_serviceHelper.ErrorLogger.Log(ex); | |
| 1093 | + configuration = null; | |
| 1094 | + } | |
| 1095 | + finally | |
| 1096 | + { | |
| 1097 | + if (connection != null) | |
| 1098 | + connection.Dispose(); | |
| 1099 | + | |
| 1100 | + DisplayStatusMessage("Database configuration connection closed.", UpdateType.Information); | |
| 1101 | + } | |
| 1102 | + | |
| 1103 | + if (!configException) | |
| 1104 | + { | |
| 1105 | + elapsedTime = (PrecisionTimer.UtcNow.Ticks - startTime).ToSeconds(); | |
| 1106 | + DisplayStatusMessage("{0} configuration load process completed in {1}...", UpdateType.Information, configType, elapsedTime < 0.01D ? "less than a second" : elapsedTime.ToString("0.00") + " seconds"); | |
| 1107 | + } | |
| 1108 | + | |
| 1109 | + return configuration; | |
| 1110 | + } | |
| 1111 | + | |
| 926 | 1112 | // Execute any defined startup data operations |
| 927 | 1113 | private void ExecuteStartupDataOperations(IDbConnection connection, Type adapterType) |
| 928 | 1114 | { |
| @@ -1978,7 +2164,7 @@ namespace GSF.TimeSeries · 1049 unmodified lines | ||
| 1978 | 2164 | /// Manually reloads system configuration. |
| 1979 | 2165 | /// </summary> |
| 1980 | 2166 | /// <param name="requestInfo"><see cref="ClientRequestInfo"/> instance containing the client request.</param> |
| 1981 | − protected virtual void ReloadConfigRequstHandler(ClientRequestInfo requestInfo) | |
| 2167 | + protected virtual void ReloadConfigRequestHandler(ClientRequestInfo requestInfo) | |
| 1982 | 2168 | { |
| 1983 | 2169 | if (requestInfo.Request.Arguments.ContainsHelpRequest) |
| 1984 | 2170 | { |
| @@ -2063,6 +2249,56 @@ namespace GSF.TimeSeries · 78 unmodified lines | ||
| 2063 | 2249 | } |
| 2064 | 2250 | } |
| 2065 | 2251 | |
| 2252 | + /// <summary> | |
| 2253 | + /// Manually reloads system configuration. | |
| 2254 | + /// </summary> | |
| 2255 | + /// <param name="requestInfo"><see cref="ClientRequestInfo"/> instance containing the client request.</param> | |
| 2256 | + protected virtual void AugmentConfigRequestHandler(ClientRequestInfo requestInfo) | |
| 2257 | + { | |
| 2258 | + if (requestInfo.Request.Arguments.ContainsHelpRequest) | |
| 2259 | + { | |
| 2260 | + StringBuilder helpMessage = new StringBuilder(); | |
| 2261 | + | |
| 2262 | + helpMessage.Append("Manually reloads system configuration."); | |
| 2263 | + helpMessage.AppendLine(); | |
| 2264 | + helpMessage.AppendLine(); | |
| 2265 | + helpMessage.Append(" Usage:"); | |
| 2266 | + helpMessage.AppendLine(); | |
| 2267 | + helpMessage.Append(" ReloadConfig [Options]"); | |
| 2268 | + helpMessage.AppendLine(); | |
| 2269 | + helpMessage.AppendLine(); | |
| 2270 | + helpMessage.Append(" Options:"); | |
| 2271 | + helpMessage.AppendLine(); | |
| 2272 | + helpMessage.Append(" -?".PadRight(20)); | |
| 2273 | + helpMessage.Append("Displays this help message"); | |
| 2274 | + helpMessage.AppendLine(); | |
| 2275 | + | |
| 2276 | + DisplayResponseMessage(requestInfo, helpMessage.ToString()); | |
| 2277 | + } | |
| 2278 | + else | |
| 2279 | + { | |
| 2280 | + DataSet dataSource = null; | |
| 2281 | + | |
| 2282 | + DisplayStatusMessage("Loading system configuration...", UpdateType.Information); | |
| 2283 | + dataSource = GetAugmentedConfigurationDataSet(m_configurationType, m_connectionString, m_dataProviderString); | |
| 2284 | + | |
| 2285 | + if ((object)dataSource != null) | |
| 2286 | + { | |
| 2287 | + // Update data source on all adapters in all collections | |
| 2288 | + m_iaonSession.DataSource = dataSource; | |
| 2289 | + m_iaonSession.AllAdapters.UpdateCollectionConfigurations(); | |
| 2290 | + SendResponse(requestInfo, true, "System configuration was successfully augmented."); | |
| 2291 | + } | |
| 2292 | + else | |
| 2293 | + { | |
| 2294 | + SendResponse(requestInfo, false, "System configuration failed to augment."); | |
| 2295 | + } | |
| 2296 | + | |
| 2297 | + // Spawn routing table calculation updates | |
| 2298 | + m_iaonSession.RecalculateRoutingTables(); | |
| 2299 | + } | |
| 2300 | + } | |
| 2301 | + | |
| 2066 | 2302 | /// <summary> |
| 2067 | 2303 | /// Updates an option in the configuration file. |
| 2068 | 2304 | /// </summary> |
| @@ -158,6 +158,39 @@ namespace GSF.TimeSeries.Statistics · 157 unmodified lines | ||
| 158 | 158 | return statistic; |
| 159 | 159 | } |
| 160 | 160 | |
| 161 | + private static double GetSubscriberStatistic_LifetimeMinimumLatency(object source, string arguments) | |
| 162 | + { | |
| 163 | + double statistic = 0.0D; | |
| 164 | + DataSubscriber subscriber = source as DataSubscriber; | |
| 165 | + | |
| 166 | + if ((object)subscriber != null) | |
| 167 | + statistic = subscriber.LifetimeMinimumLatency; | |
| 168 | + | |
| 169 | + return statistic; | |
| 170 | + } | |
| 171 | + | |
| 172 | + private static double GetSubscriberStatistic_LifetimeMaximumLatency(object source, string arguments) | |
| 173 | + { | |
| 174 | + double statistic = 0.0D; | |
| 175 | + DataSubscriber subscriber = source as DataSubscriber; | |
| 176 | + | |
| 177 | + if ((object)subscriber != null) | |
| 178 | + statistic = subscriber.LifetimeMaximumLatency; | |
| 179 | + | |
| 180 | + return statistic; | |
| 181 | + } | |
| 182 | + | |
| 183 | + private static double GetSubscriberStatistic_LifetimeAverageLatency(object source, string arguments) | |
| 184 | + { | |
| 185 | + double statistic = 0.0D; | |
| 186 | + DataSubscriber subscriber = source as DataSubscriber; | |
| 187 | + | |
| 188 | + if ((object)subscriber != null) | |
| 189 | + statistic = subscriber.LifetimeAverageLatency; | |
| 190 | + | |
| 191 | + return statistic; | |
| 192 | + } | |
| 193 | + | |
| 161 | 194 | #endregion |
| 162 | 195 | |
| 163 | 196 | #region [ Publisher Statistics ] |
| @@ -266,6 +299,39 @@ namespace GSF.TimeSeries.Statistics · 102 unmodified lines | ||
| 266 | 299 | return statistic; |
| 267 | 300 | } |
| 268 | 301 | |
| 302 | + private static double GetPublisherStatistic_LifetimeMinimumLatency(object source, string arguments) | |
| 303 | + { | |
| 304 | + double statistic = 0.0D; | |
| 305 | + DataPublisher publisher = source as DataPublisher; | |
| 306 | + | |
| 307 | + if ((object)publisher != null) | |
| 308 | + statistic = publisher.LifetimeMinimumLatency; | |
| 309 | + | |
| 310 | + return statistic; | |
| 311 | + } | |
| 312 | + | |
| 313 | + private static double GetPublisherStatistic_LifetimeMaximumLatency(object source, string arguments) | |
| 314 | + { | |
| 315 | + double statistic = 0.0D; | |
| 316 | + DataPublisher publisher = source as DataPublisher; | |
| 317 | + | |
| 318 | + if ((object)publisher != null) | |
| 319 | + statistic = publisher.LifetimeMaximumLatency; | |
| 320 | + | |
| 321 | + return statistic; | |
| 322 | + } | |
| 323 | + | |
| 324 | + private static double GetPublisherStatistic_LifetimeAverageLatency(object source, string arguments) | |
| 325 | + { | |
| 326 | + double statistic = 0.0D; | |
| 327 | + DataPublisher publisher = source as DataPublisher; | |
| 328 | + | |
| 329 | + if ((object)publisher != null) | |
| 330 | + statistic = publisher.LifetimeAverageLatency; | |
| 331 | + | |
| 332 | + return statistic; | |
| 333 | + } | |
| 334 | + | |
| 269 | 335 | #endregion |
| 270 | 336 | |
| 271 | 337 | private static readonly StatisticValueStateCache s_statisticValueCache = new StatisticValueStateCache(); |
| @@ -183,7 +183,7 @@ namespace GSF.TimeSeries · 182 unmodified lines | ||
| 183 | 183 | "Average number of IPv4 datagrams received by this process per second." |
| 184 | 184 | }; |
| 185 | 185 | |
| 186 | − string[] SubscriberStatNames = { "Subscriber Connected", "Subscriber Authenticated", "Processed Measurements", "Total Bytes Received", "Authorized Signal Count", "Unauthorized Signal Count", "Lifetime Measurements", "Lifetime Bytes Received", "Minimum Measurements Per Second", "Maximum Measurements Per Second", "Average Measurements Per Second" }; | |
| 186 | + string[] SubscriberStatNames = { "Subscriber Connected", "Subscriber Authenticated", "Processed Measurements", "Total Bytes Received", "Authorized Signal Count", "Unauthorized Signal Count", "Lifetime Measurements", "Lifetime Bytes Received", "Minimum Measurements Per Second", "Maximum Measurements Per Second", "Average Measurements Per Second", "Lifetime Minimum Latency", "Lifetime Maximum Latency", "Lifetime Average Latency" }; | |
| 187 | 187 | |
| 188 | 188 | string[] SubscriberStatDescriptions = { "Boolean value representing if the subscriber was continually connected during last reporting interval.", |
| 189 | 189 | "Boolean value representing if the subscriber was authenticated to the publisher during last reporting interval.", |
| @@ -195,12 +195,15 @@ namespace GSF.TimeSeries · 5 unmodified lines | ||
| 195 | 195 | "Number of bytes received from subscriber during the lifetime of the subscriber.", |
| 196 | 196 | "The minimum number of measurements received per second during the last reporting interval.", |
| 197 | 197 | "The maximum number of measurements received per second during the last reporting interval.", |
| 198 | − "The average number of measurements received per second during the last reporting interval." | |
| 198 | + "The average number of measurements received per second during the last reporting interval.", | |
| 199 | + "Minimum latency from output stream, in milliseconds, during the lifetime of the subscriber.", | |
| 200 | + "Maximum latency from output stream, in milliseconds, during the lifetime of the subscriber.", | |
| 201 | + "Average latency from output stream, in milliseconds, during the lifetime of the subscriber." | |
| 199 | 202 | }; |
| 200 | 203 | |
| 201 | − string[] SubscriberStatMethodSuffix = { "Connected", "Authenticated", "ProcessedMeasurements", "TotalBytesReceived", "AuthorizedCount", "UnauthorizedCount", "LifetimeMeasurements", "LifetimeBytesReceived", "MinimumMeasurementsPerSecond", "MaximumMeasurementsPerSecond", "AverageMeasurementsPerSecond" }; | |
| 202 | − string[] SubscriberStatTypes = { "System.Boolean", "System.Boolean", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int64", "System.Int64", "System.Int32", "System.Int32", "System.Int32" }; | |
| 203 | − string[] SubscriberStatFormats = { "{0}", "{0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}" }; | |
| 204 | + string[] SubscriberStatMethodSuffix = { "Connected", "Authenticated", "ProcessedMeasurements", "TotalBytesReceived", "AuthorizedCount", "UnauthorizedCount", "LifetimeMeasurements", "LifetimeBytesReceived", "MinimumMeasurementsPerSecond", "MaximumMeasurementsPerSecond", "AverageMeasurementsPerSecond", "LifetimeMinimumLatency", "LifetimeMaximumLatency", "LifetimeAverageLatency", "Lifetime Minimum Latency", "Lifetime Maximum Latency", "Lifetime Average Latency" }; | |
| 205 | + string[] SubscriberStatTypes = { "System.Boolean", "System.Boolean", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int64", "System.Int64", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int32" }; | |
| 206 | + string[] SubscriberStatFormats = { "{0}", "{0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0} ms", "{0:N0} ms", "{0:N0} ms" }; | |
| 204 | 207 | |
| 205 | 208 | string[] PublisherStatNames = { "Publisher Connected", "Connected Clients", "Processed Measurements", "Total Bytes Sent", "Lifetime Measurements", "Lifetime Bytes Sent", "Minimum Measurements Per Second", "Maximum Measurements Per Second", "Average Measurements Per Second" }; |
| 206 | 209 | |
| @@ -212,12 +215,15 @@ namespace GSF.TimeSeries · 5 unmodified lines | ||
| 212 | 215 | "Number of bytes sent by the publisher during the lifetime of the publisher.", |
| 213 | 216 | "The minimum number of measurements sent per second during the last reporting interval.", |
| 214 | 217 | "The maximum number of measurements sent per second during the last reporting interval.", |
| 215 | − "The average number of measurements sent per second during the last reporting interval." | |
| 218 | + "The average number of measurements sent per second during the last reporting interval.", | |
| 219 | + "Minimum latency from output stream, in milliseconds, during the lifetime of the publisher.", | |
| 220 | + "Maximum latency from output stream, in milliseconds, during the lifetime of the publisher.", | |
| 221 | + "Average latency from output stream, in milliseconds, during the lifetime of the publisher." | |
| 216 | 222 | }; |
| 217 | 223 | |
| 218 | − string[] PublisherStatMethodSuffix = { "Connected", "ConnectedClientCount", "ProcessedMeasurements", "TotalBytesSent", "LifetimeMeasurements", "LifetimeBytesSent", "MinimumMeasurementsPerSecond", "MaximumMeasurementsPerSecond", "AverageMeasurementsPerSecond" }; | |
| 219 | − string[] PublisherStatTypes = { "System.Boolean", "System.Int32", "System.Int32", "System.Int32", "System.Int64", "System.Int64", "System.Int32", "System.Int32", "System.Int32" }; | |
| 220 | − string[] PublisherStatFormats = { "{0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}" }; | |
| 224 | + string[] PublisherStatMethodSuffix = { "Connected", "ConnectedClientCount", "ProcessedMeasurements", "TotalBytesSent", "LifetimeMeasurements", "LifetimeBytesSent", "MinimumMeasurementsPerSecond", "MaximumMeasurementsPerSecond", "AverageMeasurementsPerSecond", "Lifetime Minimum Latency", "Lifetime Maximum Latency", "Lifetime Average Latency" }; | |
| 225 | + string[] PublisherStatTypes = { "System.Boolean", "System.Int32", "System.Int32", "System.Int32", "System.Int64", "System.Int64", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int32", "System.Int32" }; | |
| 226 | + string[] PublisherStatFormats = { "{0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0}", "{0:N0} ms", "{0:N0} ms", "{0:N0} ms" }; | |
| 221 | 227 | |
| 222 | 228 | // Parameterized query string for inserting statistic measurements |
| 223 | 229 | string statMeasurementInsertQuery = ParameterizedQueryString(connection.GetType(), StatMeasurementInsertFormat, "historianID", "pointTag", "signalTypeID", "signalReference", "description"); |
| @@ -573,6 +573,10 @@ namespace GSF.TimeSeries.Transport · 572 unmodified lines | ||
| 573 | 573 | private long m_measurementsPerSecondCount; |
| 574 | 574 | private long m_measurementsInSecond; |
| 575 | 575 | private long m_lastSecondsSinceEpoch; |
| 576 | + private long m_lifetimeTotalLatency; | |
| 577 | + private long m_lifetimeMinimumLatency; | |
| 578 | + private long m_lifetimeMaximumLatency; | |
| 579 | + private long m_lifetimeLatencyMeasurements; | |
| 576 | 580 | |
| 577 | 581 | private bool m_disposed; |
| 578 | 582 | |
| @@ -1098,6 +1102,42 @@ namespace GSF.TimeSeries.Transport · 519 unmodified lines | ||
| 1098 | 1102 | } |
| 1099 | 1103 | } |
| 1100 | 1104 | |
| 1105 | + /// <summary> | |
| 1106 | + /// Gets the minimum latency calculated over the full lifetime of the publisher. | |
| 1107 | + /// </summary> | |
| 1108 | + public int LifetimeMinimumLatency | |
| 1109 | + { | |
| 1110 | + get | |
| 1111 | + { | |
| 1112 | + return (int)Ticks.ToMilliseconds(m_lifetimeMinimumLatency); | |
| 1113 | + } | |
| 1114 | + } | |
| 1115 | + | |
| 1116 | + /// <summary> | |
| 1117 | + /// Gets the maximum latency calculated over the full lifetime of the publisher. | |
| 1118 | + /// </summary> | |
| 1119 | + public int LifetimeMaximumLatency | |
| 1120 | + { | |
| 1121 | + get | |
| 1122 | + { | |
| 1123 | + return (int)Ticks.ToMilliseconds(m_lifetimeMaximumLatency); | |
| 1124 | + } | |
| 1125 | + } | |
| 1126 | + | |
| 1127 | + /// <summary> | |
| 1128 | + /// Gets the average latency calculated over the full lifetime of the publisher. | |
| 1129 | + /// </summary> | |
| 1130 | + public int LifetimeAverageLatency | |
| 1131 | + { | |
| 1132 | + get | |
| 1133 | + { | |
| 1134 | + if (m_lifetimeLatencyMeasurements == 0) | |
| 1135 | + return -1; | |
| 1136 | + | |
| 1137 | + return (int)Ticks.ToMilliseconds(m_lifetimeTotalLatency / m_lifetimeLatencyMeasurements); | |
| 1138 | + } | |
| 1139 | + } | |
| 1140 | + | |
| 1101 | 1141 | #endregion |
| 1102 | 1142 | |
| 1103 | 1143 | #region [ Methods ] |
| @@ -1468,6 +1508,10 @@ namespace GSF.TimeSeries.Transport · 364 unmodified lines | ||
| 1468 | 1508 | { |
| 1469 | 1509 | m_lifetimeMeasurements = 0L; |
| 1470 | 1510 | m_totalBytesSent = 0L; |
| 1511 | + m_lifetimeTotalLatency = 0L; | |
| 1512 | + m_lifetimeMinimumLatency = 0L; | |
| 1513 | + m_lifetimeMaximumLatency = 0L; | |
| 1514 | + m_lifetimeLatencyMeasurements = 0L; | |
| 1471 | 1515 | } |
| 1472 | 1516 | |
| 1473 | 1517 | /// <summary> |
| @@ -1749,6 +1793,25 @@ namespace GSF.TimeSeries.Transport · 275 unmodified lines | ||
| 1749 | 1793 | return SendClientResponse(clientID, (byte)response, (byte)command, data); |
| 1750 | 1794 | } |
| 1751 | 1795 | |
| 1796 | + /// <summary> | |
| 1797 | + /// Updates latency statistics based on the collection of latencies passed into the method. | |
| 1798 | + /// </summary> | |
| 1799 | + /// <param name="latencies">The latencies of the measurements sent by the publisher.</param> | |
| 1800 | + internal protected virtual void UpdateLatencyStatistics(IEnumerable<long> latencies) | |
| 1801 | + { | |
| 1802 | + foreach (long latency in latencies) | |
| 1803 | + { | |
| 1804 | + if (m_lifetimeMinimumLatency > latency || m_lifetimeMinimumLatency == 0) | |
| 1805 | + m_lifetimeMinimumLatency = latency; | |
| 1806 | + | |
| 1807 | + if (m_lifetimeMaximumLatency < latency || m_lifetimeMaximumLatency == 0) | |
| 1808 | + m_lifetimeMaximumLatency = latency; | |
| 1809 | + | |
| 1810 | + m_lifetimeTotalLatency += latency; | |
| 1811 | + m_lifetimeLatencyMeasurements++; | |
| 1812 | + } | |
| 1813 | + } | |
| 1814 | + | |
| 1752 | 1815 | // Attempts to get the subscriber for the given client based on that client's X.509 certificate. |
| 1753 | 1816 | private void TryFindClientDetails(ClientConnection connection) |
| 1754 | 1817 | { |
| @@ -217,6 +217,10 @@ namespace GSF.TimeSeries.Transport · 216 unmodified lines | ||
| 217 | 217 | private long m_measurementsPerSecondCount; |
| 218 | 218 | private long m_measurementsInSecond; |
| 219 | 219 | private long m_lastSecondsSinceEpoch; |
| 220 | + private long m_lifetimeTotalLatency; | |
| 221 | + private long m_lifetimeMinimumLatency; | |
| 222 | + private long m_lifetimeMaximumLatency; | |
| 223 | + private long m_lifetimeLatencyMeasurements; | |
| 220 | 224 | |
| 221 | 225 | private bool m_disposed; |
| 222 | 226 | |
| @@ -590,7 +594,7 @@ namespace GSF.TimeSeries.Transport · 367 unmodified lines | ||
| 590 | 594 | } |
| 591 | 595 | |
| 592 | 596 | /// <summary> |
| 593 | − /// Gets the total number of measurements processed through this data publisher over the lifetime of the publisher. | |
| 597 | + /// Gets the total number of measurements processed through this data publisher over the lifetime of the subscriber. | |
| 594 | 598 | /// </summary> |
| 595 | 599 | public long LifetimeMeasurements |
| 596 | 600 | { |
| @@ -636,6 +640,42 @@ namespace GSF.TimeSeries.Transport · 39 unmodified lines | ||
| 636 | 640 | } |
| 637 | 641 | } |
| 638 | 642 | |
| 643 | + /// <summary> | |
| 644 | + /// Gets the minimum latency calculated over the full lifetime of the subscriber. | |
| 645 | + /// </summary> | |
| 646 | + public int LifetimeMinimumLatency | |
| 647 | + { | |
| 648 | + get | |
| 649 | + { | |
| 650 | + return (int)Ticks.ToMilliseconds(m_lifetimeMinimumLatency); | |
| 651 | + } | |
| 652 | + } | |
| 653 | + | |
| 654 | + /// <summary> | |
| 655 | + /// Gets the maximum latency calculated over the full lifetime of the subscriber. | |
| 656 | + /// </summary> | |
| 657 | + public int LifetimeMaximumLatency | |
| 658 | + { | |
| 659 | + get | |
| 660 | + { | |
| 661 | + return (int)Ticks.ToMilliseconds(m_lifetimeMaximumLatency); | |
| 662 | + } | |
| 663 | + } | |
| 664 | + | |
| 665 | + /// <summary> | |
| 666 | + /// Gets the average latency calculated over the full lifetime of the subscriber. | |
| 667 | + /// </summary> | |
| 668 | + public int LifetimeAverageLatency | |
| 669 | + { | |
| 670 | + get | |
| 671 | + { | |
| 672 | + if (m_lifetimeLatencyMeasurements == 0) | |
| 673 | + return -1; | |
| 674 | + | |
| 675 | + return (int)Ticks.ToMilliseconds(m_lifetimeTotalLatency / m_lifetimeLatencyMeasurements); | |
| 676 | + } | |
| 677 | + } | |
| 678 | + | |
| 639 | 679 | #endregion |
| 640 | 680 | |
| 641 | 681 | #region [ Methods ] |
| @@ -1524,6 +1564,10 @@ namespace GSF.TimeSeries.Transport · 882 unmodified lines | ||
| 1524 | 1564 | { |
| 1525 | 1565 | m_lifetimeMeasurements = 0L; |
| 1526 | 1566 | m_totalBytesReceived = 0L; |
| 1567 | + m_lifetimeTotalLatency = 0L; | |
| 1568 | + m_lifetimeMinimumLatency = 0L; | |
| 1569 | + m_lifetimeMaximumLatency = 0L; | |
| 1570 | + m_lifetimeLatencyMeasurements = 0L; | |
| 1527 | 1571 | } |
| 1528 | 1572 | |
| 1529 | 1573 | /// <summary> |
| @@ -1855,9 +1899,24 @@ namespace GSF.TimeSeries.Transport · 325 unmodified lines | ||
| 1855 | 1899 | else |
| 1856 | 1900 | OnNewMeasurements(measurements); |
| 1857 | 1901 | |
| 1902 | + // Gather statistics on received data | |
| 1903 | + long timeReceived = PrecisionTimer.UtcNow.Ticks; | |
| 1858 | 1904 | int measurementCount = measurements.Count(); |
| 1905 | + | |
| 1859 | 1906 | m_lifetimeMeasurements += measurementCount; |
| 1860 | 1907 | UpdateMeasurementsPerSecond(measurementCount); |
| 1908 | + | |
| 1909 | + foreach (long latency in measurements.Select(m => timeReceived - m.Timestamp)) | |
| 1910 | + { | |
| 1911 | + if (m_lifetimeMinimumLatency > latency || m_lifetimeMinimumLatency == 0) | |
| 1912 | + m_lifetimeMinimumLatency = latency; | |
| 1913 | + | |
| 1914 | + if (m_lifetimeMaximumLatency < latency || m_lifetimeMaximumLatency == 0) | |
| 1915 | + m_lifetimeMaximumLatency = latency; | |
| 1916 | + | |
| 1917 | + m_lifetimeTotalLatency += latency; | |
| 1918 | + m_lifetimeLatencyMeasurements++; | |
| 1919 | + } | |
| 1861 | 1920 | break; |
| 1862 | 1921 | case ServerResponse.BufferBlock: |
| 1863 | 1922 | // Buffer block received - wrap as a buffer block measurement and expose back to consumer |
| @@ -436,6 +436,8 @@ namespace GSF.TimeSeries.Transport · 435 unmodified lines | ||
| 436 | 436 | int binaryLength; |
| 437 | 437 | int packetSize = PacketHeaderSize; |
| 438 | 438 | |
| 439 | + long publishTime; | |
| 440 | + | |
| 439 | 441 | foreach (IMeasurement measurement in frame.Measurements.Values) |
| 440 | 442 | { |
| 441 | 443 | bufferBlockMeasurement = measurement as BufferBlockMeasurement; |
| @@ -476,6 +478,10 @@ namespace GSF.TimeSeries.Transport · 34 unmodified lines | ||
| 476 | 478 | // Process the remaining measurements. |
| 477 | 479 | if (packet.Count > 0) |
| 478 | 480 | ProcessBinaryMeasurements(packet, frameLevelTimestamp, useCompactMeasurementFormat, usePayloadCompression); |
| 481 | + | |
| 482 | + // Update latency statistics | |
| 483 | + publishTime = PrecisionTimer.UtcNow.Ticks; | |
| 484 | + m_parent.UpdateLatencyStatistics(frame.Measurements.Values.Select(m => (long)(publishTime - m.Timestamp))); | |
| 479 | 485 | } |
| 480 | 486 | |
| 481 | 487 | private void ProcessBinaryMeasurements(IEnumerable<IBinaryMeasurement> measurements, long frameLevelTimestamp, bool useCompactMeasurementFormat, bool usePayloadCompression) |
| @@ -517,7 +517,7 @@ namespace GSF.TimeSeries.Transport · 516 unmodified lines | ||
| 517 | 517 | base.QueueMeasurementsForProcessing(measurements); |
| 518 | 518 | publishInterval = (m_publishInterval > 0) ? m_publishInterval : LagTime; |
| 519 | 519 | |
| 520 | − if (DateTime.UtcNow.Ticks > m_lastPublishTime + Ticks.FromSeconds(publishInterval)) | |
| 520 | + if (PrecisionTimer.UtcNow.Ticks > m_lastPublishTime + Ticks.FromSeconds(publishInterval)) | |
| 521 | 521 | { |
| 522 | 522 | List<IMeasurement> currentMeasurements = new List<IMeasurement>(); |
| 523 | 523 | Measurement newMeasurement; |
| @@ -631,6 +631,9 @@ namespace GSF.TimeSeries.Transport · 107 unmodified lines | ||
| 631 | 631 | // Process the remaining measurements. |
| 632 | 632 | if (packet.Count > 0) |
| 633 | 633 | ProcessBinaryMeasurements(packet, useCompactMeasurementFormat, usePayloadCompression); |
| 634 | + | |
| 635 | + // Update latency statistics | |
| 636 | + m_parent.UpdateLatencyStatistics(measurements.Select(m => (long)(m_lastPublishTime - m.Timestamp))); | |
| 634 | 637 | } |
| 635 | 638 | |
| 636 | 639 | private void ProcessBinaryMeasurements(IEnumerable<IBinaryMeasurement> measurements, bool useCompactMeasurementFormat, bool usePayloadCompression) |
| @@ -673,7 +676,7 @@ namespace GSF.TimeSeries.Transport · 36 unmodified lines | ||
| 673 | 676 | m_parent.SendClientResponse(m_clientID, ServerResponse.DataPacket, ServerCommand.Subscribe, data.ToArray()); |
| 674 | 677 | |
| 675 | 678 | // Track last publication time |
| 676 | − m_lastPublishTime = DateTime.UtcNow.Ticks; | |
| 679 | + m_lastPublishTime = PrecisionTimer.UtcNow.Ticks; | |
| 677 | 680 | } |
| 678 | 681 | |
| 679 | 682 | // Rotates base time offsets |