1 Star 2 Fork 1

Tinywan / load-polling

Create your Gitee Account
Explore and code with more than 5 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

nginx

介绍

用 PHP 实现几种负载均衡调度算法,详细见 负载均衡算法 系列。fork

调度算法

Installation

composer require tinywan/load-polling 

Basic Usage

// 服务器数
$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',
)

Composer管理

安装提示错误:Could not find package tinywan/load-polling in a version matching 1.0 尝试改成Packagist的地址 https://packagist.org

"repositories": {
    "packagist": {
        "type": "composer",
        "url": "https://packagist.org"
    }
}

要使你发布的最新包可以使用,请使用以上的镜像源,为了学习

参考

Comments ( 0 )

Sign in for post a comment

About

用 PHP 实现几种负载均衡调度算法 spread retract
Cancel

Releases

No release

Contributors

All

Activities

load more
can not load any more
PHP
1
https://gitee.com/Tinywan/load-polling.git
git@gitee.com:Tinywan/load-polling.git
Tinywan
load-polling
load-polling
master

Search