Optimistic Concurrency Control

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 throughput than traditional synchronization-based mechanisms.

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

  • Developers typically don’t need to manually manage resource to avoid potential conflicts.

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.

Conclusion

Optimistic Concurrency Control (OCC) allows multiple threads to concurrently access and modify shared resources, only checking for conflicts at the time of update. Threads make changes without coordinating with others, assuming no conflicts will occur.

During commit, the system checks for conflicts; if none are found, changes are committed, otherwise, the thread rolls back and retries. This approach reduces contention for shared resources and simplifies resource management for developers. However, OCC is most effective when conflicts are rare and requires careful tuning to ensure performance benefits, as frequent conflicts can lead to higher rollback rates and reduced performance.


Project Using OCC

APTOS

APTOS uses an optimistic concurrency control technology called “block-STM” to support multi-threaded block validation and to avoid state conflicts. It is related to “software transactional memory” (STM), which allows multiple threads to execute a transaction in parallel, assuming that there are no conflicts between the transactions. If a conflict is detected, the transaction is rolled back and retried with the updated state.

Monad

Monad's execution model is classified as optimistic concurrency control (OCC).

Monad executes transactions in parallel using optimistic execution, where transactions start before earlier ones complete, potentially causing incorrect execution if data dependencies are not met. The system tracks inputs and re-executes transactions if conflicts are detected.

Optimistic execution allows for efficiency by not repeating certain steps unnecessarily. Scheduling attempts to predict dependencies to avoid re-executions, and further optimization opportunities are being explored.

For more details, visit the Monad documentation on parallel execution.

Last updated