AnsweredAssumed Answered

Fastest Way to Retrieve Events from AF

Question asked by fmocke on Mar 14, 2019
Latest reply on Mar 14, 2019 by fmocke

We are currently retrieving event frames through a custom application making use of PI AF SDK.  It is a bit slow for our needs and thus looking for alternatives. It takes about one minute to retrieve 3000 events.


I've read  about RTQP but have not tried it yet.  How does the performance of SDK, traditional ODBC and RTQP compare when retrieving event frames with custom attributes?



It seems that the SDK is supposed to give similar performance to RTQP.  Thus I need to figure out why my code takes long to execute.


See below for test code that I'm using.  The code returns about 6000 events.  With the code as below it takes between 50 and 70 seconds to run.  Commenting out the attribute lookups, the code takes less than two seconds to run.  Thus the attribute lookups are the problem. I have changed the 'isIndex' of attribute templates to true, as well as used the CaptureValues() function on the event frame.  It did not increase the perormance.


What is also interesting is only calling ef.Attributes gives the same performance as calling all the individual attributes.  Thus I assume ef.Attributes loads all the attributes in memory then is easily references by the individual attributes.  Thus the problems lies there.


Something else that might be relevant: the Reason attribute references an enumeration set with 1100 items.  Might cause issues if not indexed properly ?


AF SDK Version:

PI AF Server Version:


            Stopwatch sw = new Stopwatch();

            var eventTemplate = afDatabase.ElementTemplates.Where(x => x.Name == "Chimiwungo Down").First();

            string query = string.Format("Template:\"{0}\"", eventTemplate.GetPath(afDatabase));
            var s = new AFEventFrameSearch(afDatabase, "*", AFSearchMode.Overlapped, new AFTime("2018-01-01"), new AFTime("2019-03-13"), query);
            var eventFrames = s.FindEventFrames().OrderBy(x => x.StartTime).ToList();

            List<GridEvent> geList= new List<GridEvent>();
            foreach (var ef in eventFrames)
                GridEvent ge = new GridEvent();
                ge.Name = ef.Name;
                ge.StartDate = ef.StartTime;
                ge.EndDate = ef.EndTime;
                ge.Duration = ef.Duration.ToTimeSpan().TotalHours;
                ge.Reason = ef.Attributes["Reason"].GetValue().ToString();
                ge.ChangeHistory = (string[])ef.Attributes["Change History"].GetValue().Value;
                ge.Comment = ef.Attributes["Comment"].GetValue().ToString();
                ge.Locked = (bool)ef.Attributes["Locked"].GetValue().Value;



            Console.WriteLine(sw.ElapsedMilliseconds / 1000.0);