Skip to main content

an simple load balancer for Python

Project description

pybalancer

pybalancer an simple load balancer for Python

Features

English

  • a simple load balancer
  • consistent Hash Load Balance using uhashring ketama hash function
  • periodly health checks, remove failed instance and add when it recovers
  • manually call remove_instance when it fails.

Installation

Using pip:

$ pip install pybalaner

Basic usage

pybalancer is very simple and efficient to use:

from pybalancer import LoadBalancer

# create a consistent hash ring of 3 nodes of weight 1
balancer = LoadBalancer(instances=['node1:port1', 'node2:port2', 'node3:port3'], interval=5)

# get the node name for the remote_addr key
target_instance = balancer.get_instance(remote_addr="host:port")

failed_times = 0
# call target_instance fails
if call(target_instance):
	failed_times += 1
	if failed_times > max_fails:
		balancer.remove_instance(target_instance)


alive_instances = balancer.get_alive_instances()
print(alive_instances)

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pybalancer-1.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pybalancer-1.0-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file pybalancer-1.0.tar.gz.

File metadata

  • Download URL: pybalancer-1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for pybalancer-1.0.tar.gz
Algorithm Hash digest
SHA256 213d5e45b64ffe1843f0efb45747a0bd4c147368ef87bb6590b4497a03488b96
MD5 7260e4d46f9558200892b25e0d2d8eed
BLAKE2b-256 ac087685c8f3a23608a4a16f994dc41ade59bdd38db0c8d4ef7bc451913fc952

See more details on using hashes here.

File details

Details for the file pybalancer-1.0-py3-none-any.whl.

File metadata

  • Download URL: pybalancer-1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.7.3

File hashes

Hashes for pybalancer-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85ec0799bc03e1a80f26e9be8c6f04c6ed792c091c456a4a3f4229023ce79d92
MD5 c9912da40c2590a89cc07b94e56a2f29
BLAKE2b-256 e7b305780b7005b11f9f512b6ce7d1eb33d9bd58b30c7bc280b737fa84770367

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page