Skip to main content
PI System
AF SDK
Performance

Bulk Writing to PI Points: Choosing the Most Efficient Method

Discover why using PIPoint.PIData.UpdateValues is faster and more efficient for bulk data inserts in OSIsoft PI System than multiple AFAttribute.SetValue calls.

Roshan Soni

3 min read

Bulk Writing to PI Points: Choosing the Most Efficient Method

When working with OSIsoft PI System, it's common to encounter scenarios where you need to write multiple values to a PI Point Data Reference (DR). Selecting the most efficient method for bulk data writes can save time and reduce system load—especially when working at scale.

The Two Common Methods

  1. PIPoint.PIData.UpdateValues

    • This method allows you to send a collection of values to the PI Data Archive in a single call. It's built for efficiency and optimized for handling bulk inserts. Fewer round-trips to the server mean faster writes and less network overhead.
  2. AFAttribute.SetValue (Multiple Calls)

    • Here, you use the AFSDK’s AFAttribute.SetValue method in a loop, writing one value at a time. Each call results in a separate roundtrip to the server, introducing latency and consuming more system resources when scaling up the number of values.

Which Method Should You Use?

For writing many values to a PI Point DR, PIPoint.PIData.UpdateValues is significantly more efficient than calling AFAttribute.SetValue multiple times. Here's why:

  • Reduced Server Roundtrips: Instead of opening a new connection and transaction for each value, you batch the values into a single transaction.
  • Optimized for Bulk Operations: The UpdateValues API is designed specifically for handling groups of values, minimizing overhead.

Practical Example

Suppose you have a list of new sensor readings to insert:

// Assume pipoint is an instance of PIPoint
List<AFValue> valuesToWrite = GetSensorReadings();
IList<AFValue> errors;

// Bulk write
pipoint.Data.UpdateValues(valuesToWrite, AFUpdateOption.Insert, AFBufferOption.BufferIfPossible, out errors);

Compare this to calling SetValue in a loop:

foreach (AFValue val in valuesToWrite)
{
    myAttribute.SetValue(val, AFUpdateOption.Insert);
}

The first approach is faster and puts less strain on your infrastructure.

Best Practices

  • Use UpdateValues whenever inserting or updating multiple values to a PI Point.
  • Reserve SetValue for occasional, single-value updates where simplicity or imperative logic is paramount.

Conclusion

If performance and efficiency matter (and they almost always do), opt for PIPoint.PIData.UpdateValues when inserting multiple values to a PI Point Data Reference. It’s a simple change that can lead to significant benefits for both developers and system administrators.

Tags

#Performance
#PIData
#UpdateValues
#AFAttribute.SetValue
#Bulk Insert
#PI Point Data Reference

About Roshan Soni

Expert in PI System implementation, industrial automation, and data management. Passionate about helping organizations maximize the value of their process data through innovative solutions and best practices.

Sign in to comment

Join the conversation by signing in to your account.

Comments (0)

No comments yet

Be the first to share your thoughts on this article.

Related Articles

Enhancing PI ProcessBook Trends with Banding and Zones: User Needs, Workarounds, and the Road Ahead

A look at the user demand for trend banding/zoning in OSIsoft PI ProcessBook, current VBA workarounds, UI challenges, and how future PI Vision releases aim to address these visualization needs.

Roshan Soni

Migrating PIAdvCalcFilVal Uptime Calculations from PI DataLink to PI OLEDB

Learn how to translate PI DataLink's PIAdvCalcFilVal advanced calculations—like counting uptime based on conditions—into efficient PI OLEDB SQL queries. Explore three practical approaches using PIAVG, PIINTERP, and PICOunt tables, and get tips for validation and accuracy.

Roshan Soni

Understanding PI Web API WebID Encoding: Can You Generate WebIDs Client-Side?

Curious about how PI Web API generates WebIDs and whether you can encode them client-side using GUIDs or paths? This article explores the encoding mechanisms, current documentation, and best practices for handling WebIDs in your applications.

Roshan Soni