mt-olympus/metis

Load Balance implementation in PHP

1.1.1 2020-03-06 12:13 UTC

This package is auto-updated.

Last update: 2024-04-06 21:25:47 UTC


README

Introduction

This is a Dynamic Routing and Load Balance library made with PHP.

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

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.

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.

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:

Static server list

The list is an well formed array:

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.

  • 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

Zend Framework

Include the module in your application.config.php