Event Monitoring SIMATIC S71500 - Memory usage issues

Questions regarding the use of the .NET SDK 2.0 for Server or Client development or integration into customer products ...

Moderator: uasdknet

Post Reply
asdin
Jr. Member
Jr. Member
Posts: 3
Joined: 14 Nov 2019, 10:05

Event Monitoring SIMATIC S71500 - Memory usage issues

Post by asdin »

Hello

I have implemented subscription, based on Subscription Data Change() (Monitoring Events). The Programm monitors 80 PLC-Variables.
The issue is, the Memory usage get higher(around 4gb and continuer to be higher..etc) with time when data changes event rises. i don't know what causes of high memory usage,
i tried to reduce app footprint but it didn't work. Possible some data buffering in background...??

This is the code:

Start Monitoring

Code: Select all

// Step 1 --------------------------------------------------
                // Create and initialize subscription
                m_subscription = new Subscription(m_opcStation.GetSession());
                m_subscription.PublishingEnabled = true;
                m_subscription.PublishingInterval = 500;
                m_subscription.MaxKeepAliveTime = 50000;
                m_subscription.Lifetime = m_opcStation.GetSession().SecureChannelLifetime;
                // Data change events will be received through Subscription_DataChanged
                m_subscription.DataChanged += new DataChangedEventHandler(Subscription_DataChanged);
                // Create subscription on server
                m_subscription.Create();

                // Step 2 --------------------------------------------------
                // Prepare variables to monitor as data monitored item
                m_monitoredItems = new List<MonitoredItem>();
                // Default is monitoring Value attributes
                foreach (StationSensorXmlData temp in m_stationDataModel.LineNode)
                {
                    //string sNode = CreateNewNodeIds(m_StationDataModel.dataBlockName, temp.PLCVariable);
                    NodeId NodeId = new NodeId(temp.PLCVariable, m_opcStation.GetNamespaceIndex());
                    DataMonitoredItem dataMonitoredItem = new DataMonitoredItem(NodeId, Attributes.Value);
                    dataMonitoredItem.DiscardOldest = true;
                    dataMonitoredItem.SamplingInterval = -1;
                    dataMonitoredItem.QueueSize = 1;
                    m_monitoredItems.Add(dataMonitoredItem);
                }
                // Step 3 --------------------------------------------------
                // Create monitored items on server
                results = m_subscription.CreateMonitoredItems(m_monitoredItems);
Event: Subscription Data Change

Code: Select all

        private void Subscription_DataChanged(Subscription subscription, DataChangedEventArgs e)
        {
            var sensorName = string.Empty;
            var ErrorVar = string.Empty;
            var StatusCode_errorDebug = string.Empty;
            var stationDataSheetTemp = new Tuple<string, string, int, int, string>(string.Empty, string.Empty, 0,0, string.Empty);

            try
            {
                // Check that the subscription has not changed.
                if (!Object.ReferenceEquals(m_subscription, subscription))
                {
                     Console.WriteLine("subscription has changed");
                    return;
                }

                //Start execution time
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                //m_db.SQLConnectionOpen();
                foreach (DataChange change in e.DataChanges)
                {
                    sensorName = change.MonitoredItem.NodeId.Identifier as string;
                    StatusCode_errorDebug = change.Value.StatusCode.Message;
                    /* get station data */
                    bool isPlcVarExist = m_stationDataSheetBuffer.TryGetValue(sensorName, out stationDataSheetTemp);

                    if (StatusCode.IsGood(change.Value.StatusCode))
                    {
                        if (m_stationTyp == 1)     /* Master station */
                        {
                            ErrorVar = MasterToDb(change, stationDataSheetTemp, sensorName);
                        }
                        else if (m_stationTyp == 3) /* Station */
                        {
                            /* connect to Master opc */
                            m_opcMaster.ConnectToOPC(m_opcMasterIp);
                            if (isPlcVarExist)
                            {
                                ErrorVar = StationToDb(change, stationDataSheetTemp, sensorName);
                            }
                            else
                            {
                                ErrorVar = "Sensor ID not fount!";
                            }
                            /* connect to Master opc */
                            m_opcMaster.Disconnect();
                        }
                        else if(m_stationTyp == 2)  /* Live bit Master */
                        {
                            ErrorVar = LiveBitMaster(change);
                        }
                        else
                        {
                            ErrorVar = "Station not found!";
                        }
                    }
#if DEBUG
                    Console.WriteLine($"{ErrorVar};{sensorName};{change.Value.WrappedValue}");
#endif
                }
                stopwatch.Stop();  //Stop execution time
            }
            catch (Exception ex)
            {
                m_opcMaster.Disconnect();
#if DEBUG
                Console.WriteLine(ex.Message);
#endif
            }

        }
Thank you in advance

Best regards,

User avatar
Support Team
Hero Member
Hero Member
Posts: 3064
Joined: 18 Mar 2011, 15:09

Re: Event Monitoring SIMATIC S71500 - Memory usage issues

Post by Support Team »

Hello,

please use the "FullClient" as shipped with the .NET based OPC UA SDK and do the same test (subscribe to 80 nodes on the S7-1500). Check if the memory increases as well, if memory is stable the SDK code is probably correct, and the mem leak is located in your application.

Please refer to the sample code provided with the SDK to prove your application.
Best regards
Unified Automation Support Team

Post Reply