带宽限制
用于控制访问代理服务的流量速率,如果是目标服务是集群,控制的是所有目标服务的总流量速率,也就是是以代理维度进行限流。
基本概念
| 方向 | 说明 |
|---|---|
| 入站 (in) | 客户端访问代理服务的流量(下载到客户端) |
| 出站 (out) | 代理服务响应客户端的流量(上传到服务端) |
限流行为
当客户端请求速度超过限制时(默认500ms):
| 协议 | 行为 |
|---|---|
| HTTP | 返回 HTTP 429 (Too Many Requests) 状态码 |
| TCP | 直接关闭连接 |
配置示例
示例 1:限制总带宽(上下行共享)
[[proxies]]
name = "web"
protocol = "http"
custom_domains = ["a.domain.com"]
targets = [
{ host = "127.0.0.1", port = 8001 }
]
[proxies.bandwidth]
enabled = true
limit_total = "2Mbps"
示例 2:分别限制入站和出站带宽
[[proxies]]
name = "web"
protocol = "http"
custom_domains = ["a.domain.com"]
targets = [
{ host = "127.0.0.1", port = 8001 }
]
[proxies.bandwidth]
enabled = true
limit_in = "2Mbps"
limit_out = "1Mbps"
示例 3:限制总带宽的同时分别设置出入站
[[proxies]]
name = "web"
protocol = "http"
custom_domains = ["a.domain.com"]
targets = [
{ host = "127.0.0.1", port = 8001 }
]
[proxies.bandwidth]
enabled = true
limit_total = "2Mbps"
limit_in = "1Mbps"
limit_out = "1Mbps"
注意
如果同时填写了三个参数,那么limit_in 和 limit_out 两者之和不能超过 limit_total,此时limit_total会失效,系统会以 limit_in 和 limit_out 的值为准进行限流。
示例 4:只限制入站带宽和总带宽
[[proxies]]
name = "web"
protocol = "http"
custom_domains = ["a.domain.com"]
targets = [
{ host = "127.0.0.1", port = 8001 }
]
[proxies.bandwidth]
enabled = true
limit_total = "5Mbps"
limit_in = "1Mbps"
如果只配置了 limit_total 和 limit_in,则 limit_out 的值会自动计算为 limit_total - limit_in,也就是
limit_out="4Mbps"(5Mbps - 1Mbps)
参数说明
| 参数名 | 类型 | 默认值 | 描述 | 必填 |
|---|---|---|---|---|
| enabled | Boolean | false | 是否启用带宽限制 | 否 |
| limit_total | String | - | 总带宽限制(入站+出站共享) | 否 |
| limit_in | String | - | 入站带宽限制(客户端下载) | 否 |
| limit_out | String | - | 出站带宽限制(客户端上传) | 否 |
带宽格式
单位区分大小写,必须使用大写形式,数值必须为正整数,书写格式如下:
数值 + 单位
支持的单位:
| 单位 | 说明 | 转换系数 |
|---|---|---|
| bps | 比特每秒 | 1 |
| Kbps | 千比特每秒 | 1,000 |
| Mbps | 兆比特每秒 | 1,000,000 |
| Gbps | 吉比特每秒 | 1,000,000,000 |
有效值示例
limit_total = "10Mbps"
limit_in = "100Kbps"
limit_out = "1Gbps"
验证规则
| 规则 | 说明 |
|---|---|
| 总带宽必须大于 0 | limit_total 必须为正数 |
| 入站/出站必须大于等于 0 | 可以为 0 表示不限速 |
| 入站/出站不能大于总带宽 | 单向带宽不能超过总带宽 |
| 入站 + 出站不能大于总带宽 | 两者之和不能超过总带宽 |