Dubbox and micro service

Dubbox and microservices

< /p>

What role does zookeeper play in Dubbo and what role does it play?

Now the overall structure is as follows (assuming that the service consumer serves the order and the service provider serves the user):

share picture

What’s the problem with this?

  1. When the service provider adds nodes, the configuration file needs to be modified

    li>

When one of the service providers is down, the service consumers cannot perceive it in time, and it will go down Service sending request

At this time, the registration center has to be introduced

< p>Registration Center

Dubbo currently supports 4 kinds of registration centers, (multicast zookeeper redis simple) Zookeeper registration center is recommended, this article will talk about using zookeeper to realize service registration and discovery (knocking on the blackboard, another use of zookeeper) , The general process is as follows

share picture

Now let’s look at the introduction to Dubbo on Dubbo’s official website. Does it look similar to the one we drew above?

Share pictures

Node role description

Share pictures

Description of Calling Relationship

  1. The service container is responsible for starting (the Spring container in the above example), loading, and running the service provider.
  2. When the service provider starts, it registers its services with the registration center.
  3. When service consumers start, they subscribe to the registration center for the services they need.
  4. The registration center returns a list of service provider addresses to consumers. If there are changes, the registration center will Connect and push change data to consumers.
  5. Service consumers, from the provider address list, based on the soft load balancing algorithm, choose one to provide If the call fails, choose another call.
  6. service consumers and providers, accumulate the number of calls and call time in the memory, and send it every minute at regular intervals Once statistical data is sent to the monitoring center.

?

To use the registry, you only need Change provider.xml and consumer.xml to the following

share picture

If zookeeper is a cluster, separate multiple addresses with commas

register How to store information in zookeeper?

After starting the above service, we observe that the root node of zookeeper has one more dubbo node and others, as shown in the figure As follows

share picture

The last node 192.168.1.104 is the intranet address. You can have the same effect as the localhost configured above. You can think about why I marked the last node in green. That’s right, the last node is a temporary node, and the other nodes are persistent nodes. In this way, when the service goes down, this node will automatically disappear, no longer provide services, and service consumers will no longer request them. If multiple DemoServices are deployed, there will be several nodes under the providers, and one node holds the service address of a DemoService.

In fact, a zookeeper cluster can be shared by multiple applications, such as Storm cluster and Dubbo configuration. Zookeeper cluster, why? Because different frameworks will build different nodes on zookeeper, they will not affect each other. For example, dubbo will create a /dubbo node, and storm will create a /storm node, as shown in the figure

share picture

?

If the same method call is provided by the Dubbox cluster, then a load balancing mechanism will need to be provided. (Note: Zookeeper itself does not have a load balancing function, but its feature (you can find out that those Dubbo servers are down through the heartbeat mechanism, thereby maintaining the callable list) can use other methods to achieve similar load balancing capabilities. For example, dubbo consumers have achieved After the server list, one of them will be called randomly. Commonly used load balancing implementations are as follows:

Round Robin

Each request is sent to each server in turn.

In the figure below, a total of 6 clients have generated 6 requests, and these 6 requests press (1,2,3,4,5, 6) Send in order. (1,3,5) requests will be sent to server 1, (2,4,6) requests will be sent to server 2.

share picture

This algorithm is more suitable for each server with similar performance If there is a difference in performance, the server with poor performance may not be able to bear the excessive load

share picture

weighted round-robin

weighted round-robin is in round Based on the query, according to the performance difference of the server, a weight is assigned to the server, and the server with high performance is assigned a higher weight. For example, in the following figure, server 1 is assigned a weight of 5, and server 2 is assigned The weight is 1, then (1,2,3,4,5) requests will be sent to server 1, (6) requests will be sent to server 2.

Share pictures

Minimal connections

Because the connection time of each request is different, using polling or weighted polling algorithms may cause the current number of connections to one server to be too large, and the connection to the other server to be too small, causing The load is unbalanced.

For example, in the figure below, (1, 3, 5) requests will be sent to server 1, but (1, 3) will be disconnected soon, and only (5) requests to connect to server 1 ;(2, 4,6) The request is sent to server 2, only the connection of (2) is disconnected, at this time (6, 4) requests to connect to server 2. When the system continues to run, server 2 will bear an excessive load.

Share pictures

< p>The least connection algorithm is to send the request to the server with the least number of connections currently.

For example, in the figure below, server 1 currently has the smallest number of connections, then the new incoming request 6 will be sent to server 1.

Share pictures

< p>Weighted least connections

On the basis of the least connections, weights are assigned to each server according to the performance of the server, and then the number of connections that each server can handle is calculated based on the weight

Random algorithm

Send the request randomly to the server

Similar to the polling algorithm, this algorithm is more suitable for the server with similar performance Scene

share picture

IP Hash (IP Hash)

The source address hash is obtained by calculating the hash value of the client IP and then modulating the number of servers The serial number of the target server.

It can be guaranteed that requests from clients of the same IP will be forwarded to the same server to implement conversationsSticky.

share picture< /p>

Leave a Comment

Your email address will not be published.