-
Notifications
You must be signed in to change notification settings - Fork 232
Expand file tree
/
Copy pathcustom-per-route-options.html.md.erb
More file actions
124 lines (80 loc) · 5.33 KB
/
custom-per-route-options.html.md.erb
File metadata and controls
124 lines (80 loc) · 5.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
---
title: Configuring per-route options
owner: CF for VMs Networking
---
By default, communication between Gorouter and backends is configured through the 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 options, described in the sections below:
- `loadbalancing`: Configures the load balancing algorithm used by Gorouter for this particular route. <%= vars.per_route_lb_version %>
- Settings: `round-robin`, `least-connection`, `hash`.
- `hash_header`: Defines the HTTP header used for hash-based routing decisions. Required when `loadbalancing` is set to `hash`. Cannot be used with other load balancing algorithms. <%= vars.hash_routing_version %>
- `hash_balance`: Sets the float number for the balance factor used by Gorouter to manage load imbalance applying the hash-based routing for this route. Optional when `loadbalancing` is `hash`. Cannot be used with other algorithms. <%= vars.hash_routing_version %>
## <a id="loadbalancing"></a> Configure Gorouter's Load Balancing Algorithm
<%= vars.per_route_lb_version %>
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 the following settings for load balancing:
- `round-robin` distributes the load evenly across all available backends
- `least-connection` directs traffic to the backend with the fewest active connections at any given time, optimizing resource utilization
- `hash` distributes requests based on a specific HTTP header value, ensuring requests with the same header value are consistently directed to the same backend. See [Hash-Based Routing](hash-based-routing.html) for details. <%= vars.hash_routing_version %>
### <a id="lb-set-manifest"></a> Configure Load Balancing using an App Manifest
To configure per-route load balancing for an application that has not yet been pushed:
1. In the application manifest, include a `route` definition with an `options: loadbalancing` attribute set to `round-robin` or `least-connection`. For example:
```yaml
---
applications:
- name: MY-APP
routes:
- route: MY-HOST.EXAMPLE.COM
options:
loadbalancing: least-connection
```
Where `MY-APP` is the name of your app and `MY-HOST.EXAMPLE.COM` is the route you want to map to your app.
1. Push the app with the manifest:
```console
cf push -f manifest.yml
```
### <a id="lb-create-route"></a> Create a Route with a Specific Load Balancing Algorithm Using the CF CLI
To create a route with a per-route `loadbalancing` option, you can use the CLI command `create-route`.
For example:
```console
cf create-route EXAMPLE.COM --hostname MY-HOST --option loadbalancing=round-robin
```
### <a id="lb-map-route"></a> Map a Route to an Existing App with a Specific Load Balancing Algorithm Using the CF CLI
To create and map a new route to an existing application with the per-route `loadbalancing` option, you can use the CLI command `map-route`.
For example:
```console
cf map-route MY-APP EXAMPLE.COM --hostname MY-HOST --option loadbalancing=round-robin
```
<p class="note">
The command <code>map-route</code> supports the <code>--option</code> flag only for new routes.
To update an existing route, use the command <code>update-route</code> described below.</p>
### <a id="lb-update-route"></a> Update the Load Balancing Algorithm of an Existing Route Using the CF CLI
To change the per-route `loadbalancing` option of an existing route, you can use the CLI command `update-route`.
For example, to change an app route's algorithm from `least-connection` to `round-robin`, you can run the `update-route` command:
```console
cf update-route EXAMPLE.COM --hostname MY-HOST --option loadbalancing=round-robin
```
### <a id="lb-remove-route-option"></a> Remove the Specific Load Balancing Algorithm Using the CF CLI
To remove the `loadbalancing` option from an existing route, run:
```console
cf update-route EXAMPLE.COM --hostname MY-HOST -r loadbalancing
```
## <a id="hash-based-routing"></a> Configure Hash-Based Routing
<%= vars.hash_routing_version %>
Hash-Based Routing is a load-balancing method that routes incoming requests to application instances based on a specific HTTP header value. This ensures consistent routing, so requests with the same header value are always routed to the same instance.
For details on Hash-Based Routing concepts, features, and how it compares to Session Affinity, see [Hash-Based Routing](hash-based-routing.html).
For instructions on configuring hash-based routing using the app manifest or the CF CLI, see [Configure Hash-Based Routing](hash-based-routing.html#configure).
## <a id="lb-retrieve-route-options"></a> Retrieve Route Options
To view route options, you can query the route using the `route` command:
```console
cf route EXAMPLE.COM --hostname MY-HOST
```
The response lists the chosen `loadbalancing` algorithm option, e.g. `least-connection`:
```console
options: {loadbalancing=least-connection}
```
Or `hash` with its related options:
```console
options: {hash_balance=1.2, hash_header=HASH-HEADER-NAME, loadbalancing=hash}
```