Client load balancing (Ribbon)

Client load to achieve

1, know their request destination (virtual host name, the default is spring.application.name)
2, get all the server address list (that is, the registry).
3, select an address, find the virtual host name corresponding ip, port (corresponding to the virtual host name to the ip and port).
4, initiating the actual request (the most simple request).

Ribbion principle

  1. Intercepts the request.
  2. Get url.
  3. List serviceName get through the url.
  4. By load balancing algorithm to select a ServiceInstance. ( Load pluggable custom algorithm, and may be customized via the configuration file or code )
  5. Alternatively the request, the original into the url serviceName ip + port.

Core ILoadBalance

Which includes all service providers clusters: ip and port. Each service has a ILoadBalancer, ILoadBalancer which has the list of services .

1, ILoadBalancer undertake eureka and ribbon. Access to services address list, select one.
2, each service has ILoadBalancer.
3, select the service with IRule (load balancing strategy).

Treatment of unwanted services:
two ways:
1. Update mechanism, the latest update of service.
2.ping mechanism, good service a try.

Load balancing strategy

Default: ZoneAvoidanceRule (Regional Balance Strategy)
BestAvailableRule (lowest concurrency strategy)
RoundRobinRule (polling
policy) . . .

Configuration hunger load

ribbon:
eager-load:
enabled: true
clients:
- SERVICE-NAM

to sum up

  1. Several load balancing. (Hard, soft (server, client (Ribbon)))
  2. Ribbon may be used alone. The need to provide services address list.
  3. principle. Intercepting the request, and the replacement address (the SERVICENAME ip + port).
  4. Source. ILoadBalancer, Map <service name, ILoadBalancer>
  5. @LoadBalanced, interceptor. (LoadBalancerInterceptor the intercept)
  6. Custom Configuration: java configuration, yml configuration.
  7. Custom load balancing strategy

Custom load configuration

1,java

//所有client走入该配置
@RibbonClients(defaultConfiguration = RibbonConfiguration.class)
//RibbonConfiguration中可使用ribbon提供负载,或自定义负载
//单个client走入该配置
@RibbonClient(name = "service-name",configuration = RibbonConfiguration.class)

2, YML

//不添加service-name为所有
service-name:
  ribbon:
    NFLoadBalancerRuleClassName: com.netflix.loadbalancer.RandomRule
//自定义策略
service-sms:
  ribbon:
    # 自定义负载策略
    NFLoadBalancerRuleClassName: com.mybalance.RaymondRule
Published 25 original articles · won praise 0 · Views 572

Guess you like

Origin blog.csdn.net/RaymondCoder/article/details/105214524