https://github.com/tinywan/load-balancing
Implementing several load balancing scheduling algorithms with PHP - 用 PHP 实现几种负载均衡调度算法
https://github.com/tinywan/load-balancing
nginx-load-balance nginx-upstream php7 polling robin robin-panel
Last synced: about 1 month ago
JSON representation
Implementing several load balancing scheduling algorithms with PHP - 用 PHP 实现几种负载均衡调度算法
- Host: GitHub
- URL: https://github.com/tinywan/load-balancing
- Owner: Tinywan
- Created: 2019-01-15T02:30:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-08-16T09:01:53.000Z (about 5 years ago)
- Last Synced: 2024-10-31T20:12:59.293Z (11 months ago)
- Topics: nginx-load-balance, nginx-upstream, php7, polling, robin, robin-panel
- Language: PHP
- Homepage:
- Size: 102 KB
- Stars: 49
- Watchers: 4
- Forks: 14
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Introduction(介绍)
用 PHP 实现几种负载均衡调度算法,详细见 [负载均衡算法](https://www.fanhaobai.com/2018/11/load-balance-round-robin.html) 系列。[fork](https://github.com/fan-haobai/load-balance)
### Scheduling Algorithm (调度算法)
* [普通轮询(general Round Robin)](https://github.com/Tinywan/load-polling/blob/master/src/Robin.php)
* [加权轮询(Weighted Round Robin)](https://github.com/Tinywan/load-polling/blob/master/src/WeightedRobin.php)
* [平滑加权轮询(Smooth Weighted Round Robin)](https://github.com/Tinywan/load-polling/blob/master/src/SmoothWeightedRobin.php)### Install
```composer log
composer require tinywan/load-balancing
```### Basic Usage
```php
// 服务器数
$services = [
'192.168.10.1' => 5,
'192.168.10.2' => 1,
'192.168.10.3' => 1,
];// 使用平滑加权算法 (Smooth Weighted Round Robin)
$robin = new \Robin\SmoothWeightedRobin();
$robin->init($services);$nodes = [];
$sumWeight = $robin->getSumWeight();
for ($i = 1; $i <= $sumWeight; $i++) {
$node = $robin->next();
$nodes[$i] = $node;
}
var_export($nodes);// 会生成如下均匀序列
array (
1 => '192.168.10.1',
2 => '192.168.10.1',
3 => '192.168.10.2',
4 => '192.168.10.1',
5 => '192.168.10.3',
6 => '192.168.10.1',
7 => '192.168.10.1',
)
```### Help
* [负载均衡算法](https://github.com/fan-haobai/load-balance)
* [负载均衡算法 — 轮询](https://www.fanhaobai.com/2018/11/load-balance-round-robin.html)
* [负载均衡算法 — 平滑加权轮询](https://www.fanhaobai.com/2018/11/load-balance-smooth-weighted-round-robin.html)
* [Nginx的负载均衡 - 加权轮询 (Weighted Round Robin) 上篇](https://blog.csdn.net/zhangskd/article/details/50194069)
* [Nginx的负载均衡 - 加权轮询 (Weighted Round Robin) 下篇](https://blog.csdn.net/zhangskd/article/details/50197929)
* [Composer/Packagist包](https://www.chenjie.info/1880)