2017 © Pedro Peláez
 

library metis

Load Balance implementation in PHP

image

mt-olympus/metis

Load Balance implementation in PHP

  • Thursday, October 13, 2016
  • by Lansoweb
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7,217 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 11 % Grown

The README.md

Metis

Introduction

This is a Dynamic Routing and Load Balance library made with PHP., (*1)

It's goal is to "choose" an endpoint to connect to in distributed systems, like in a micro service architeture., (*2)

You can use this library with Athena server, that can returns more than one server and use this module to choose one of them based on some rules and statistics about the servers., (*3)

You can inject a Metis instance to a Hermes, and it will automatically choose a server to connect to. More info on the Hermes documentation., (*4)

Components

  • Service list
  • Rule

Service list

  • Static: from a configuration file
  • Fetched: from a remote server

The fetched method is available through one of the following libraries: * metis-athena: Fetches the list from a Athena (Service Discovery) service * metis-demeter: Fetches the list from a Demeter (Distributed Configuration) service, (*5)

Static server list

The list is an well formed array:, (*6)

return [
    'metis' => [
        'services' => [
            'service1' => [ // a unique service identification
                [
                    'host' => 'server1',
                    'uri' => 'http://192.168.1.2/v1/service1',
                ],
                [
                    'host' => 'server2',
                    'uri' => 'https://server2/v1/service1',
                ],
                [
                    'host' => 'server3',
                    'uri' => 'https://server3.mycompany.com:7001/v1/service1',
                ],
            ],
            'service2' => [ // a unique service identification
                [
                    'host' => 'server1',
                    'uri' => 'http://192.168.1.2:7002/v1/service2',
                ],
            ],
        ],
    ],
];

Strategy

Regardless the chosen strategy, if there is a Cerberus (Circuit Breaker) attached, the unavailable services will be filtered., (*7)

  • RoundRobin: Cycles among the services in a specific order
  • Random: Each time will select a random service from the list
  • ResponseTime: Each service has it's response time measured and this time is weighted. The faster service have more probability to be chosen.

Installation

composer require mt-olympus/metis

Zend Expressive

Just copy the config/metis.global.php.dist to your expressive project as config/autoload/metis.global.php, (*8)

Zend Framework

Include the module in your application.config.php, (*9)

The Versions