dubbo configure load balancing, clustered environment

Then dubbo as a project architecture, give consumer provide consumers with load balancing and clustering strategies with nginx,

But think the next, consumer more, but also a provider, is not it all finally fell on top of this provider?

For Liezi:

  A hotel has a Houchu in cooking,

  There are 100 la carte reception staff,

  100 customers to ordering, the waiter came to tell each Houchu cook, then Houchu ...

 


Dubbo load balancing, usually the provider's services to achieve our cluster management, that is, load balancing, and consumer services at the time of the request of the consumer, by addressing certain algorithm (weights), reference may be under Nginx

 

Dubbo provides four load balancing strategy

  Random Random LoadBalance size arranged according to their weights, random

  Polling RoundRobin LoadBalance example: abc a b executing the perform then c, then to A ...   

  Minimum number of active calls (weight) LeastActive LoadBalance
    active call count number refers to the difference before and after the high priority call, the same random number is active. So that less slow provider receives a request, because the greater the difference between before and after the call will be slower provider counts.

  Consistency Hash ConsistentHash LoadBalance
    same parameters are always sent to the same provider, if the provider hung up, it will be based on its virtual node, in equal shares to other service providers, will not cause a huge change

 

* Note : The default is random random (that is, do not configure load balancing strategy, the default is random)

Load Balancing configuration levels:

It can also be accurate to the configuration level each method to the service level

Service-level server configuration:

<dubbo:service interface="接口名" loadbalance="roundrobin"/>

Method-level server configuration:

<dubbo: service interface = "Interface name"> 
  <Dubbo: Method, name = "method name" loadbalance = "balanced policy name" />
</ Dubbo: Service>

Client service-level configuration:

<dubbo:reference interface="" loadbalance="roundrobin" />

Client method-level configuration:

<dubbo:reference interface="" loadbalance="roundrobin">
    <dubbo:method name="方法名" loadbalance="均衡策略明"/>
</dubbo:reference>

 

 

We can also be operated by a visual interface management platform

 

After you configure load balancing below, it is necessary to configure our cluster of dubbo

 


 

Dubbo cluster with

Specific approach is the service provider's configuration file is modified, the same configuration file inside the application name, dubbo will be considered in the same cluster.

Only you need to deploy multiple clusters:

  application the same name

<Dubbo: the Application name = "service name " />

  Protocol ports need to modify different

<Dubbo: Protocol name = " Dubbo " Port = " ports need to be modified, can not be repeated " />

 

The following is a case I configured services:

Requirements: Configuring a clustered environment, two service providers

 

provider01

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://code.alibabatech.com/schema/dubbo
        HTTP: // code.alibabatech.com/schema/dubbo/dubbo.xsd ">

 
    <-!   Configuration Application Name 
    Note: You need the same cluster name value in the case of the same cluster configuration
      -> 
    <Dubbo: the Application name = " Provider-Dubbo " /> 


    ! <-   configuration registry: 
        address: ip registries: port 
        Note: If the registration center and ZooKeeper cluster, the cluster would talk about all of the IP: PORT added to the property which - 
        protocol: Registry type
       -> 
    <Dubbo: Registry address = " 169.254.18.25:2181,169.254.18.25:2182,169.254.18.25:2183 " protocol = " ZooKeeper " /> 
    ! <- configuration protocol and port - > 
    <Dubbo:protocol name="Dubbo " Port = " 20880 " /> 
    <Dubbo: Protocol name = " the Hessian " Port = " 20 881 " /> 

    <-!   configuration register interface
         ref : reference implementation class, because we added @Service scanned for annotations in which implementation class
      -> 
    <Dubbo: Protocol-Service = " Dubbo "  interface = " cn.arebirth.dubbo.service.UserDubboService "  REF = " userDubboServiceImpl " loadbalance = "of the RoundRobin" />
<Dubbo:service protocol="hessian" interface="cn.arebirth.dubbo.service.CarDubboService" ref="carDubboServiceImpl" loadbalance="roundrobin"/>
</beans>

After the service configuration, packaged and released to the server running, we will find such content on dubbo-admin console

 

 

provider02

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans.xsd
        http://code.alibabatech.com/schema/dubbo
        HTTP: // code.alibabatech.com/schema/dubbo/dubbo.xsd ">

 
    <-!   Configuration Application Name 
    Note: You need the same cluster name value in the case of the same cluster configuration
      -> 
    <Dubbo: the Application name = " Provider-Dubbo " /> 


    ! <-   configuration registry: 
        address: ip registries: port 
        Note: If the registration center and ZooKeeper cluster, the cluster would talk about all of the IP: PORT added to the property which - 
        protocol: Registry type
       -> 
    <Dubbo: Registry address = " 169.254.18.25:2181,169.254.18.25:2182,169.254.18.25:2183 " protocol = " ZooKeeper " /> 
    ! <- configuration protocol and port - > 
    <Dubbo:protocol name="Dubbo " Port = " 20 881 " /> 
    <Dubbo: Protocol name = " the Hessian " Port = " 20991 " /> 

    <-!   configuration register interface
         ref : reference implementation class, because we added @Service scanned for annotations in which implementation class
      -> 
    <Dubbo: Protocol-Service = " Dubbo "  interface = " cn.arebirth.dubbo.service.UserDubboService "  REF = " userDubboServiceImpl " loadbalance = "of the RoundRobin" />
<Dubbo:service protocol="hessian" interface="cn.arebirth.dubbo.service.CarDubboService" ref="carDubboServiceImpl" loadbalance="roundrobin"/>
</beans>

We put provider02 packaged and released to run on the server, we will see our services have been successfully completed registration,

At this also means that the cluster set up is completed

 

 

 

We carefully observe the top of the configuration file is not difficult to find, in fact, a different port, the rest are the same,

 

ps:

  Build a clustered environment Note:

    The same cluster environment must match the application name

    Port must be different

 

 

Guess you like

Origin www.cnblogs.com/arebirth/p/dubboloadbalancecluster.html