add balancers doc

This commit is contained in:
jebbs 2022-10-12 09:43:34 +08:00
parent e06e975096
commit ecc434f837
10 changed files with 476 additions and 36 deletions

View File

@ -15,24 +15,23 @@
### Fields
| Type | Format |
|----------------|--------------------------------|
| `direct` | [Direct](./direct) |
| `block` | [Block](./block) |
| `socks` | [SOCKS](./socks) |
| `http` | [HTTP](./http) |
| `shadowsocks` | [Shadowsocks](./shadowsocks) |
| `vmess` | [VMess](./vmess) |
| `trojan` | [Trojan](./trojan) |
| `wireguard` | [Wireguard](./wireguard) |
| `hysteria` | [Hysteria](./hysteria) |
| `shadowsocksr` | [ShadowsocksR](./shadowsocksr) |
| `vless` | [VLESS](./vless) |
| `tor` | [Tor](./tor) |
| `ssh` | [SSH](./ssh) |
| `dns` | [DNS](./dns) |
| `selector` | [Selector](./selector) |
| `urltest` | [URLTest](./urltest) |
| Type | Format |
|---------------|------------------------------|
| `direct` | [Direct](./direct) |
| `block` | [Block](./block) |
| `socks` | [SOCKS](./socks) |
| `http` | [HTTP](./http) |
| `shadowsocks` | [Shadowsocks](./shadowsocks) |
| `vmess` | [VMess](./vmess) |
| `trojan` | [Trojan](./trojan) |
| `wireguard` | [Wireguard](./wireguard) |
| `hysteria` | [Hysteria](./hysteria) |
| `tor` | [Tor](./tor) |
| `ssh` | [SSH](./ssh) |
| `dns` | [DNS](./dns) |
| `selector` | [Selector](./selector) |
| `leastload` | [LeastLoad](./leastload) |
| `leastping` | [LeastPing](./leastping) |
#### tag

View File

@ -15,24 +15,23 @@
### 字段
| 类型 | 格式 |
|----------------|--------------------------------|
| `direct` | [Direct](./direct) |
| `block` | [Block](./block) |
| `socks` | [SOCKS](./socks) |
| `http` | [HTTP](./http) |
| `shadowsocks` | [Shadowsocks](./shadowsocks) |
| `vmess` | [VMess](./vmess) |
| `trojan` | [Trojan](./trojan) |
| `wireguard` | [Wireguard](./wireguard) |
| `hysteria` | [Hysteria](./hysteria) |
| `shadowsocksr` | [ShadowsocksR](./shadowsocksr) |
| `vless` | [VLESS](./vless) |
| `tor` | [Tor](./tor) |
| `ssh` | [SSH](./ssh) |
| `dns` | [DNS](./dns) |
| `selector` | [Selector](./selector) |
| `urltest` | [URLTest](./urltest) |
| 类型 | 格式 |
|---------------|------------------------------|
| `direct` | [Direct](./direct) |
| `block` | [Block](./block) |
| `socks` | [SOCKS](./socks) |
| `http` | [HTTP](./http) |
| `shadowsocks` | [Shadowsocks](./shadowsocks) |
| `vmess` | [VMess](./vmess) |
| `trojan` | [Trojan](./trojan) |
| `wireguard` | [Wireguard](./wireguard) |
| `hysteria` | [Hysteria](./hysteria) |
| `tor` | [Tor](./tor) |
| `ssh` | [SSH](./ssh) |
| `dns` | [DNS](./dns) |
| `selector` | [Selector](./selector) |
| `leastload` | [LeastLoad](./leastload) |
| `leastping` | [LeastPing](./leastping) |
#### tag

View File

@ -0,0 +1,46 @@
`leastload` determines the stability or load of nodes based on the standard deviation of the round-trip time from recent checks.
### Structure
```json
{
"type": "leastload",
"tag": "leastload-balancer",
"outbounds": [
"proxy-"
],
"fallback": "block",
"check": {
... // Health Check Fields
},
"pick": {
... // Balancer Node Pick Fields
}
}
```
### Fields
#### outbounds
List of outbound tags / tag prefixes.
for example, if there are `proxy-a`, `proxy-b`,`proxy-c` outbounds in the system:
- `proxy-a` will match the specific `proxy-a` outbound.
- `proxy-` will match all the above outbounds.
#### fallback
==Required==
The fallback outbound tag. if no outbound matches the policy, the fallback outbound will be used.
### Health Check Fields
See [Health Check](/configuration/shared/health_check/)。
### Balancer Node Pick Fields
See [Balancer Node Pick](/configuration/shared/node_pick/)。

View File

@ -0,0 +1,44 @@
`leastload` 根据最近检查的往返时间标准差来确定节点的稳定性或负载量。
### 结构
```json
{
"type": "leastload",
"tag": "leastload-balancer",
"outbounds": [
"proxy-"
],
"fallback": "block",
"health_check": {
... // 健康检查字段
},
"pick": {
... // 负载均衡节点筛选字段
}
}
```
### 字段
#### outbounds
用于选择的出站标签或标签前缀。例如:若系统中存在 `proxy-a`, `proxy-b`,`proxy-c`:
- `proxy-a` 将匹配特定的 `proxy-a` 出站。
- `proxy-` 将匹配以上所有出站。
#### fallback
==必填==
如果没有符合负载均衡策略的节点,回退到此出站。
### 健康检查字段
参阅 [健康检查](/zh/configuration/shared/health_check/)。
### 负载均衡节点筛选字段
参阅 [负载均衡节点筛选](/zh/configuration/shared/node_pick/)。

View File

@ -0,0 +1,46 @@
`leastping` determines the response speed of nodes based on the average round-trip time of recent checks. The nodes selected by this strategy are often those are closer to the server of check destination.
### Structure
```json
{
"type": "leastping",
"tag": "leastping-balancer",
"outbounds": [
"proxy-"
],
"fallback": "block",
"check": {
... // Health Check Fields
},
"pick": {
... // Balancer Node Pick Fields
}
}
```
### Fields
#### outbounds
List of outbound tags / tag prefixes.
for example, if there are `proxy-a`, `proxy-b`,`proxy-c` outbounds in the system:
- `proxy-a` will match the specific `proxy-a` outbound.
- `proxy-` will match all the above outbounds.
#### fallback
==Required==
The fallback outbound tag. if no outbound matches the policy, the fallback outbound will be used.
### Health Check Fields
See [Health Check](/configuration/shared/health_check/)。
### Balancer Node Pick Fields
See [Balancer Node Pick](/configuration/shared/node_pick/)。

View File

@ -0,0 +1,44 @@
`leastping` 根据最近检查的往返时间平均值来确定节点的响应速度。该策略选择的节点往往是离检查目标服务器较近的节点。
### 结构
```json
{
"type": "leastping",
"tag": "leastping-balancer",
"outbounds": [
"proxy-"
],
"fallback": "block",
"health_check": {
... // 健康检查字段
},
"pick": {
... // 负载均衡节点筛选字段
}
}
```
### 字段
#### outbounds
用于选择的出站标签或标签前缀。例如:若系统中存在 `proxy-a`, `proxy-b`,`proxy-c`:
- `proxy-a` 将匹配特定的 `proxy-a` 出站。
- `proxy-` 将匹配以上所有出站。
#### fallback
==必填==
如果没有符合负载均衡策略的节点,回退到此出站。
### 健康检查字段
参阅 [健康检查](/zh/configuration/shared/health_check/)。
### 负载均衡节点筛选字段
参阅 [负载均衡节点筛选](/zh/configuration/shared/node_pick/)。

View File

@ -0,0 +1,45 @@
### Structure
```json
{
"interval": "60s",
"sampling": 10,
"timeout": "5s",
"destination": "http://www.gstatic.com/generate_204",
"connectivity": "http://connectivitycheck.platform.hicloud.com/generate_204",
"max_rtt": "1000ms",
"tolerance": 0.2
}
```
### Fields
#### interval
The interval of health check for each node. Must be greater than `10s`, default is `60s`.
#### sampling
The number of recent health check results to sample. Must be greater than `0`, default is `10`.
#### timeout
The timeout of each health check. Must be greater than `0s`, default is `5s`.
#### destination
The destination of health check. Default is `http://www.gstatic.com/generate_204`.
#### connectivity
The destination of connectivity check. If health check fails, it may be caused by network unavailability (e.g. disconnecting from WIFI). Set this field to avoid the node being judged to be invalid under such circumstances. If not set, this behavior will not occur.
#### max_rtt
The maximum round-trip time of health check that is acceptable. Nodes that exceed this value will not be selected. Default is `0`, which accepts any node.
#### tolerance
The tolerance of health check failure. Must be greater than `0` and less than `1`, default is `0`.
`sampling=10, tolerance=0.2` means that in the last 10 checks, 2 failures are allowed at most.

View File

@ -0,0 +1,45 @@
### 结构
```json
{
"interval": "60s",
"sampling": 10,
"timeout": "5s",
"destination": "http://www.gstatic.com/generate_204",
"connectivity": "http://connectivitycheck.platform.hicloud.com/generate_204",
"max_rtt": "1000ms",
"tolerance": 0.2
}
```
### 字段
#### interval
每个节点的健康检查间隔。不小于`10s`,默认为 `60s`
#### sampling
对最近的多少次检查结果进行采样。大于 `0`,默认为 `10`
#### timeout
健康检查超时时间。大于 `0s`,默认为 `5s`
#### destination
健康检查目标。默认为 `http://www.gstatic.com/generate_204`
#### connectivity
网络连通性检查地址。健康检查失败,可能是由于网络不可用造成的(比如断开 WIFI 连接)。设置此项,可避免此类情况的下将节点判定为失效。若不设置,则不会有此行为。
#### max_rtt
可接受的健康检查最大往返时间,超过此设定值的节点将被不被选择。 默认为 `0`,即接受任何节点。
#### tolerance
健康检查失败的容忍度。大于 `0`,小于 `1`,默认为 `0`
`sampling=10, tolerance=0.2`,则表示在最近的 10 次检查中,最多允许 2 次失败。

View File

@ -0,0 +1,87 @@
### Structure
```json
{
"expected": 1,
"baselines": [
"50ms",
"100ms",
"150ms",
"200ms",
"250ms",
"350ms"
],
"costs": [
{
"match": "proxy-c",
"value": 10
},
{
"match": "x2.0"
},
{
"regexp": true,
"match": "x\\d+(\\.\\d+)?"
}
]
}
```
### expected
The expected number of outbound to be selected. The default value is 1.
### baselines
The RTT baselines which divides the node into different ranges. The default value is empty.
!!! tip "How does expected and baselines works"
The following examples illustrate the logic of different configuration combinations:
1. expected=`3` baselines =`[]`, select 3 nodes with the smallest RTT in recent checks.
1. expected=`3` baselines =`["50ms", "100ms", "150ms"]`
Suppose in the previous example, 3 nodes of `40ms`, `65ms`, `90ms` are selected, but there are more nodes of `90-100ms`, which are almost as good as the selected ones, we do not hope to waste them.
With the above baselines, to select 3 nodes, it must step into the `50-100ms` range, then other nodes in this range are also selected.
> The RTT described above, for the `leastload` strategy, refers to the node cost-weighted RTT standard deviation; for the `leastping` strategy, it refers to the node cost-weighted RTT average.
### costs
The cost rules of outbounds. The default value is empty.
Each cost rule has three fields:
```json
{
"regexp": true,
"match": "x\\d+(\\.\\d+)?",
"value": 10
}
```
It sets the cost of a outbound by matching its tag. The cost value will be eventually weighted to the node's RTT. The effect is that the higher the cost of a node, the lower the probability of it being selected.
The preceding cost rule has higher priority: if multiple rules can be matched, only the first matched rule will be used.
If no rule is matched, the node has a cost of `1`.
### costs.regexp
To enable regular expression matching. The default value is `false`.
### costs.match
match pattern.
### costs.value
Explicitly set the cost value for matching nodes. Defaults to `0`, i.e. not explicitly set.
If the field is not explicit set, the node's cost value is automatically set based on the number matched in the `match` expression from the tag. For example, matching the node `proxy-b-x2.0` with the regular expression `x\\d+(\\.\\d+)?` gets `x2.0`, then the number `2.0` is extracted and set to the cost value of this node.
If not explicitly set, and no number is found in the matched text, the cost value is set to `1`.

View File

@ -0,0 +1,85 @@
### 结构
```json
{
"expected": 1,
"baselines": [
"50ms",
"100ms",
"150ms",
"200ms",
"250ms",
"350ms"
],
"costs": [
{
"match": "proxy-c",
"value": 10
},
{
"match": "x2.0"
},
{
"regexp": true,
"match": "x\\d+(\\.\\d+)?"
}
]
}
```
### expected
期望选出的节点数量。默认为 `1`
### baselines
选择节点的基准线,它将节点划分为不同的档位。默认为空。
!!! tip "expected 和 baselines 的作用逻辑"
以下举例说明不同配置组合的逻辑:
1. expected=`3` baselines =`[]`,表示选出历次检查中 RTT 最小的 3 个节点。
1. expected=`3` baselines =`["50ms", "100ms", "150ms"]`
假设在上一例子中,选择了 `40ms`, `65ms`, `90ms` 的三个节点,但还有 N 个 `90-100ms` 的节点与被选的几乎同样优秀,我们不希望浪费它们。
配置上述基准线后,要选择到 3 个节点,必须跨入 `50-100ms` 这一档位,那么这一档位内的其它节点也一同被选中。
> 上方所述 RTT对于 `leastload` 策略,指的是节点成本加权的 RTT 标准差;对于 `leastping` 策略,指的是节点成本加权的 RTT 平均值。
### costs
节点的成本规则。默认为空。
节点的成本规则是一个数组,每个规则包含三个字段:
```json
{
"regexp": true,
"match": "x\\d+(\\.\\d+)?",
"value": 10
}
```
它通过匹配出站的 `tag` 来设置成本值,这个成本值最终会加权到节点的 RTT 上。效果是,节点的成本越高,它被选中的概率越低。
排在前面的成本规则具有更高优先级,如果能匹配到多个规则,只会使用第一个匹配到的规则。
如果没有匹配到任何规则,那么节点的成本为 `1`
### costs.regexp
是否使用正则表达式匹配。默认为 `false`
### costs.match
匹配表达式
### costs.value
显式设定匹配节点的成本值。默认为 `0`,即不显式设置。
在没有设置此字段的情况下,节点的成本值会根据 `match` 表达式中匹配到的数字自动设置。例如,以正则表达式 `x\\d+(\\.\\d+)?` 匹配节点 `proxy-b-x2.0`,将匹配到 `x2.0`。其中的数字 `2.0` 会被提取并设置为这个节点的成本值。
若没有显式设置,且匹配文本中没有找到数字,那么成本值会被设置为 `1`