Setting the session pool size

Note

The article is being updated.

The client’s session pool size affects resource consumption (RAM, CPU) on the server side of YDB.
Simple math: if 1000 clients of the same DB have 1000 sessions each, 100000 actors (workers, session performers) are created on the server side. If you don’t limit the number of sessions on the client, this may result in a slow cluster that is close to a failure.
By default, the YDB SDK limits the number of sessions to 50.
A good recommendation is to set the limit on the number of client sessions to the minimum required for the normal operation of the client app. Keep in mind that sessions are single-threaded both on the server and client side. So if the application needs to make 1000 simultaneous (inflight) requests to YDB for its estimated load, the limit should be set to 1000 sessions.
Here it’s necessary to distinguish between the estimated RPS (requests per second) and inflight. In the first case, this is the total number of requests to YDB completed within 1 second. For example, if RPS\=10000 and the average latency is 100ms, it’s sufficient to set the session limit to 1000. This means that each session will perform an average of 10 consecutive requests for the estimated second.

Below are examples of the code for setting the session pool limit in different YDB SDKs

Go

Java

  1. package main
  2. import (
  3. "context"
  4. "github.com/ydb-platform/ydb-go-sdk/v3"
  5. )
  6. func main() {
  7. db, err := ydb.Open(
  8. ctx,
  9. os.Getenv("YDB_CONNECTION_STRING"),
  10. ydb.WithSessionPoolSizeLimit(500),
  11. )
  12. if err != nil {
  13. panic(err)
  14. }
  15. defer func() {
  16. _ = db.Close(ctx)
  17. }()
  18. }

Setting the session pool size - 图1

  1. this.tableClient = TableClient.newClient(rpc)
  2. // 10 - minimum number of active sessions to keep in the pool during the cleanup
  3. // 500 - maximum number of sessions in the pool
  4. .sessionPoolSize(10, 500)
  5. .build();

Setting the session pool size - 图2