Optimistic concurrency control (OCC)

The basic idea behind OCC is to allow concurrent access to shared resources and only check for conflicts at the time of update. In other words, if multiple threads are accessing the same data, each thread can make changes to that data without checking with the others, assuming that there will be no conflicts.

When a thread tries to commit its changes, the system checks whether there have been any conflicts with changes made by other threads. If there are no conflicts, the changes are committed; otherwise, the thread must roll back its changes and retry.

OCC works by allowing all threads to make changes to the data without any locking, assuming that there will be no conflicts. However, if a conflict does occur, one of the threads must roll back its changes and retry, which can lead to reduced performance.

There are some pros and cons to using OCC in this context:

Pros:

  • OCC can provide better concurrency and throughput than traditional locking mechanisms.

  • It can help reduce the amount of contention for shared resources.

  • Developers don’t need to worry about conflicts with other threads.

Cons:

  • OCC is most effective when contention is low, and conflicts are relatively rare.

  • OCC can result in higher rollback rates if conflicts occur frequently.

  • OCC requires careful tuning to ensure that it provides the desired performance benefits.

PCC acquires locks dynamically at runtime, which can lead to indeterminate behavior. To mitigate this issue, several techniques require pre-declaration of resources to be accessed. However, these methods often require modifications to the original transaction format, which can impact compatibility.

Last updated