Package enabling to load balance requests to databases in django projects
Project description
DjangoLoadBalancer
Package enabling to load balance requests to databases in django projects. It creates a separate process, where all requests to databases from user's app instances are sent. The process creates one thread for every database that was specified in settings.py. Each thread is responsible for managing one database.
Installation
pip install djangoloadbalancer
How to use
- Rather than extending models.Model, your models must extend LoadBalancerModel, example:
import django_load_balancer.load_balancer_model
from django.db import models
class Destination(django_load_balancer.load_balancer_model.LoadBalancerModel):
name = models.CharField(max_length=100)
desc = models.CharField(max_length=100)
- Specify load balancer's settings in project's settings.py file, example:
LOAD_BALANCER={
'CUD_ALGORITHM': 'MULTITHREADING',
'R_ALGORITHM': {
'NAME':'ROUND_ROBIN',
},
'DATABASES': ['default','DB1','DB2','DB3','DB4'],
'WAIT_TIME': 2,
'ADDRESS': {
'HOST' : 'localhost',
'PORT' : 6000,
'AUTHKEY' : 'pass'
}
}
- R_ALGORITHM - algorithm that will determine to which database will be the next READ query sent
- ROUND_ROBIN - next database for READ query is just the next in list
- INTERVAL_TIME - regularly sends queries to databases to determine their response time. This response time is later used to choose database for READ query - the database with the smallest response time will be chosen. Queries to determine response time are send every INTERVAL seconds.
- DATABASES - names of databases from settings.py's DATABASES that will be used for loadbalancing
- WAIT_TIME - amount of time that load balancer will wait to check if the database, that went down, is up
- ADDRESS - address of load balancer process
- Add 'django_load_balancer' to INSTALLED_APPS in project's settings before 'django.contrib.staticfiles', example:
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django_load_balancer',
'django.contrib.staticfiles',
'LoadBalancer',
]
- Run djangoloadbalancer.py:
user1@user1:~/djangoProject1$ python3 venv/bin/djangoloadbalancer.py
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
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 djangoloadbalancer-0.0.56.tar.gz.
File metadata
- Download URL: djangoloadbalancer-0.0.56.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc8ea9a3ef9c622c1d2a004b3d3ad9caf84a6ae1680358a5be39b31f9f75d3a4
|
|
| MD5 |
641df99da2947f4e4b6b0d8ba31c285b
|
|
| BLAKE2b-256 |
e3c40d386817d6da9f5e3d3a6b39a0fae30ff0b041d2d4954beff8e82c1fbf44
|
File details
Details for the file djangoloadbalancer-0.0.56-py3-none-any.whl.
File metadata
- Download URL: djangoloadbalancer-0.0.56-py3-none-any.whl
- Upload date:
- Size: 17.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72290ed5ff52a8ad46141cdabdfd7acb4441ccf695d70f9ec54bcc373c029fa5
|
|
| MD5 |
5c2c00ee6619a22dd01942da83125ee1
|
|
| BLAKE2b-256 |
57a38f7dfde6421210d9921044515a39015f93ecf7987ff0c8e9f1a16c8d5772
|