Connection Information

To perform the requested action, WordPress needs to access your web server. Please enter your FTP credentials to proceed. If you do not remember your credentials, you should contact your web host.

Connection Type

Technique #2: partitioning transactions via stored procedures – PB Docs 2022 – PowerBuilder Library

Technique #2: partitioning transactions via stored procedures – PB Docs 2022

Technique #2: partitioning transactions via stored
procedures

Imagine your PowerBuilder client contains the following
code:

This is not only problematic from a runtime performance
perspective since there would be numerous server calls over the WAN,
but also it could result in a “long transaction” that would tie up the
database resulting in poor database scalability.

The business logic and the data access logic (for saving data)
are intermingled. When the first “Update( )” is submitted to the
database, the related table in the database will be locked until the
entire transaction is ended by the “Commit( )”. The longer a
transaction is the longer other clients must wait, resulting in fewer
transactions per unit of time.

To improve the performance and scalability of the application,
the above code can be partitioned in two steps:

  1. Step 1 — Move the business logic (or as much as possible)
    outside of the transaction. In other words, the business logic
    should appear either before all Updates of the transaction or
    after Commit of the transaction. This way the transaction is not
    tied up while the business logic is executing.

  2. Step 2 — Partition the transaction by moving all the
    Updates into a stored procedure. The stored procedure will be
    executed on the database side and only return the final result.
    This would eliminate the multiple server calls from the multiple
    updates to just one server call over the WAN for saving all the
    data in one shot.

It is generally best to divide the original transaction into
three segments or procedures: “Retrieve Data”, “Calculate”
(time-consuming logic), and “Save Data”. The “Retrieve Data” procedure
retrieves all required data for the calculation. This data usually
would be cached in a DataWindow(s) or a DataStore(s). In the
“Calculate” procedure, the data cached in DataStore will be used to
perform the calculation instead of retrieving data directly from the
database. The calculation result would be cached to the DataStore and
then saved to the database by the “Save Data” procedure.

Example of the new PowerBuilder client code partitioned into
three segments and invoking a stored procedure to perform the
Updates:

Example of code for the stored procedure to update the
database:

In summary, with the above performance optimization technique,
the performance and scalability are improved since the transaction is
shorter. The server call-inducing Updates are all implemented on the
server-side rather than the client-side, improving the response time.
Secondly, moving the business logic out of the transaction further
shortens the transaction. If the business logic cannot be moved out of
the transaction, one may want to consider implementing the business
logic together with the transaction as a stored procedure. In summary,
shorter transactions are equal to better scalability and faster
performance.


Document get from Powerbuilder help
Thank you for watching.
Was this article helpful?
Subscribe
Notify of
guest
0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x