mt-olympus / metis
Load Balance implementation in PHP
Installs: 24 257
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.1
- laminas/laminas-cache: ^2.8 || ^2.9
- laminas/laminas-servicemanager: ^3.1
- laminas/laminas-stdlib: ^3.0
- mt-olympus/hermes: ^1.5
This package is auto-updated.
Last update: 2024-11-06 22:52:02 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:
- metis-athena: Fetches the list from a Athena (Service Discovery) service
- metis-demeter: Fetches the list from a Demeter (Distributed Configuration) service
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