Distributed system

Distributed system is by a group of communication through the network, in order to complete the common task and coordinate work into the computer node system. The emergence of distributed systems is to use cheap, ordinary machines to complete computing, storage tasks that a single computer can not complete. The purpose is to use more machines to process more data. A distributed system is a software system built on a network. First of all to be clear, only the processing capacity of a single node cannot meet the increasing computation, storage tasks, and the ascension of the hardware (add memory, disk, using better CPU) high to do more harm than good, the application cannot be further optimized, we just need to consider a distributed system, Because the distributed system needs to solve the same problems as the stand-alone system, and because the distributed system has multiple nodes and communicates through the network, many problems that the stand-alone system does not have will be introduced. In order to solve these problems, more mechanisms and protocols will be introduced, bringing more problems

Dubbo document

With the development of the Internet, the scale of web applications continues to expand, and the conventional vertical application architecture has been unable to cope with it. Distributed service architecture and mobile computing architecture are becoming inevitable, and a governance system is urgently needed to ensure the orderly evolution of the architecture

Single application Architecture

A data access framework (ORM) for simplifying the workload of adding, deleting, and updating a website is critical when only one application is needed and all functions are deployed together to reduce deployment nodes and costsSuitable for small websites, small management systems, all functions are deployed into one function, easy to use

disadvantages

1, performance expansion is difficult 2, collaborative development problem 3, not conducive to upgrade and maintenance

Vertical application Architecture

As the number of visits increases, the acceleration caused by the addition of a single application becomes less and less, and the application is split into several unrelated applications to improve efficiency, the WEB framework (MVC) for accelerating front-end page development is the key

Mobile Computing Architecture

When there are more and more services, problems such as capacity evaluation and waste of small services gradually emerge. In this case, a scheduling center is added to manage cluster capacity in real time based on access pressure and improve cluster utilization. In this case, the resource scheduling and governance center is the key to improve machine utilization RPC

RPC stands for remote scheduling. It is a form of interprocess communication. It is a technical idea, not a specification, that allows a program to call a procedure or function in another address space (usually on another machine on a shared network). Instead of the programmer explicitly coding the details of this remote call that whether the programmer is calling a local function or a remote function, essentially writing the code that calls the local function or the remote function, essentially writing the code that calls it

In other words, two servers, A and B, have one application deployed on server A. If they want to call the function/method provided by the application on server B, they cannot call directly because they do not have A memory space. Therefore, they need to express the call semantics and convey the call data over the network. Why use RPC? It is the requirement that cannot be completed in a process, or even in a computer through local call, such as communication between different systems, or even communication between different organizations. Due to the horizontal expansion of computing power, applications need to be deployed in a cluster composed of multiple machines. RPC calls remote functions as if they were local;

Dubbo concept

What is the dubbo? Apache Dubbo I dAbeu | is a high-performance, lightweight open source Java RPC framework, it provides three core ability: remote method call to an interface, intelligent fault tolerance and load balancing, and automatic registration and discovery of services.

Windows installation zookeeper

The sh suffix is Linux Now open will not report the error!Opening the server generates an error, just like modifying configuration variables on LinuxOpen the client

A simple test and our ZooKeeper is installed!

A brief introduction to Dubbo

Provider: A service Provider that exposes a service. At startup, the service Provider registers its services with the registry. Service Consumer: the service Consumer who invokes the remote service. When the service Consumer starts up, he subscribes to the registry for the service he needs. The service Consumer selects one provider from the provider address list and invokes it based on the soft load balancing algorithm. Registry: The registry returns the list of service provider addresses to the consumer. If there is a change, the registry will push the change data to the Consumer Monitoring Center (Monitor) based on the long connection: service consumers and providers are called in memory for a cumulative number of times and call time, and regularly send statistics to the monitoring center once a minute

Call Relationship Description

The service container is responsible for starting, loading, and running the service provider. At startup, service providers register their services with the registry. At startup, service consumers subscribe to the registry for the services they need.

The registry returns a list of service provider addresses to the consumer, and if there are changes, the registry pays to push change data to the consumer based on long connection changes. The service consumer, from the provider address list, based on the soft load balancing algorithm, selects the provider to make the call, if the call fails, then selects another call. Service consumers and providers accumulate calls and call times in memory and regularly send statistics to the monitoring center every minute.

Install Dubbo and you can see who’s consuming what, so to speak, as a visual tool, right

The first stepMVN clean package -dmaven.test. skip=true After generating jar, open zooKeeper, double-click jar!!Access this port number, log in root, root can log inIn fact, the effect is equivalent to visualization!

Springboot integrates Dubbo and ZooKeeper

The first step

Step 2 Add the Springboot module

Structure of consumersA simple service

package com.jj.proviser.service;

public interface proviser {
// Returns a string method
    public String demo(a);
}

Copy the code

The implementation class

package com.jj.proviser.service;

import org.apache.dubbo.config.annotation.Service;
import org.springframework.stereotype.Component;

// Add a comment
@Component   // Use this universal annotation because dubbo's service annotation is the same as the original service annotation
@Service
public class proviserimpl implements proviser{
    @Override
    public String demo(a) {
        return "I'm Jiaojiao's first server!"; }}Copy the code

Yml server

Configure the port number
server.port=8081
The name of the service center
dubbo.application.name=proviser-server
Address of the registry
Dubbo. Registry. Address = zookeeper: / / 127.0.0.1:2181
# Those have to be registered
dubbo.scan.base-packages=com.jj.proviser.service

Copy the code

Rely on

<! - dubbo dependence - >
        <! -- https://mvnrepository.com/artifact/org.apache.dubbo/dubbo-spring-boot-starter -->
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
            <version>2.7.6</version>
        </dependency>
        <! -- ZooKeeper client dependencies -->
        <! -- https://mvnrepository.com/artifact/com.github.sgroschupf/zkclient -->
        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
            <version>0.1</version>` `</dependency>
        <! -- Log conflicts -->
        <! -- Introducing zooKeeper -->
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-framework</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.curator</groupId>
            <artifactId>curator-recipes</artifactId>
            <version>2.12.0</version>
        </dependency>
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
            <version>3.4.14</version>
            <! Slf4j-log4j12 -->
            <exclusions>
                <exclusion>
                    <groupId>org.slf4j</groupId>
                    <artifactId>slf4j-log4j12</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
Copy the code

To start the project, see our own provider on Dubbo for details Configuration consumer

package com.jj.proviser.service;

import org.apache.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Service;

@Service
public class Comsumer {

// If you want to get a provider, you need to go to the registry
    @Reference // Reference POM coordinates can and can define interfaces with the same path
    proviser proviser;
    public void buy(a)
    {

        String demo = proviser.demo();
        System.out.println("I am Jiaojiao's first demo ="+ demo); }}Copy the code

yml

Configure the port number
server.port=8082
Where do consumers get what they need
dubbo.application.name=consumer
Address of the registry
Dubbo. Registry. Address = zookeeper: / / 127.0.0.1:2181

Copy the code

The test results