5 Replies Latest reply on Sep 17, 2015 3:02 PM by SvenBatalla

    How to improve performance of PI tag lookup with element list?

    SvenBatalla

      I have a list of elements that I have retrieved from PIAF.  This list requires that all of its attributes be loaded.  The handy "LoadElements" method was used and the performance of retrieving the elements and their attributes is sufficient for my needs.

       

      Enter PI tags.

       

      In my application, I require additional information about the PI tags that have been associated to my elements.  Namely, the path, description, and engineering units.  To achieve this, I iterate over each element in my list and run this code (or close enough as makes no difference):

       

      PIPoint pipoint = myAttribute.PIPoint;
      string tagName = pipoint.GetPath();
      pipoint.LoadAttributes("descriptor", "engunits");
      

       

      This code seems pretty quick.  Run it on its own and the results come back sub-second.  However, in a case where I have 5,000 elements with up to 7 tag attributes each (so 35,000 tags), the performance drains.  Even with Parellel loops, I can only seem to bring the performance down to ~30s.  Keep in mind (if you try to run this) that I do have other properties of the tag that I retrieve (e.g. stateset), so it is not the only contributor to the 30s.  However, it is this segment of code is the slowest (likely because of the lookup), so this is where I would like to start.

       

      Any suggestions?

        • Re: How to improve performance of PI tag lookup with element list?
          SvenBatalla

          I should also mention that the goal is 20,000 element, so 140,000 tags.  Ideally the lookup has a negligible impact on performance.

          • Re: How to improve performance of PI tag lookup with element list?
            Rhys Kirk

            Have you tried using a PIPointList? Add each PIPoint to a PIPointList then LoadAttributes on the list. If you chunk in 1,000 PI Points at a time to start with you should see some improvement. I think that AF SDK will chunk at 1,000 PI Points at a time to fetch PI Point Attributes.

            1 of 1 people found this helpful
              • Re: How to improve performance of PI tag lookup with element list?
                SvenBatalla

                Well that was a golden nugget!  The preload activities that I have are slower now, but not as slow as NOT preloading.  I mentioned earlier that getting data was taking 30s.  It is now 6.9s.  I'd say that's pretty good (by comparison)!

                 

                Thanks!

                • Re: How to improve performance of PI tag lookup with element list?
                  SvenBatalla

                  I may have spoken too soon.  It looked like everything worked, but upon closer inspection it did not.  I must have done something wrong, so please help me out here.

                   

                  I already have an AFAttributeList for a different preload.  I use this to create a PIPointList, and then preload the attributes like so (simplified for brevity):

                   

                  var pointList = new PIPointList();
                  foreach(AFAttribute attribute in myAttributeList)
                  {
                    pointList.Add(attribute.PIPoint);
                  }
                  pointList.LoadAttributes("descriptor", "engunits");
                  

                   

                  Later in the code, when I am using the data, I attempt to get the point attribute in question like so:

                   

                  PIPoint pipoint = myAttribute.PIPoint;
                  myObject.Description = pipoint.GetAttribute("descriptor").ToString();
                  

                   

                  This throws an exception:

                   

                  The PI Point attribute 'descriptor' was not found. The attribute must be loaded before attempting to get its value.

                   

                  My guess (and what I'll work on while waiting for an answer) is that the original list of PIPoints that were preloaded is NOT the same PIPoints used later in the code.  Even though the technically are, they are not the same actual objects in memory.  So I'll need to pass the original list into this function I am using.  That is not ideal, but that's what I'm going to try.

                   

                  Unless I am missing something...?

                  1 of 1 people found this helpful