unimr.memcachedlock implements a distributed "soft" locking mechanism using
memcached. It provides factory functions and decorators for a primitive
locking, a reentrant locking and a special locking for zeo-clients.
The native locking methods of python's threading module supports thread safe
locking and therefore, provides only full locking support for single zope
installations. However, zeo-clients have no locking mechanism beetween each
other for concurrent write operations on identical objects (e.g. Catalog) and
are unnecessarily stressed to resolve ConflictErrors on heavy load. The
reason for this problem is the optimistic concurrency control of the ZODB
which primarly prepares the changes of an object (in many cases expensive
calculations) and thereafter checks the validity of the object for the write
process. The higher the number of writes on the same object the higher the
risk that a concurrent zeo-client has already invalidated the object while
another zeo-client has still this object in use. The client with the
invalidated object is constrained to roll back its changes and to recalculate
the changes based on the refreshed object. At worst, this state goes in
circles and results in a ConflictError. The optimistic concurrency control
therefore perfectly fits only concurrent write operations on distinct objects.
Memcache locking overcomes this problem because it extends the regular
concurrency mechanism by a shared locking beetween all involved zeo-clients
by serializing the concurrent write operations before a ConflictError is
provoked. This mechanism is also known as pessimistic concurrency control.
|