Load Balancer quickstart
Enable Load Balancer on a connector, add a second address with a weight, and take one address out of rotation.
This guide instructs you through spreading the requests of your first connector across two origin servers with Load Balancer.
- Enable Load Balancer on the connector, and add a second address with a weight for each address.
- Send repeated requests through your workload and see answers from both servers.
- Take one address out of rotation, and see every request reach the other one.
Four parts make the chain, listed in the order this guide uses them:
- The connector from the Connectors quickstart gets Load Balancer and the Round Robin method.
- The addresses of the connector become two:
httpbin.org, with a weight of2, andhttpbingo.org, with a weight of1. - The rule that sends every request under
/anythingto the connector stays as it is. - The workload that serves your application receives the requests. Its deployment needs no change.
Both servers are public services that answer a request for /anything/get with a JSON copy of that request. Each one identifies itself in the server response header, so the response shows which address answered. To use your own servers, replace both hostnames with servers that hold the same content.
The prerequisites and the three stages show the steps of one interface at a time. Select yours:
Prerequisites
- The result of the Connectors quickstart: the connector
my-connector, and a rule that sends every request under/anythingto it. - The workload domain of the workload that serves the application, of the form
<id>.map.azionedge.net. This guide writes it as<workload-domain>. curl, to send the requests to the workload domain.
- Access to Azion Console.
Enable Load Balancer and add an address
A connector holds one address until Load Balancer is on. With Load Balancer on, it holds up to 15 addresses, and a balancing method chooses one for each request. Round Robin takes the addresses in turn. For the bounds, refer to Connectors limits.
Each address carries a weight from 1 to 100, and a higher weight allocates more traffic to that address. The weight shapes the share of requests, not an exact split. Each address also carries a server role. Both addresses in this guide are Primary. A Backup address receives requests only when every primary address fails, and the IP Hash method refuses it. For more information, refer to Server role.
Every address of a connector receives the same Host header and the same transport protocol. Two changes to the connection options make one setting work for both servers:
- The
Hostheader becomes${host}, the host the client requested, instead ofhttpbin.org. A fixedhttpbin.orgwould sendhttpbingo.orgaHostheader that names a different server. - The connector reaches both servers over HTTP. Over HTTPS,
httpbingo.orgaccepts only connections for its own name.
To enable Load Balancer with the Azion CLI, put the whole connector in a JSON file. The update command needs the full body, with every field the connector keeps. Save this body as connector.json:
modules.load_balancer on each address holds its role and weight. modules.load_balancer under attributes turns Load Balancer on, and config must carry at least one key.
Update the connector from the file. Replace <connector-id> with the ID of your connector. The command needs --type even though the file names the type:
The output confirms the update:
The connector has Load Balancer on and two active addresses. The settings that config leaves out take the API defaults: max_retries 0, connection_timeout 60, and read_write_timeout 120.
Confirm both addresses answer
The check is the same whichever interface changed the connector. In the commands, replace <workload-domain> with the workload domain of your workload.
A connector change takes several minutes to reach Azion’s distributed infrastructure, and data centers apply it at different times. Until then, some requests still reach httpbin.org alone, and some can return a 502 error page. Repeat the requests until both servers answer. For more information, refer to Propagation.
Send a request for a path under /anything, and print the response headers with the body:
Send the same request several times. An answer from httpbin.org carries this server header:
An answer from httpbingo.org carries this one:
Both servers answer for the same path, so the connector spreads requests across both addresses.
The answers come in no fixed order. Each data center balances on its own, so a run of requests can favor one address, and the share varies from run to run. For more information, refer to Load Balancer.
Take an address out of rotation
An address with Active off stays on the connector and receives no requests. Use it to take a server out before maintenance, without deleting the address. This stage takes httpbingo.org out.
To take the address out with the Azion CLI, edit the connector.json you saved. Add "active": false to the httpbingo.org address:
Update the connector from the file:
The output confirms the update:
The address httpbingo.org is inactive, and it keeps its role and weight.
The change reaches data centers at different times, as when you added the address. For several minutes, some requests still reach httpbingo.org. Send this request several times:
Once every data center holds the change, every answer carries the httpbin.org header:
No answer carries the Fly header. The connector sends every request to the active address, and httpbingo.org stays on the connector with its role and weight.