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

3. import (
4. "context"
5. "os"

7. "github.com/ydb-platform/ydb-go-sdk/v3"
8. "github.com/ydb-platform/ydb-go-sdk/v3/balancers"
9. )

11. func main() {
12. ctx, cancel := context.WithCancel(context.Background())
13. defer cancel()
14. db, err := ydb.Open(
15. ctx,
16. os.Getenv("YDB_CONNECTION_STRING"),
17. ydb.WithBalancer(
18. balancers.RandomChoice(),
19. ),
20. )
21. if err != nil {
22. panic(err)
23. }
24. defer func() {
25. _ = db.Close(ctx)
26. }()
27. }

Random choice - 图1