- 
                Notifications
    
You must be signed in to change notification settings  - Fork 22
 
Description
In YDB, request balancing is handled by the client - the server provides a list of nodes in the cluster, and the SDK distributes the load among them.
The C++ SDK implements 2 balancing policies:
- UseAllNodes. All nodes are used uniformly
 - UsePreferableLocation. Nodes from a user-specified data center are used. If no live nodes remain in the required data center, all nodes in the cluster are used.
 
A special case of UsePreferableLocation is the PreferLocalDC mode, when no location is specified. In this case, the nearest data center is considered the preferred one. Currently, this mechanism only works in an internal environment - when each node knows which data center it is in, and the balancer sends requests to all data centers during the first connection and returns the fastest response - which is considered to be the local one.
If a user is not in an internal environment, this will not work. However, users still want to use PreferLocalDC to reduce latency. For this purpose, it is proposed to determine the nearest data center using TCP pings. The data center with the smallest RTT will be considered local.
As part of this task, we need to:
- Implement a new balancing policy
 - Write tests for it