Do you know why Dubbo's performance is so strong? You will understand after reading it!

foreword

Why does Dubbo say he has high performance?

High performance starts from the underlying principles. Since it is an RPC framework, the main thing is remote procedure (method) invocation, so to improve performance, we must start from the two most critical and time-consuming aspects: serialization and network communication. .

Serialization: When we learn Java network development, we know that if local objects are to be transmitted on the network, they must implement the Serializable interface, that is, they must be serialized. We have many serialization schemes: xml, json, binary stream... Among them, the most efficient is the binary stream (because the computer is binary). However, Dubbo uses the most efficient binary.

Network communication: Unlike HTTP, which requires 7 steps (three handshakes and four waves), Dubbo adopts the Socket communication mechanism, which improves the communication efficiency in one step, and can establish long connections without repeated connections and directly transmit data

Other RPC frameworks

gRPC

Thrift

HSF

Dubbo's past and present

dubbo has been used as a framework internally by Alibaba.

In 2011, dubbo was hosted on GitHub (open source)

After the release of version 2.4.11 in November 2014, it was announced that it would stop updating. Since then, many companies have open sourced their own variants based on Dubbo (such as Dangdang's Dubbo X, Netease Koala's Dubbo K)

In 2017, SpringCloud was born. After feeling the pressure, Dubbo updated several versions in a row. In January 2018, Ali and Dangdang merged Dubbo and Dubbo X and released version 2.6. On New Year's Eve in 2018, Ali contributed Dubbo to the Apache Foundation. Can

2018 New Year's Eve to date, Apache maintains and updates Dubbo

  • Starting from the basics, the concept of RPC is explained in detail, and the important role of PRC in distributed applications.
  • Application entry foundation of Dubbo distributed service framework.
  • The idea of ​​​​transforming traditional applications to distributed and microservices.
  • Features of the Dubbo protocol.
  • Detailed development process of Dubbo distributed service, implementation and deployment of Dubbo service, service management of Zookeeper, etc.

dubbo overview

Apache Dubbo (incubating) |ˈdʌbəʊ| is a high-performance, lightweight open source Java RPC framework that provides three core capabilities: interface-oriented remote method invocation, intelligent fault tolerance and load balancing, and automatic service registration and discovery .

Dubbo is a distributed service framework dedicated to providing high-performance and transparent RPC remote service invocation solutions and service governance solutions.

characteristic:

Interface-oriented proxy: call the method of the interface, call the method of the B server on the A server, and the dubbo realizes the call to B, without caring about the details of the implementation, just like MyBatis accesses the Dao interface and can operate the database. Don't care about the implementation of Dao interface methods. This development is convenient and comfortable.

Basic Architecture

  • Service Provider (Provider): The service provider that exposes the service. When the service provider starts, it registers the service it provides with the registry.
  • Service consumer (Consumer): The service consumer that calls the remote service. When the service consumer starts, it subscribes to the registry for the service it needs. The service consumer selects the provider address list based on the soft load balancing algorithm. One provider makes the call, and if the call fails, another call is chosen.
  • Registry: The registry returns the service provider address list to the consumer. If there is a change, the registry will push the change data to the consumer based on the long connection
  • Monitoring Center (Monitor): Service consumers and providers, accumulate the number of calls and call time in memory, and regularly send statistical data to the monitoring center every minute

Description of the calling relationship:

  • The service container is responsible for starting, loading, and running the service provider.
  • When the service provider starts, it registers the service it provides with the registry.
  • When a service consumer is started, it subscribes to the registry for the services it needs.
  • The registry returns the service provider address list to the consumer. If there is a change, the registry will push the change data to the consumer based on the persistent connection.
  • The service consumer, from the provider address list, selects a provider to call based on the soft load balancing algorithm, and if the call fails, selects another provider to call.
  • Service consumers and providers accumulate the number of calls and call times in memory, and regularly send statistical data to the monitoring center every minute.

Protocols supported by Dubbo

Support multiple protocols: dubbo , hessian , rmi , http, webservice , thrift , memcached , redis. Dubbo officially recommends using the dubbo protocol. The default port of dubbo protocol is 20880

Using the dubbo protocol, the spring configuration file is added:

<dubbo:protocol name=“dubbo” port=“20880” />

E-commerce platform needs

According to the system requirements of an e-commerce platform, users browse products; select products to place an order, and the order system needs to obtain the delivery address in the user information; request the payment system to complete the payment.

direct connection dubbo

Peer-to-peer direct project: Consumers access service providers directly, without a registry. The consumer must specify the access address (url) of the service provider.

The consumer directly accesses the fixed service provider through the url address. This url address is unchanged.

Goals

User access------>【Commodity website service】Access----->【Order service】

Method to realize

Taking JavaSE as an example, service providers and service consumers are both JavaSE projects

(1) Create a service provider: order service

A. Create a new java project

Project name:
link-orderservice-provider

Set version to 1.0.0

B 、 maven pom.xml

Add the JDK1.8 compilation plugin to the label under

C. Create order entity class: Order

D. New order service interface: OrderService

E. The implementation class of the new interface: OrderServiceImpl

F. Create dubbo configuration file

orderservce-provider.xml

G. Test configuration file

H. Install the local jar to the maven repository

For the methods in the service interface to be used by consumers, the consumer project needs to know the interface name and the method names and parameters in the interface. These information service providers know. The class file of the interface needs to be packaged as a jar

The class files of the service interface project are packaged as jars, installed in the maven repository, and the provider jars in the repository can be used by consumers.

Execute install using IDEA's maven window

(2) Create service consumers: commodity website

I. Create a new java project

Project name: link-main-web

J 、 maven pom.xml

Add the JDK1.8 compilation plugin to the label under

K. Create a purchase interface

L. Create an implementation class for the purchase interface

M. Create dubbo configuration file

shop-consume.xml

N. Execute the consumer

Best Practices for Dubbo as a Service

subcontract

It is recommended to put the service interface, service model, service exception, etc. in the public package.

granularity

The service interface should be as granular as possible, and each service method should represent a function, not a step of a function. It is recommended to divide the service interface into units of business scenarios, and abstract similar services to prevent the explosion of the number of interfaces.

It is not recommended to use too abstract general interfaces, such as: Map query (Map), such interfaces do not have clear semantics, which will bring inconvenience to later maintenance.

Version

Each interface should define a version number to distinguish different implementations of the same interface, such as: <dubbo:service interface="com.xxx.XxxService" version="1.0" />.

Guess you like

Origin blog.csdn.net/m0_48795607/article/details/119580377