5 Replies Latest reply on Dec 22, 2017 8:49 AM by BjørnOlav

    PI API performance vs PI SDK

    BjørnOlav

      We're currently doing a pilot project to decide whether to base our data polling on using the API or the .NET SDK.

      Our initial results indicate a huge performance gain using the SDK with a 1:10 gain.

       

      When polling from the API we use

      //url: https://pi_webapi/piwebapi/streams/P08H9Krknbh0ymdssBHK29FgUA0AAAUElfREFcS1ZJTC5BR0cxLkcxLk1WLk1fSQ/recorded?startTime=2… 
      //reducing bandwidth by selectedFields=Items.Timestamp;Items.Value;Items.Good
      //maxCount=1000, we concatenate results over 1000
      //results are json deserialized
      var response = await _client.GetAsync(url);
      if (response.IsSuccessStatusCode)
      {
         var result = await response.Content.ReadAsAsync<T>();
         return result;
      }
      
      

       

      When polling from the SDK we use

      PIPoint myPoint = PIPoint.FindPIPoint(staticPIServer, tag);
      if (myPoint != null)
      {
         var data = myPoint.RecordedValues(new AFTimeRange(start, end), AFBoundaryType.Inside, null, false);
      }
      
      

       

      Is our approach to using the API wrong?

       

      Best Regards,

      Bjørn Olav

        • Re: PI API performance vs PI SDK
          John Messinger

          Your approach to using the PI Web API is not necessarily wrong. As a general rule, you will always get better performance when using the AFSDK natively, as opposed to using other technologies such as the PI Web API or the OLEDB providers. This is because technologies such as PI Web API have to translate the calls you make to it into SDK calls when it accesses the data archive server or the asset server, and then wraps the returned data into a JSON bundle to send back to the caller. You then add a little more overhead by having to deserialize that into a format you can use.

           

          When deciding which development technology to use for your application, you need to consider multiple factors, performance being just one of them. Is the performance difference crucial to the requirements that your custom application is being built to address? If the answer is yes, then don't use the PI Web API. Will there be restrictions or limitations on your ability to deploy the PI AF Client package along with your application on the target machine(s)? If yes, the the PI Web API will allow you to run your custom application as a kind of thin client with no additional software needing to be installed. Will your application be required to run on non-Windows platforms? What additional requirements will you need to meet with your application? Remember also that the PI Web API is not a fully featured replacement for the AFSDK - there are some things you just can't do using the PI Web API at present (and that may not change in the future). Will some of your application features require functionality only available natively in the AFSDK?

           

          I'm more of an SDK developer than a web API developer - most of the time using the SDK is a more appropriate choice in the applications I write. Plus I am more familiar with the SDK, so I stick with the familiar. While I've only recently begun exploring the PI Web API, so far the only reason I've had to use it has been to cover a cross-platform requirement for a specific custom application. And the performance difference was quite noticeable, but is a trade-off that had to be made for cross-platform compatibility.

           

          So if there are no barriers to writing a native SDK application, then I would recommend that route as you will get a better performing application in terms of data access (you still have to use the appropriate bulk methods to realise many of these gains).

          8 of 8 people found this helpful