Optimistic Concurrency

I’d seen this term crop up from time to time over the past few years but didn’t know what it meant. Thanks to Wikipedia this cipher has been decoded.

The optimism in optimistic concurrency refers to the attitude towards locks. An optimistic attitude assumes that locks aren’t necessary. This is considered optimistic because it assumes that transactions typically won’t step on each other. For some situations this is true; overlapping transactions are so rare that it’s more efficient to back-off and try again on the rare occasions they occur. Since locks are relatively expensive and rare, avoiding them lets the system handle more transactions overall (in this case).

On the other hand, if overlapping transactions are common then the cost of backing off and re-trying may exceed the cost of acquiring a lock for each transaction. Of course this partly depends on the granularity of the lock. The goal of finer grained locks is to reduce contention and, ultimately, to improve throughput.

The other aspect of optimistic concurrency is the way overlaps are handled. They’re detected, usually via some “modified-last” type token. If the underlying data has been changed since the writer last read it then the transaction fails and is reattempted.

No comments:

Post a Comment