Selector

    How do clients select a node to invoke? You can use a selector to do this and it is just like a load balancing with routing algorithm.

    rpcx supports multiple selectors and you can set it when you create XClient.

    Example:random

    This selector will pick a node randomly.

    Roundrobin

    Example:roundrobin

    select the node in a round-robin fashion.

    Example:

    use the smooth weighted round-robin balancing, implemented the same algorithm in Nginx.

    Algorithm is as follows: on each peer selection we increase current_weightof each eligible peer by its weight, select peer with greatest current_weightand reduce its current_weight by total number of weight points distributedamong peers.

    WeightedICMP

    Example:ping

    use the result of ping (ICMP) to set weight of each node. The shorter ping time, the higher weight of the node.

    assume is cost time of ping:

    • weight=191 if t <= 10
    • weight=201 -t if 10 < t <=200
    • weight=0 if t >= 1000

    Example:

    Use JumpConsistentHash to router the same node for the same servicePath, serviceMethod and arguments. It is a fast consistent hash algorithm.

    If nodes have changed, the algorithm will re-calculate consistent hash.

    Geography

    Example:geo

    Services must set the geo location in their metadata.

    If they are multiple closest services, select one randomly.

    You should use the below method set geo location of clients and it will change selector to Geo selector.

    Example:

    If the above selectors are not suitable for you, you can develop a customized selector.

    The selector is an interface:

    1. type Selector interface {
    2. UpdateServer(servers map[string]string)

    -Select: defines the select algorithm.-: clients init the nodes and update if nodes change.

    By smallnest updated 2018-12-04 11:47:26