How to connect a golang client to multiple alpha servers


(John Goodall) #1

What is the correct way to connect a single go client to multiple alpha instances? In the go documentation, it says: “You can connect to multiple Dgraph alphas to distribute the workload evenly.”, but there is no example of how to properly do that. There are a couple of other threads that raise this issue, but no actual code snippets. I assume you need to create a separate grpc connection and api client, and then pass those to the dgo client, but I can’t seem to get it working as expected. Can someone post a snippet of how they are doing this?}


(Daniel Mai) #2

The Dgraph Live Loader can connect to multiple Alpha instances using dgo. You can take a look at how it does that:


(John Goodall) #3

That is a big help, thanks!

For anyone looking in the future, note that x.SetupConnection uses grpc.WithTimeout(10*time.Second)), which looks to be deprecated, so instead use DialContext.


(John Goodall) #4

Will that approach, using multiple grpc connections for one client, round robin the mutations? We are seeing one node in a three node alpha cluster with way higher utilization.
Thanks


(Daniel Mai) #5

If you provide multiple Alpha addresses to dgo, then one will be picked randomly per transaction.