mirror of https://github.com/status-im/consul.git
docs: service rate limiting examples (#19925)
* Include examples on usage page. * Description/example alignment
This commit is contained in:
parent
69e3f93ee8
commit
c870c00e70
|
@ -1737,16 +1737,15 @@ Proxy services must be in transparent proxy mode to configure destinations. Refe
|
|||
|
||||
</CodeTabs>
|
||||
|
||||
|
||||
### Enable request rate limit for a service on all paths <EnterpriseAlert inline />
|
||||
|
||||
The following example limits the request rate on all paths to `service-foo` to an average of `1000` requests per second but allows up to `1500` temporary concurrent requests.
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service to an average of 1000 requests per second, but allows the service to accept up to 1500 concurrent requests.
|
||||
|
||||
<CodeTabs tabs={[ "HCL", "Kubernetes YAML", "JSON" ]}>
|
||||
|
||||
```hcl
|
||||
Kind = "service-defaults"
|
||||
Name = "service-foo"
|
||||
Name = "billing"
|
||||
Protocol = "http"
|
||||
|
||||
RateLimit {
|
||||
|
@ -1756,21 +1755,21 @@ RateLimit {
|
|||
}
|
||||
}
|
||||
```
|
||||
|
||||
```yaml
|
||||
kind: ServiceDefaults
|
||||
name: service-foo
|
||||
name: billing
|
||||
protocol: http
|
||||
rateLimit:
|
||||
instanceLevel:
|
||||
requestsPerSecond: 1000
|
||||
requestsMaxBurst: 1500
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"Kind": "service-defaults",
|
||||
"Name": "service-foo",
|
||||
"Name": "billing",
|
||||
"Protocol": "http",
|
||||
"RateLimit": {
|
||||
"InstanceLevel": {
|
||||
|
@ -1780,6 +1779,7 @@ rateLimit:
|
|||
}
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
### Enable request rate limit on a prefixed path <EnterpriseAlert inline />
|
||||
|
@ -1840,11 +1840,12 @@ rateLimit:
|
|||
}
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
||||
### Enable request rate limits on multiple paths <EnterpriseAlert inline />
|
||||
|
||||
The following example limits the request rate to the `billing` service when requests begin with `/api` and `/login`.
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service depending on the path it received the request on. The service is limited to an average of 500 requests when the request is made on an HTTP path with the `/api` prefix. When an instance of the billing service receives a request from the `/login` path, it is limited to an average of 100 requests per second and 500 concurrent connections.
|
||||
|
||||
<CodeTabs tabs={[ "HCL", "Kubernetes YAML", "JSON" ]}>
|
||||
|
||||
|
@ -1883,6 +1884,7 @@ rateLimit:
|
|||
requestsPerSecond: 100
|
||||
requestsMaxBurst: 500
|
||||
```
|
||||
|
||||
```json
|
||||
{
|
||||
"Kind": "service-defaults",
|
||||
|
@ -1905,4 +1907,5 @@ rateLimit:
|
|||
}
|
||||
}
|
||||
```
|
||||
|
||||
</CodeTabs>
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
---
|
||||
layout: docs
|
||||
page_title: Limit request rates to services in the mesh
|
||||
description: Learn how to limit the rate of requests to services in a Consul service mesh. Rate limits on requests improves network resilience and availability
|
||||
description: Learn how to limit the rate of requests to services in a Consul service mesh. Rate limits on requests improves network resilience and availability.
|
||||
---
|
||||
|
||||
# Limit request rates to services in the mesh
|
||||
|
@ -32,12 +32,39 @@ Specify request rate limits in the service defaults configuration entry. Create
|
|||
1. `RateLimits.InstanceLevel.RequestPerSecond`: Set an average number of requests per second that Consul should allow to the service. The number of requests may momentarily exceed this value up to the value specified in the `RequestsMaxBurst` parameter, but Consul temporarily lowers the speed of the transactions.
|
||||
1. `RateLimits.InstanceLevel.RequestsMaxBurst`: Set the maximum number of concurrent requests that Consul momentarily allows to the service. Consul blocks any additional requests over this limit.
|
||||
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service to an average of 1000 requests per second, but allows the service to accept up to 1500 concurrent requests.
|
||||
|
||||
```hcl
|
||||
Kind = "service-defaults"
|
||||
Name = "billing"
|
||||
Protocol = "http"
|
||||
|
||||
RateLimit {
|
||||
InstanceLevel {
|
||||
RequestsPerSecond = 1000
|
||||
RequestsMaxBurst = 1500
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
<Tab heading="Kubernetes" group="k8s">
|
||||
|
||||
1. `spec.rateLimits.instanceLevel.requestPerSecond`: Set an average number of requests per second that Consul should allow to the service. The number of requests may momentarily exceed this value up to the value specified in the `requestsMaxBurst` parameter, but Consul temporarily lowers the speed of the transactions.
|
||||
1. `spec.rateLimits.instanceLevel.requestsMaxBurst`: Set the maximum number of concurrent requests that Consul momentarily allows to the service. Consul blocks any additional requests over this limit.
|
||||
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service to an average of 1000 requests per second, but allows the service to accept up to 1500 concurrent requests.
|
||||
|
||||
```yaml
|
||||
kind: ServiceDefaults
|
||||
name: billing
|
||||
protocol: http
|
||||
rateLimit:
|
||||
instanceLevel:
|
||||
requestsPerSecond: 1000
|
||||
requestsMaxBurst: 1500
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
|
@ -59,6 +86,30 @@ Specify request rate limits in the service defaults configuration entry. Create
|
|||
- `RequestsPerSecond`: Set an average number of requests per second that Consul should allow to the service through the matching path. The number of requests may momentarily exceed this value up to the value specified in the `RequestsMaxBurst` parameter, but Consul temporarily lowers the speed of the transactions. This configuration overrides the value specified in `RateLimits.InstanceLevel.RequestPerSecond` field of the configuration entry.
|
||||
- `RequestsMaxBurst`: Set the maximum number of concurrent requests that Consul momentarily allows to the service through the matching path. Consul blocks any additional requests over this limit. This configuration overrides the value specified in `RateLimits.InstanceLevel.RequestsMaxBurst` field of the configuration entry.
|
||||
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service depending on the path it received the request on. The service is limited to an average of 500 requests when the request is made on an HTTP path with the `/api` prefix. When an instance of the billing service receives a request from the `/login` path, it is limited to an average of 100 requests per second and 500 concurrent connections.
|
||||
|
||||
```hcl
|
||||
Kind = "service-defaults"
|
||||
Name = "billing"
|
||||
Protocol = "http"
|
||||
|
||||
RateLimit {
|
||||
InstanceLevel {
|
||||
Routes = [
|
||||
{
|
||||
PathPrefix = "/api"
|
||||
RequestsPerSecond = 500
|
||||
},
|
||||
{
|
||||
PathPrefix = "/login"
|
||||
RequestsPerSecond = 100
|
||||
RequestsMaxBurst = 500
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
</Tab>
|
||||
<Tab heading="Kubernetes" group="k8s">
|
||||
|
||||
|
@ -71,8 +122,23 @@ Specify request rate limits in the service defaults configuration entry. Create
|
|||
- `requestsPerSecond`: Set an average number of requests per second that Consul should allow to the service through the matching path. The number of requests may momentarily exceed this value up to the value specified in the `requestsMaxBurst` parameter, but Consul temporarily lowers the speed of the transactions. This configuration overrides the value specified in `spec.rateLimits.instanceLevel.requestPerSecond` field of the CRD.
|
||||
- `requestsMaxBurst`: Set the maximum number of concurrent requests that Consul momentarily allows to the service through the matching path. Consul blocks any additional requests over this limit. This configuration overrides the value specified in `spec.rateLimits.instanceLevel.requestsMaxBurst` field of the CRD.
|
||||
|
||||
The following example configures the default behavior for a service named `billing`. This configuration limits each instance of the billing service depending on the path it received the request on. The service is limited to an average of 500 requests when the request is made on an HTTP path with the `/api` prefix. When an instance of the billing service receives a request from the `/login` path, it is limited to an average of 100 requests per second and 500 concurrent connections.
|
||||
|
||||
```yaml
|
||||
kind: service-defaults
|
||||
name: billing
|
||||
protocol: http
|
||||
rateLimit:
|
||||
instanceLevel:
|
||||
routes:
|
||||
- pathPrefix: /api
|
||||
requestsPerSecond: 500
|
||||
- pathPrefix: /login
|
||||
requestsPerSecond: 100
|
||||
requestsMaxBurst: 500
|
||||
```
|
||||
|
||||
</Tab>
|
||||
</Tabs>
|
||||
|
||||
Refer to the [service defaults configuration entry reference](/consul/docs/connect/config-entries/service-defaults) for additional specifications and example configurations.
|
||||
|
||||
Refer to the [service defaults configuration entry reference](/consul/docs/connect/config-entries/service-defaults) for additional specifications and example configurations.
|
Loading…
Reference in New Issue