go-driver
go-driver copied to clipboard
Why only use the current server node each time in cluster.Do()?
conn, _ := http.NewConnection(http.ConnectionConfig{
Endpoints: []string{"endpoint_a", "endpoint_b", "endpoint_c"},
})
c, _ := driver.NewClient(driver.ClientConfig{
Connection: conn,
Authentication: driver.BasicAuthentication("user", "passwd"),
})
ctx := context.Background()
db, _ := c.Database(ctx, "mydatabase")
found, _ := db.CollectionExists(ctx, "mycollection")
As we can see the code above, i have three endpoints: endpoint_a, endpoint_b and endpoint_c. When the line "found, _ := db.CollectionExists(ctx, "mycollection")" is executed, it will call the function cluster.Do() in the file cluster/cluster.go, the main flow of cluster.Do() is as follows and the getNextServer() function return the server node saved by the current variable:
if s == nil {
s = c.getCurrentServer()
}
for {
// if success, return the resp as result
// Failed, try next server
attempt++
if specificServer != nil {
// A specific server was specified, no failover.
return nil, driver.WithStack(err)
}
if attempt > len(c.servers) {
// We've tried all servers. Giving up.
return nil, driver.WithStack(err)
}
s = c.getNextServer()
}
We only use the current server node(such as endpoint_a) and use the next one until the current has failed, if the endpoint_a is running success all the time, the other endpoints is idle. So, I want to know why not random pick a server node in the c.servers, or use a load balance method for these endpoints? I'm looking forward to your explanation for my puzzle. Thank you!
There are a few API calls which have to be made to the same server. These are mostly cursor related.
However that does not explain all. We have "load-balancing" behavior on our wishlist, but did not get to it yet.
@ewoutp Is Load Balancing feature available now?
@neunhoef Please answer this
Any update or movement on this issue?
In V2 we have added Load Balancing to the endpoints in the Client with two preconfigured implementations:
- Round-Robin https://github.com/arangodb/go-driver/blob/master/v2/examples/example_client_roundrobin_test.go
- Maglev: https://github.com/arangodb/go-driver/blob/master/v2/examples/example_client_maglev_test.go
Here is the PR which introduced that: https://github.com/arangodb/go-driver/pull/538/files