OPTIMIZING YOUR PI SDK APPLICATIONS BUILDERS' CAFÉ WEBINAR SERIES
PRESENTERS Jay Lakumb Product Manager Charlie Henze Software Development Lead Cristóbal Escamilla vcampus Team Member 2
VCAMPUS-EXCLUSIVE WEBINARS The Builders' Café Webinar Series Submit your ideas here: 3
AGENDA Optimization your PI SDK Applications Leveraging PI Server Mechanisms Threads Asynchronous Functions ListData Functions EventPipes Conclusion PI SDK Roadmap (Hint: SDK Buffering!) 4
THE OSISOFT SDKS PI SDK PI Points (Attributes & Data) PI Server Message Log Various PI Databases (Users & Groups, etc.) AF SDK AF Databases, Elements, Attributes AF Analysis Rules (ARs) and Data References (DRs) AF Connectivity Models and Cases Notifications SDK (a.k.a. AN SDK) Notification Configuration (including Delivery Channel) Manipulation of notification instances Event Frames SDK (a.k.a. EF SDK) 5
PROGRAMMING WITH PI SDK Assemblies (installed in GAC Global Assembly Cache) OSIsoft.PISDK OSIsoft.PISDKCommon OSIsoft.PISDKDlg OSIsoft.PITimeServer 6
PROGRAMMING WITH PI SDK Assemblies (installed in GAC Global Assembly Cache) OSIsoft.PISDK OSIsoft.PISDKCommon OSIsoft.PISDKDlg OSIsoft.PITimeServer Help File: \PIPC\Help\PISDK.CHM Manage/Find PI Points Read/Write Data Perform Calculations Invoke Common Dialog Windows... 6
WAYS TO OPTIMIZE PI SDK APPLICATIONS Connection Pooling One ServerManager hierarchy per thread Single sign on inherits caller s Windows identity. Supports PITrust and PIIdentity (Interactive Login not supported) One multiplexed connection at the network layer. The PI SDK object also inherits user s identity but does not optimize sharing of equivalent authorization. PISDK Asynchronous Calls Non-blocking calls Easy to implement ListData Functions Grouping of tags May reduce the number of calls Event Pipes Sign up for updates instead of polling 7
OPTIMIZING YOUR PI SDK APPLICATIONS
Single-Thread Linear execution Susceptible to blocking calls Low code complexity Easy to debug SINGLE VS.MULTI Multi-Thread Parallel/concurrent execution Susceptible to thread-locks/race/starve conditions Increases application complexity 9
IMPERSONATION LogonUser Attempts to log a user on to the local computer If successful you receive a handle to a token that represents the logged-on user Use this token handle to impersonate the specified user via the WindowsIdentity.Impersonate. LogonUser function is part of the Advapi32.dll library and needs to be included explicitly in your application. C# Example: 10
CLOSEHANDLE FUNCTION CloseHandle Closes an open object handle (in this case an Access Token) Invalidates the specified object handle, decrements the object's handle count, and performs object retention checks After the last handle to an object is closed, the object is removed from the system. CloseHandle function is part of the Kernel32.dll library and needs to be included explicitly in your application. C# Example: 11
DEMONSTRATION 12
LEVERAGING PI SERVER MECHANISMS
CONCURRENCY FROM MULTIPLE CLIENTS PI Server is a multi-process, multi-threaded system Each process (subsystem) has a different number of RPC threads by default View/Change these in SMT > Tuning Parameters This is leveraged in client applications 14
SYNCHRONOUS & ASYNCHRONOUS Synchronous Function return when it finishes the process Execution of the program will wait for the value to be available (user interface won t be responsive) Asynchronous Function returns immediately Execution of the program continues Program needs to monitor the status of the pending function calls (the user interface is responsive) Output arguments must be cleaned up by the developer. 15
ASYNCHRONOUS There are three methods you could use to check the status of a PIAsynchStatus object: Loop for status to change. Register a Windows Event Callback. Wait for a call completion handle change. 16
DEMONSTRATION 17
ASYNCHRONOUS FUNCTIONS Find the latest list in \PIPC\HELP\pisdk.chm (under PIAsynchStatus Object ) 18
LISTDATA FUNCTIONS Some functions take a list of tags and return one value per tag, those can help you optimize queries to make less calls and improve performance: ListData.Snapshot ListData.ArcValue Both return a PISDK.PointValues collection 19
PLOTVALUES Given a start and end time and number of desired plotting intervals (typically pixels) return values suitable for plotting in a PIValues collection Supports Asynchronous calling Only brings the minimum number of values required to represent the trend at the passed resolution. 20
USING EVENTPIPES Generic channel/listener for various PI events Subscribes for updates to the PI Update Manager Supported by objects like: PIData, ListData PIPoints See the "Deeper in PI SDK«webinar Recorded September 30th, 2009 http://vcampus.osisoft.com/media/p/2109.aspx 21
CONCLUSION
PI SDK ROADMAP SDK 2010 (1.4) Major Features: Buffering (aka client-side buffering) Fanning to High Availability PI Collective Use Cases: PI Clients and PI Data Access products that write to PI Manual entry applications Custom interfaces Schedule: Targeted for H2 2010 See Engineering Plan on Tech Support site Prerequisites: PI Server 3.4.375 or higher (may require upgrade) 23
WHAT SHOULD I USE? Improve UI responsiveness using an asynchronous design and/or EventPipe Performance and scalability with PIAsynchStatus Improve scalability with Connection pooling Reduce data transfers by delegating standard calculations to the PI Server Minimize server calls using EventPipe and ListData.ArcValue Visual Studio 2008 Team Use Application profiler to find bottle necks http://msdn.microsoft.com/en-us/magazine/cc337887.aspx 24
WHAT SHOULD I USE? Enabling PI SDK Tracing you can: Find out what PI SDK calls a running application is making Know how long those calls are taking to execute Impact performance negatively, so please remember to revert the values when you are no longer needing it. 25
Q & A Users on Conference Call: Please do not put the call on hold as we would probably hear music! Users on Internet Audio: Type your questions in LiveMeeting 26
VCAMPUS-EXCLUSIVE WEBINARS The "Builders' Café" Webinar Series Submit your ideas here: 27
NEXT VCAMPUS WEBINARS 28
HOW TO CONTACT US vcampus Discussion Forums vcampus@osisoft.com http://twitter.com/osisoftvcampus http://vcampus.osisoft.com > Contact Us 29