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
djangoloadbalancer-0.0.56.tar.gz
(11.7 kB
view hashes)
Built Distribution
Close
Hashes for djangoloadbalancer-0.0.56.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fc8ea9a3ef9c622c1d2a004b3d3ad9caf84a6ae1680358a5be39b31f9f75d3a4 |
|
MD5 | 641df99da2947f4e4b6b0d8ba31c285b |
|
BLAKE2b-256 | e3c40d386817d6da9f5e3d3a6b39a0fae30ff0b041d2d4954beff8e82c1fbf44 |
Close
Hashes for djangoloadbalancer-0.0.56-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72290ed5ff52a8ad46141cdabdfd7acb4441ccf695d70f9ec54bcc373c029fa5 |
|
MD5 | 5c2c00ee6619a22dd01942da83125ee1 |
|
BLAKE2b-256 | 57a38f7dfde6421210d9921044515a39015f93ecf7987ff0c8e9f1a16c8d5772 |