Configuring per-route options
Page last updated:
By default, communication between Gorouter and backends is configured via general settings at the platform level.
This topic describes how to specify per-route Gorouter options scoped at the application level. This greater granularity lets developers tailor optimal routing behavior for applications’ unique load profiles or other requirements.
Gorouter supports the following per-route option, described in the section below:
loadbalancing
: Configures the load balancing algorithm used by Gorouter for this particular route.- Settings:
round-robin
,least-connections
.
- Settings:
loadbalancing: Configure Gorouter’s Load Balancing Algorithm
The per-route option loadbalancing
allows configuring the load balancing algorithm, which defines how the load is distributed between Gorouters and backends.
This option supports two settings for load balancing:
round-robin
distributes the load evenly across all available backendsleast-connections
directs traffic to the backend with the fewest active connections at any given time, optimizing resource utilization
Configure Load Balancing in an App Manifest
To configure per-route load balancing for an application that has not yet been pushed:
In the application manifest, include a
route
definition with anoptions: loadbalancing
attribute set toround-robin
orleast-connections
. For example:--- applications: - name: MY-APP routes: - route: MY-APP.EXAMPLE.COM options: loadbalancing: least-connections
Where
MY-APP
is the name of your app andMY-APP.EXAMPLE.COM
is the route you want to map to your app.Push the app with the manifest:
cf push -f manifest.yml
To confirm the setting, query the
routes
API endpoint for the app’s route:cf curl /v3/routes/?hosts=MY-APP
Where
MY-APP
is the host attribute of the route. The response lists the chosenloadbalancing
algorithm setting:"options": { "loadbalancing": "least-connections" }
Change Load Balancing of an Existing App
To change the per-route loadbalancing
setting of an app that has already been pushed, cf curl
the /v3/routes
API.
For example, to change an app route’s algorithm from least-connections
to round-robin
:
Execute a
PATCH
request to the targeted API endpoint:cf curl /v3/routes/GUID -X PATCH -H "Content-type: application/json" \ -d '{ "options": { "loadbalancing": "round-robin" } }'
Where
GUID
is the unique identifier for the route.To confirm the setting, query the
routes
API endpoint for the route:cf curl /v3/routes/GUID
Where GUID
is the unique identifier for the route. The response lists the new round-robin
setting:
"options": {
"loadbalancing": "round-robin"
}
Create a pull request or raise an issue on the source for this page in GitHub