Giter Club home page Giter Club logo

tiny-load-balancer's Introduction

ReactPHP tiny balancer

This is a ReactPHP based tiny load balanced for testing and development purposes. With a simple configuration and an already published docker image, you will be able to manage multiple servers in your docker-compose without any pain by balancing your traffic among them all.

Install

You can install the balancer by just cloning the repository somewhere in your localhost.

cd /tmp/
git clone [email protected]:driftphp/tiny-load-balancer.git
cd tiny-load-balancer

Then, you should install the composer dependencies. Make sure you have composer installed locally. If you have some php platform issues, just composer update instead of install.

composer install

Use it

You can use the balancer as a simple random balancer. Not even a round robin. This repository is meant to be used as a small piece of code for balancing TCP requests among a set of ReactPHP servers, so a simple random balancing would be enough for that purpose.

./balancer 8000 8001
./balancer 8000 myhost:8001 127.0.0.1:8002
./balancer 8000 myhost:8001-8010
./balancer 8000 :8001-8010
  • By default, local 127.0.0.1 host will be used if only ports are defined
  • Ports with format 8001-8010 will result in a sequence of all ports between both numbers, 8001, 8002, 8003... 8010
  • You can use named hosts
  • You can add multiple hosts and ports

By default, debug will be enabled. You can disable output by using the flag silence.

./balancer 8000 8001 --silence

docker-compose

You can add this balancer in your docker-compose file.

version: '3'
services:
  tiny_balancer:
    image: "driftphp/tiny-balancer"
    ports:
      - "8000:8000"
    networks: [main]
    entrypoint: [
      "/balancer",
      "8000",
      "server_1:8000",
      "server_2:8000"
    ]

  server_1:
    build: .
    networks: [main]
    container_name: server_1
    entrypoint: ["/server-entrypoint.sh"]

  server_2:
    build: .
    networks: [main]
    container_name: server_2
    entrypoint: ["/server-entrypoint.sh"]

networks:
  main:

tiny-load-balancer's People

Contributors

mmoreram avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.