Mongoengine pessimistic lock utility
Project description
# PessimisticLockMongo
Pessimistic lock implementation for mongoengine, using a very simple logic
`Inspired by mongolock and pessimistic locks concept.`
Read more about the implementation [here](https://medium.com/@abhishek.tamrakar/implementing-pessimistic-locks-in-mongodb-8f3fbe2ddfa9)
## Setting up the context
The real intention behind writing this utility isn't just Database locking. Locking is already handled in mongoDB, sufficient or not, but it locks the Database with exclusive write locks, thats when the problem begins.
With multiple collections and frequent requests coming in, it is on DB performance when a transaction is waitingon the lock on Database, when there is only one collection involved in the operation at the moment.
Hence, this utility, targets collection based locking mechanism, fully controoled in application for the DB.
## Usage
```
from mongoEngineLock import mongoEngineLock, MongoLockTimeout
lock = mongoEngineLock('<db..name>', poll=1, timeout=40, retries=15)
with lock(entity):
try:
<..do something here..>
except Exception as e:
raise e
# or use with conditional statements
if lock(entity):
try:
<..do something here..>
except Exception as e:
raise e
```
##### mongoEngineLock Parameters:
**client**: connection information for MongoEngine.
**poll**: interval to introduce a delay while retrying.
**timeout**: interval (seconds) to introduce timeout.
**retries**: number of retries before timeout.
##### Instance of the class takes exactly 1 parameter:
**entity**: owner of the lock or collection name(in case there are more than one collections to be managed in a database).
## Misc
* Try to use a smaller polling interval or interval based on time taken to execute the query, in case of bigger DB size.
* Worth to mention, timeout or retries should not supersede each other.
* Use proper NTP servers to keep your machines in time sync.
Pessimistic lock implementation for mongoengine, using a very simple logic
`Inspired by mongolock and pessimistic locks concept.`
Read more about the implementation [here](https://medium.com/@abhishek.tamrakar/implementing-pessimistic-locks-in-mongodb-8f3fbe2ddfa9)
## Setting up the context
The real intention behind writing this utility isn't just Database locking. Locking is already handled in mongoDB, sufficient or not, but it locks the Database with exclusive write locks, thats when the problem begins.
With multiple collections and frequent requests coming in, it is on DB performance when a transaction is waitingon the lock on Database, when there is only one collection involved in the operation at the moment.
Hence, this utility, targets collection based locking mechanism, fully controoled in application for the DB.
## Usage
```
from mongoEngineLock import mongoEngineLock, MongoLockTimeout
lock = mongoEngineLock('<db..name>', poll=1, timeout=40, retries=15)
with lock(entity):
try:
<..do something here..>
except Exception as e:
raise e
# or use with conditional statements
if lock(entity):
try:
<..do something here..>
except Exception as e:
raise e
```
##### mongoEngineLock Parameters:
**client**: connection information for MongoEngine.
**poll**: interval to introduce a delay while retrying.
**timeout**: interval (seconds) to introduce timeout.
**retries**: number of retries before timeout.
##### Instance of the class takes exactly 1 parameter:
**entity**: owner of the lock or collection name(in case there are more than one collections to be managed in a database).
## Misc
* Try to use a smaller polling interval or interval based on time taken to execute the query, in case of bigger DB size.
* Worth to mention, timeout or retries should not supersede each other.
* Use proper NTP servers to keep your machines in time sync.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
mongoEngineLock-0.1.0.tar.gz
(3.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mongoEngineLock-0.1.0.tar.gz.
File metadata
- Download URL: mongoEngineLock-0.1.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7be6c0792516115c8378ba93778d821cbd54a1468ad035448fff8f679a1cedb8
|
|
| MD5 |
572a4d77b8b121fc3d68751c1cfb0c12
|
|
| BLAKE2b-256 |
b9f6336a2232e4ce947400556e7a6e3b6ce2b0c3496dde7216c694c13d0d0c78
|
File details
Details for the file mongoEngineLock-0.1.0-py2-none-any.whl.
File metadata
- Download URL: mongoEngineLock-0.1.0-py2-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.0 CPython/2.7.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2dbfd690188b62b4a476bb95aa90a6154e9be6a6750343f505701b32343424c2
|
|
| MD5 |
46d1d648c7c0c3ec0308957ae4d5b074
|
|
| BLAKE2b-256 |
6f6663d9c9b2032375568098598e96d5b9960e927f6190051aca9ae1c08b6631
|