github.com/anycable/anycable-go@v1.5.1/etc/dns/README.md (about) 1 # DNS load balancing playground 2 3 To play with the gRPC DNS load balancing feature, you need to run multiple RPC servers on different network interfaces and a DNS server. 4 5 ## Running multiple RPC servers 6 7 On MacOS, you can add aliases for the loopback interface as follows: 8 9 ```sh 10 sudo ifconfig lo0 alias 127.0.0.2 11 sudo ifconfig lo0 alias 127.0.0.3 12 sudo ifconfig lo0 alias 127.0.0.4 13 ``` 14 15 Now you can run an RPC server bound to one of the aliases: 16 17 ```sh 18 ANYCABLE_RPC_HOST=127.0.0.2:50051 bundle exec anycable 19 ANYCABLE_RPC_HOST=127.0.0.3:50051 bundle exec anycable 20 21 # or 22 ANYCABLE_RPC_HOST=127.0.0.2:50051 anyt --only-rpc 23 ANYCABLE_RPC_HOST=127.0.0.3:50051 anyt --only-rpc 24 25 26 # the same for other addresses 27 ``` 28 29 ## Running a DNS server 30 31 We use [async-dns](https://github.com/socketry/async-dns) to implement a simple DNS server resolving `anycable-rpc.local` to currently running RPC server' IPs: 32 33 ```sh 34 $ ruby server.rb 35 36 0.0s info: Starting Async::DNS server (v1.3.0)... [ec=0x5dc] [pid=21146] [2023-02-21 10:08:53 -0500] 37 0.0s info: <> Listening for datagrams on #<Addrinfo: 127.0.0.1:2346 UDP> [ec=0x5f0] [pid=21146] [2023-02-21 10:08:53 -0500] 38 0.0s info: <> Listening for connections on #<Addrinfo: 127.0.0.1:2346 TCP> [ec=0x604] [pid=21146] [2023-02-21 10:08:53 -0500] 39 ``` 40 41 ## Running anycable-go 42 43 Now you need to run anycable-go with the following RPC host configuration: 44 45 ```sh 46 ANYCABLE_RPC_HOST=dns://127.0.0.1:2346/anycable-rpc.local:50051 anycable-go 47 48 # or 49 ANYCABLE_RPC_HOST=dns://127.0.0.1:2346/anycable-rpc.local:50051 make run 50 ``` 51 52 You should see the logs of connecting to multiple RPC servers: 53 54 ```sh 55 INFO 2023-02-21T15:14:04.472Z context=main Starting AnyCable 1.2.3-aec3660 56 # ... 57 DEBUG 2023-02-21T15:14:04.682Z context=grpc connected to 127.0.0.2:50051 58 DEBUG 2023-02-21T15:14:04.682Z context=grpc connected to 127.0.0.1:50051 59 # ... 60 ```