Recording Lock Contention Information

You can record information about lock contentions; that is, the number of times lock requests on individual persistent objects have had to be rejected or queued because the object was already locked. Lock contention information is recorded:

The information recorded includes the number of contentions, the total time processes have spent waiting for a lock on each object, and the maximum time spent waiting for each lock.

By default, lock contentions are not recorded.

Lock contention information is returned in instances of the LockContentionInfo class.

Only one process at a time can be in control of lock contention recording; that is, if a process has called the beginLockContentionStats method to start lock contention recording, no other process can begin, end, or clear contention recording. However, other processes can retrieve the lock contention information.

The method in the following example shows the use of the System class lock contentions methods.

showLockContentions();
vars
    oa : ObjectArray;
    o : Object;
    lci : LockContentionInfo;
    ts : TimeStamp;
    avgWaitTime : Decimal[10,1];
begin
    create oa transient;
    system.beginLockContentionStats(10000);
    process.sleep(60000); //record 1 minute of lock activity
    system.getLockContentionStats(oa, 10000, 5, ts);
    write "FIRST MINUTE";
    foreach o in oa do
        lci := o.LockContentionInfo;
        write CrLf & "Object= " & lci.target.String;
        write "Contentions= " & lci.totalContentions.String;
        avgWaitTime := (lci.totalWaitTime / lci.totalContentions);
        write "Average wait time= " & avgWaitTime.String;
    endforeach;
    oa.purge;
    //Repeat
    system.clearLockContentionStats();
    process.sleep(60000); //record 1 minute of lock activity
    system.getLockContentionStats(oa, 10000, 5, ts);
    write CrLf & "SECOND MINUTE";
    foreach o in oa do
        lci := o.LockContentionInfo;
        write CrLf & "Object= " & lci.target.String;
        write "Contentions= " & lci.totalContentions.String;
        avgWaitTime := (lci.totalWaitTime / lci.totalContentions);
        write "Average wait time= " & avgWaitTime.String;
    endforeach;
    oa.purge;
    system.endLockContentionStats();
epilog
    delete oa;
end;

For details, see the following subsections.