Random choice

Note

The article is being updated.

The YDB SDK uses the random_choice algorithm by default.

Below are examples of the code for forced setting of the “random choice” balancing algorithm in different YDB SDKs

Go

  1. package main
  2. import (
  3. "context"
  4. "os"
  5. "github.com/ydb-platform/ydb-go-sdk/v3"
  6. "github.com/ydb-platform/ydb-go-sdk/v3/balancers"
  7. )
  8. func main() {
  9. ctx, cancel := context.WithCancel(context.Background())
  10. defer cancel()
  11. db, err := ydb.Open(
  12. ctx,
  13. os.Getenv("YDB_CONNECTION_STRING"),
  14. ydb.WithBalancer(
  15. balancers.RandomChoice(),
  16. ),
  17. )
  18. if err != nil {
  19. panic(err)
  20. }
  21. defer func() {
  22. _ = db.Close(ctx)
  23. }()
  24. }

Random choice - 图1