Dubbo+zookeeper build highly available distributed clusters

Source: Internet
Author: User

We discussed the cluster of Nginx+tomcat, which is already very flexible cluster technology, but when our system encountered a larger bottleneck, the full application of the single point server can not meet our needs, at this time, we have to consider another, we are familiar with the content is distributed, And the current popular Dubbo framework.

One, background


We used to call other people's interfaces remotely, and that's what we did:


The problems we encounter:

(1) When the service is more and more, the service URL configuration management becomes very difficult, the F5 hardware load Balancer's single point pressure is also more and more big.
A service registry, a dynamic registration and discovery service, is required to make the location of the service transparent.
and through the consumer to obtain the service provider address list, realizes the soft load equalization and the failover, reduces to F5 hardware load balancer the dependence, also may reduce the partial cost.
(2) When further development, the dependencies of the service become more complex, and even unclear which application to start before which application, the architect can not fully describe the application of the architectural relationship.
At this point, you need to automatically draw a dependency graph between applications to help the architect clean up the relationship.
(3) Then, the number of calls to the service more and more, the capacity of the service to expose the problem, the service needs a number of machine support. When to add the machine.
In order to solve these problems, the first step is to count the number of calls and response times of the service now daily, as a reference index for capacity planning.
Secondly, to be able to dynamically adjust the weight, online, the weight of a machine has been increased, and in the process of increasing the record response time changes, until the response time to reach the threshold, record the amount of traffic at this time, and then multiply the number of this traffic to the total capacity of the machine.

What did Dubbo do for us to solve these problems:




Load Balancing:


This is known as soft load balancing.



Now let's get in touch with this excellent framework:

Brief introduction

Architecture diagram:

Node role Description:

Provider: The service provider that exposes the service.

Consumer: Invokes the service consumer of the remote service.

Registry: Registration Center for service Registration and discovery.

Monitor: The monitoring center of the call time reconciliation call times for statistical services.

Container: Service Run container.


Call Relationship Description:

0. The service container is responsible for starting, loading, and running the service provider.

1. The service provider registers its own services with the registry at the time of commencement.

2. When starting, the service consumer subscribes to the registry for the services it needs.

3. The registry returns the service provider address list to the consumer, and if so, the registry will push the change data to the consumer based on the long connection.

4. Service consumers, from the provider address list, based on the soft load equalization algorithm, select a provider to invoke, if the call fails, then select another call.

5. Service consumers and providers, in the memory of the cumulative number of calls and call time, timed every minute to send statistical data to the monitoring center.



Dubbo provides a number of protocols, Dubbo Protocol, RMI Protocol, Hessian protocol, we look at the Dubbo source code, there are various protocol implementation, as shown in the figure:

We didn't use Dubbo before, most of them used Hessian to use the exposure and invocation of our service, using Hessianproxyfactory to invoke the remote interface.

The above is referred to the Dubbo official network introduction, Next we will introduce Springmvc, Dubbo, zookeeper integration use.


Third: Dubbo and Zookeeper, SPRINGMVC integrated use

The first step: Install Zookeeper on Linux

Zookeeper as the Dubbo Service Registry Center, Dubbo originally based on the Database Registry center, did not adopt the Zookeeper,zookeeper a distributed service framework, is the tree type directory service data storage, can do the cluster management data, Here can be very good as the Dubbo Service Registration Center, Dubbo can do with zookeeper cluster deployment, when the provider of abnormal downtime, such as power outages, zookeeper registry can automatically delete the provider information, when the provider restarts, can automatically restore registration data, as well as subscription requests. We first install the Zookeeper on Linux, we install the simplest single point, the cluster is more troublesome.

You need to install the JDK first, download from Oracle's Java Web site, and install it very simply, no longer detailed.

Stand-alone mode

A stand-alone installation is very simple, as long as you get the zookeeper package and extract to a directory such as: C:\zookeeper-3.4.5\, zookeeper startup script under the bin directory, Windows boot script is zkserver.cmd.

Before you execute the startup script, there are a few basic configuration items to configure, zookeeper configuration files in the Conf directory, this directory has zoo_sample.cfg and log4j.properties, you need to do is to Zoo_ SAMPLE.CFG is renamed Zoo.cfg because zookeeper will find this file as the default profile at startup. The following is a detailed description of the meaning of each configuration item in this configuration file.


[HTML]   View plain  copy <span style= "font-size:18px;" ># The number of milliseconds of each tick   ticktime=2000    # the number of ticks that the initial    #  synchronization phase can take   initlimit=10   # The number  of ticks that can pass between    # sending a request  and getting an acknowledgement  

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.