@ -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.
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.
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.