Code Monkey home page Code Monkey logo

lb2's Introduction

  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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.