Skip to content

bersen66/lb2

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ff08648 · May 15, 2024

History

7 Commits
Apr 30, 2024
May 6, 2024
May 6, 2024
May 15, 2024
May 15, 2024
May 15, 2024
May 15, 2024
May 15, 2024
May 6, 2024
Apr 30, 2024
May 6, 2024
May 15, 2024

Repository files navigation

  1. Introduction
    1. Supported algorithms
  2. Installation
  3. YAML-config example
  4. Run app

lb2

lb2 is an asynchronous multithreaded load balancer written in C++. It is designed to be highly configurable and supports six different algorithms of load balancing. This project aims to provide a flexible and efficient solution for distributing network traffic across multiple servers.

Supported algorithms

  • round-robin
  • weighted round-robin
  • ip-hash
  • consistent hash
  • least-connections
  • least-response-time

Installation:

First of all make sure, that pip is installed. It will be used for installing CMake and Conan if needed.

To automatically install all dependencies and build application type:

./lbbuild.sh build Release

This script builds app and copies configs folder to build/lb2/configs

To build and run unit tests type:

./lbbuild.sh test Release

Config example:

# Configure logging
logging:
  # Optional value.
  file:
    name: logs/logs.txt # Logfile name
    level: debug  # Possible values: trace, debug, info, warning, error
  console:
    level: debug

thread_pool:
  threads_number: auto # or number

acceptor:
  port: 9090  # Port number
  ip_version: 4 # or 6

# Configure load balancing algorithm
load_balancing:
  # Possible values:
  #  - round_robin
  #  - weighted_round_robin
  #  - consistent_hash
  #  - ip_hash
  #  - least_connections,
  #  - least_response_time


  # Example config of least connections
  algorithm: least_connections
  endpoints:
    - ip: "127.0.0.1"
      port: 8081
    - ip: "127.0.0.2"
      port: 8082
    - ip: "127.0.0.3"
      port: 8083

  # Example config of least response time
  # algorithm: least_response_time
  # endpoints:
  #   - ip: "127.0.0.1"
  #     port: 8081
  #   - ip: "127.0.0.2"
  #     port: 8082
  #   - ip: "127.0.0.3"
  #     port: 8083

  # Example config of round robin
  # algorithm: round_robin
  # endpoints:
  #   - ip: "127.0.0.1"
  #     port: 8081
  #   - ip: "127.0.0.2"
  #     port: 8082
  #   - ip: "127.0.0.3"
  #     port: 8083

  # Example config of weighted round robin
  # algorithm: weighted_round_robin
  # endpoints:
  #   - ip: "127.0.0.1"
  #     port: 8081
  #     weight: 1
  #   - ip: "127.0.0.2"
  #     port: 8082
  #     weight: 2
  #   - ip: "127.0.0.3"
  #     port: 8083
  #     weight: 3

  # Example config of consistent hash
  # algorithm: consistent_hash
  # replicas: 5
  # endpoints:
  #   - ip: "127.0.0.1"
  #     port: 8081
  #   - ip: "127.0.0.2"
  #     port: 8082
  #   - ip: "127.0.0.3"
  #     port: 8083

  # Example config of ip hash
  # algorithm: ip_hash
  # endpoints:
  #   - ip: "127.0.0.1"
  #     port: 8081
  #   - ip: "127.0.0.2"
  #     port: 8082
  #   - ip: "127.0.0.3"
  #     port: 8083

Run app

  • Firstly, build app. To do it type: ./lbbuild.sh build Release

  • Then, go to build/lb2/

  • Modify configs in build/lb2/configs/config.yaml or write your own.

  • Run app using: ./lb_app