Skip to content
master
Switch branches/tags
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 

README.md

负载均衡算法

介绍

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

预览图

调度算法

轮询

快速使用

use Robin\SmoothWeightedRobin;

require_once '/Autoloader.php';

// 加权轮询
$services = [
    '192.168.10.1:2202' => 5,
    '192.168.10.2:2202' => 1,
    '192.168.10.3:2202' => 1,
];

// 使用平滑加权算法
$robin = new SmoothWeightedRobin();
$robin->init($services);

$nodes = [];
for ($i = 1; $i <= 7; $i++) {
    $node = $robin->next();
    $nodes[$i] = $node;
}

//var_export(array_count_values($nodes));
var_export($nodes);

调度结果

使用平滑加权算法调度,会生成如下均匀序列:

'192.168.10.1:2202'
'192.168.10.1:2202'
'192.168.10.2:2202'
'192.168.10.1:2202'
'192.168.10.3:2202'
'192.168.10.1:2202'
'192.168.10.1:2202'

About

No description, website, or topics provided.

Resources

Releases

No releases published

Packages

No packages published

Languages