Aggregating Event Frame Data Part 1 of 9 - Introduction

Blog Post created by rdavin Employee on May 10, 2017

The Advanced AF SDK lab at UC SF 2017 was on this very topic.  The material in this 9-part series follows much of that lab.


Blog Series: Aggregating Event Frame Data

Part 1 - Introduction

Part 2 - Let's Start at the End

Part 3 - Setting up the App

Part 4 - Classical FindEventFrames

Part 5 - Lightweight FindObjectFields

Part 6 - Summary per Model

Part 7 - GroupedSummary per Manufacturer

Part 8 - Compound AFSummaryRequest

Part 9 - Conclusion



PI AF SDK 2.9 has many new exciting improvements and methods, particularly with the AFEventFrameSearch class.  This version introduces new methods that has the potential to:

  1. Simplify your code
  2. Reduce number of RPC calls
  3. Reduce overall execution time
  4. Reduce memory consumption
  5. Reduce CPU usage
  6. Reduce network traffic


Just as a teaser to what the blog series will illustrate, using the classical FindEventFrames(fullLoad: true) for my app takes over 140 seconds and over 100 MB of allocated memory.  Using some of these methods can reduce the run time to less than 10 seconds and under 10 MB memory!  That alone should encourage you to follow this series.  Granted there's always the disclaimer "Actual results may vary" but trust me on this.  When I put together what I felt was a real-world application, I was amazed at the improvement.  I am quite enthusiastic about sharing this information with the PISquare community.


Here's a list of some of the methods brand new to AFEventFrameSearch:

  1. BinnedSummary
  2. BinnedSummaryAsync
  3. FindObjectFields
  4. FrequencyDistribution
  5. FrequencyDistributionAsync
  6. GroupedSummary
  7. GroupedSummaryAsync
  8. Histogram
  9. HistogramAsync
  10. Summary
  11. SummaryAsync


When you get your hands on AF 2.9, you definitely want to check these new methods out. For this particular series, I will be showcasing these methods:

  1. FindObjectFields (Part 5)
  2. Summary (Part 6)
  3. GroupedSummary (Part 7)
  4. AFSummaryRequest (Part 8)


I grew to appreciate each method for what it does.  In particular, I really liked FindObjectFields.  While it's used here within my examples for aggregation, it's not actually an aggregation method; it's quite versatile and its primary purpose is to be used for detail data.


Also NEW: Implements IDisposable

Effective with AF SDK 2.9, the abstract AFSearch class now implements IDisposable. This means that any class derived from AFSearch, such as AFEventFrameSearch, also implements IDisposable. This also means you may now wrap the call in a using block as in:


using (var search = new AFEventFrameSearch(arguments))
     //do something with the search


When the using block terminates the cache will immediately be released on the server. Code prior to AF SDK 2.9 that doesn’t specify using will still work without modification, though you are encouraged to make these changes. If you don’t make this change, the cache will eventually be released when its Timeout expires.


Besides a using block, you may alternatively issue an explicit Close() on your search object. This too will immediately release the server cache. Though using or Close() is not required, it is considered a best practice to do so.


Caveat: Use CaptureValues

It's a welcome sight to see both lightweight and aggregation search methods available for event frames.  You will see in Part 2 an example of performance improvements.  However, you will only realize a such boost in performance if you have issued CaptureValues for your event frames.  This allows server-side filtering of attribute values or aggregation of attribute values.


If you have not captured values, your code will still work just fine albeit more slowly as filtering and evaluation of attribute values must be performed client-side.


Why You Should Keep Reading the Series

So keep an eye out in the forums for updates to this blog series.  Hope I've whet your appetite enough to want to read through all 9 parts!  Warning: they will get longer and contain code.  Don't fear that you will have to do a lot of reading only to be disappointed in the results.  In Part 2, I will go ahead and show you the final performance results!  That's right.  We start with the end.  I'm confident that by showing you the savings and benefits early that you will be glad to be vested to read the entire series.