Send requests to the least busy endpoint
Compare four endpoints instead of the default two and pick the one with the fewest requests in flight, for a destination whose requests vary in cost.
Configuration
apiVersion: kuma.io/v1alpha1
kind: MeshLoadBalancingStrategy
metadata:
name: backend-least-request
namespace: kong-mesh-demo
labels:
kuma.io/mesh: default
spec:
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
default:
loadBalancer:
type: LeastRequest
leastRequest:
choiceCount: 4
activeRequestBias: 1Copied!
type: MeshLoadBalancingStrategy
name: backend-least-request
mesh: default
spec:
to:
- targetRef:
kind: MeshService
labels:
kuma.io/display-name: backend
default:
loadBalancer:
type: LeastRequest
leastRequest:
choiceCount: 4
activeRequestBias: 1Copied!
Adjust konnect_mesh_control_plane.my_meshcontrolplane.id and konnect_mesh.my_mesh.name according to your current configuration.
resource "konnect_mesh_load_balancing_strategy" "backend_least_request" {
provider = konnect-beta
type = "MeshLoadBalancingStrategy"
name = "backend-least-request"
spec = {
to = [
{
target_ref = {
kind = "MeshService"
labels = {
"kuma.io/display-name" = "backend"
}
}
default = {
load_balancer = {
type = "LeastRequest"
least_request = {
choice_count = 4
active_request_bias = { integer = 1 }
}
}
}
}
]
}
labels = {
"kuma.io/mesh" = konnect_mesh.my_mesh.name
}
cp_id = konnect_mesh_control_plane.my_meshcontrolplane.id
mesh = konnect_mesh.my_mesh.name
}
Copied!