From d7635e3496181277cd35c292344c928b0f1ac8ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BD=97=E6=B3=BD=E8=BD=A9?= Date: Thu, 7 Mar 2024 10:06:54 +0800 Subject: [PATCH] docs: add bandwidthLimit plugin (#356) Signed-off-by: spacewander --- .../docs/reference/plugins/bandwidth_limit.md | 88 +++++++++++++++++++ .../docs/reference/plugins/bandwidth_limit.md | 88 +++++++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 site/content/en/docs/reference/plugins/bandwidth_limit.md create mode 100644 site/content/zh-hans/docs/reference/plugins/bandwidth_limit.md diff --git a/site/content/en/docs/reference/plugins/bandwidth_limit.md b/site/content/en/docs/reference/plugins/bandwidth_limit.md new file mode 100644 index 00000000..b3c46b6c --- /dev/null +++ b/site/content/en/docs/reference/plugins/bandwidth_limit.md @@ -0,0 +1,88 @@ +--- +title: Bandwidth Limit +--- + +## Description + +The `bandwidthLimit` plugin restricts the maximum bandwidth of the data stream by leveraging Envoy's `bandwidth_limit` filter. Note that this limitation only applies to the request or response body. + +## Attribute + +| | | +|-------|---------| +| Type | Traffic | +| Order | Outer | + +## Configuration + +See the corresponding [Envoy documentation](https://www.envoyproxy.io/docs/envoy/v1.28.0/configuration/http/http_filters/bandwidth_limit_filter). + +## Usage + +Assumed we have the HTTPRoute below attached to `localhost:10000`, and a backend server listening to port `8080`: + +```yaml +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: default +spec: + parentRefs: + - name: default + namespace: default + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: backend + port: 8080 +``` + +By applying the configuration below, the upload speed of requests sent to `http://localhost:10000/` will be limited to approximately 10kb/s: + +```yaml +apiVersion: mosn.io/v1 +kind: HTTPFilterPolicy +metadata: + name: policy +spec: + targetRef: + group: gateway.networking.k8s.io + kind: HTTPRoute + name: default + filters: + bandwidthLimit: + config: + statPrefix: policy_bandwidth_limit + enableMode: REQUEST + limitKbps: 10 + fillInterval: 0.02s +``` + +The bandwidth limit is not very precise. The smaller the `fillInterval`, the higher the accuracy. + +To test the effect of the plugin, we have the backend server listening on port `8080` which echoes all received requests. Let's try it with [bombardier](https://pkg.go.dev/github.com/codesenberg/bombardier): + +``` +$ bombardier -m POST -f go.sum -c 10 -t 180s -d 60s -l http://localhost:10000/ +Bombarding http://localhost:10000/ for 1m0s using 10 connection(s) +[======================================================================================================================================================] 1m0s +Done! +Statistics Avg Stdev Max + Reqs/sec 0.15 2.77 52.57 + Latency 40.35s 15.50s 1.29m + Latency Distribution + 50% 38.35s + 75% 45.28s + 90% 0.99m + 95% 1.15m + 99% 1.29m + HTTP codes: + 1xx - 0, 2xx - 19, 3xx - 0, 4xx - 0, 5xx - 0 + others - 0 + Throughput: 20.11KB/s +``` + +Since the upstream bandwidth is limited to 10KB/s and the downstream bandwidth is not restricted, bombardier reported an overall bandwidth of 20.11KB/s. diff --git a/site/content/zh-hans/docs/reference/plugins/bandwidth_limit.md b/site/content/zh-hans/docs/reference/plugins/bandwidth_limit.md new file mode 100644 index 00000000..47e9c1d7 --- /dev/null +++ b/site/content/zh-hans/docs/reference/plugins/bandwidth_limit.md @@ -0,0 +1,88 @@ +--- +title: Bandwidth Limit +--- + +## 说明 + +`bandwidthLimit` 插件通过利用 Envoy 的 `bandwidth_limit` 过滤器限制数据流的最大带宽。注意该限制只涉及请求体或响应体。 + +## 属性 + +| | | +|-------|---------| +| Type | Traffic | +| Order | Outer | + +## 配置 + +请参阅相应的 [Envoy 文档](https://www.envoyproxy.io/docs/envoy/v1.28.0/configuration/http/http_filters/bandwidth_limit_filter)。 + +## 用法 + +假设我们有下面附加到 `localhost:10000` 的 HTTPRoute,并且有一个后端服务器监听端口 `8080`: + +```yaml +apiVersion: gateway.networking.k8s.io/v1 +kind: HTTPRoute +metadata: + name: default +spec: + parentRefs: + - name: default + namespace: default + rules: + - matches: + - path: + type: PathPrefix + value: / + backendRefs: + - name: backend + port: 8080 +``` + +通过应用下面的配置,发送到 `http://localhost:10000/` 的请求的上传速度将被限制在大约 1kb/s: + +```yaml +apiVersion: mosn.io/v1 +kind: HTTPFilterPolicy +metadata: + name: policy +spec: + targetRef: + group: gateway.networking.k8s.io + kind: HTTPRoute + name: default + filters: + bandwidthLimit: + config: + statPrefix: policy_bandwidth_limit + enableMode: REQUEST + limitKbps: 10 + fillInterval: 0.02s +``` + +带宽限制并不是很精准。`fillInterval` 越小,精确度越高。 + +为了测试插件效果,我们让监听端口 `8080` 的后端服务器返回所有收到的请求。让我们用 [bombardier](https://pkg.go.dev/github.com/codesenberg/bombardier) 试一下: + +``` +$ bombardier -m POST -f go.sum -c 10 -t 180s -d 60s -l http://localhost:10000/ +Bombarding http://localhost:10000/ for 1m0s using 10 connection(s) +[======================================================================================================================================================] 1m0s +Done! +Statistics Avg Stdev Max + Reqs/sec 0.15 2.77 52.57 + Latency 40.35s 15.50s 1.29m + Latency Distribution + 50% 38.35s + 75% 45.28s + 90% 0.99m + 95% 1.15m + 99% 1.29m + HTTP codes: + 1xx - 0, 2xx - 19, 3xx - 0, 4xx - 0, 5xx - 0 + others - 0 + Throughput: 20.11KB/s +``` + +由于上行带宽被限制在 10KB/s,而下行带宽没有限制,bombardier 报告了整体带宽是 20.11KB/s。