Dubbo and Spring Cloud Architecture Technology Route Pairs in Microservices

Microservice architecture is a hot topic on the Internet and an inevitable result of the development of Internet technology. It advocates dividing a single application into a set of small services that coordinate and cooperate with each other to provide users with ultimate value. Although there are no recognized technical standards, specifications or drafts for microservice architecture, there are already some influential open source microservice architecture frameworks in the industry that provide key ideas for microservices, such as Dubbo and Spring Cloud. Major Internet companies also have self-developed microservice frameworks, but their models are not much different from the two.

The main advantages of microservices are as follows:

1. Reduce complexity

Splitting the complex business that was originally coupled together into a single service avoids the endless accumulation of original complexity. Each microservice focuses on a single function and clearly expresses service boundaries through well-defined interfaces. Each service developer only focuses on the service itself, and improves the performance of the system by using various technical means such as caching and DAL, and is completely transparent to the consumer.

2. Can be deployed independently

Since microservices have independent running processes, each microservice can be deployed independently. When the business is iterated, only the iteration of related services needs to be released, which reduces the workload of testing and reduces the risk of service release.

3. Fault tolerance

In a microservices architecture, when a component fails, the failure is isolated in a single service. Reduce the harm caused by errors through current limiting, fusing and other methods to ensure the normal operation of core business.

4. Expansion

Monolithic architecture applications can also achieve horizontal expansion, that is, the entire application is completely copied to different nodes. When different components of the application have different scaling requirements, the microservices architecture demonstrates its flexibility, because each service can be scaled independently according to actual needs.

This article mainly focuses on the technical selection, communication protocol, service dependency mode, start mode, and operation mode of microservices to comprehensively compare the two development frameworks of Dubbo and Spring Cloud. The architect can choose a suitable microservice architecture platform according to the company's technical strength and the characteristics of the project, so as to steadily implement the microservice transformation or development process of the project.

1. Core components

The core elements of microservices are service discovery, registration, routing, circuit breaker, downgrade, and distributed configuration. Based on the above several necessary conditions, Dubbo and Spring Cloud are compared.

1. Overall structure

Dubbo core components (as shown below):

Provider: The provider of the exposed service, which can start the service through jar or container

Consumer: The service consumer that invokes the remote service.

Registry: Service registry and discovery center.

Monitor: Count the number of services and calls, and call the time monitoring center. (It can be displayed in the console page of dubbo, currently there is only a simple version)

Container: The container in which the service runs.

▲Dubbo overall architecture

The overall architecture of Spring Cloud is as follows

Service Provider: The provider that exposes the service.

Service Consumer: The service consumer that invokes the remote service.

EureKa Server: Service registry and service discovery center.

▲The overall architecture of Spring Cloud

Comments: From the perspective of the overall structure, the two models are similar, and both require service providers, registration centers, and service consumers.

2. Core elements of microservice architecture

Dubbo only implements service governance, while Spring Cloud sub-projects cover many components under the microservice architecture, and service governance is only one aspect of it. Dubbo provides a variety of Filters. For the "none" elements in the above, it can be improved by extending Filter.

E.g

1. Distributed configuration: You can use Taobao's diamond and Baidu's disconf to achieve distributed configuration management

2. Service tracking: You can use Jingdong's open source Hydra, or extend Filter to use Zippin for service tracking

3. Batch tasks: you can use Dangdang open source Elastic-Job, tbschedule

Comments: From the perspective of core elements, Spring Cloud is better. In the development process, as long as the sub-projects of Spring Cloud are integrated, the integration of various components can be successfully completed, while Dubbo needs to be customized and developed by implementing various Filters. The cost and technical difficulty are slightly higher.

2. Communication protocol

Based on the communication protocol level, compare the protocol types supported by the two frameworks and the operation efficiency;

(1), support agreement

1. Dubbo: Dubbo uses the RPC communication protocol and provides serialization methods as follows:

dubbo: The default protocol of Dubbo uses a single long connection and NIO asynchronous communication, which is suitable for small data volume and large concurrent service calls, and the number of service consumer machines is much larger than the number of service provider machines.

rmi: RMI protocol is implemented by JDK standard java.rmi.*, using blocking short connection and JDK standard serialization method

Hessian: The Hessian protocol is used to integrate Hessian services. The bottom layer of Hessian uses Http communication and Servlet to expose services. By default, Dubbo embeds Jetty as a server implementation.

http: Implemented using Spring's HttpInvoker

Webservice: CXF-based implementation of frontend-simple and transports-http

2. Spring Cloud: Spring Cloud uses the REST API of the HTTP protocol

(2), performance comparison

Using a Pojo object containing 10 properties and requesting 100,000 times, Dubbo and Spring Cloud have different thread counts, and the time-consuming (ms) per request is as follows:

Note: Both the client and server configurations use Alibaba Cloud's ECS server, 4-core 8G configuration, and dubbo uses the default dubbo protocol

Comments: dubbo supports various communication protocols, and the consumer and the server use long links to interact. The communication speed is slightly better than that of Spring Cloud. If there are strict requirements for the response time of the system, long links are more suitable.

3. Service Dependence Mode

Dubbo: The service provider and the consumer depend on the interface. The service call is designed as follows:

interface layer: the service interface layer, which defines all the interfaces provided by the service to the outside world

Molel layer: DTO object layer of the service,

business layer: business implementation layer, implements interface interface and interacts with DB

Therefore, it is necessary to define its own interface for each microservice and publish it to the private repository through continuous integration. The caller application has a strong dependency on the abstract interface provided by the microservice, and the development, testing, and integration environments require strict management. version dependent.

The interface and model layers are published to the warehouse through maven's install & deploy commands, and the service caller only needs to rely on the interface and model layers. Only release Snapshot versions during development and debugging. Wait until the service debugging is completed before releasing the Release version, and distinguish the version of each iteration by the version number. You can access dubbo through xml configuration without intrusion to the program.

clipboard.png

▲Dubbo interface dependency method

Spring Cloud: The service provider and the service consumer interact through json, so only the relevant json fields need to be defined, and the consumer and the provider have no interface dependencies. The service configuration is realized by the annotation method, which has a certain intrusion to the program.

clipboard.png

Comments: Dubbo service is a little more dependent and needs a perfect version management mechanism, but less program intrusion. Spring Cloud, on the other hand, omits the issue of version management through Json interaction, but the meaning of specific fields needs to be managed uniformly, and its own Rest API interaction lays the foundation for cross-platform calls.

Fourth, the component operation process

Each component in the figure below needs to be deployed on a separate server. The gateway is used to accept front-end requests, aggregate services, and call background atomic services in batches. Each service layer interacts with a separate DB.

clipboard.png

▲Dubbo component operation process

gateWay: front gateway, specific business operations, gateWay automatically completes the load balancing mechanism provided by dubbo

Service: atomic service, which only provides atomic services related to the business

Zookeeper: Atomic service is registered on zk

clipboard.png

Spring Cloud components run

Spring Cloud

All requests go through the API Gateway (Zuul) to access internal services.

After the gateway receives the request, it obtains the available services from the registry (Eureka).

After the load is balanced by Ribbon, it is distributed to the specific instances of the backend.

Microservices communicate with each other through Feign to process business.

Comments: The business deployment method is the same, and a gateway is required to isolate the risk of directly calling the atomic service from the outside. Dubbo needs to develop its own set of API gateway, and Spring Cloud can complete gateway customization through Zuul configuration. Spring Cloud is slightly better in terms of usage.

5. Microservice Architecture Composition and Precautions

It doesn't really matter whether you use dubbo or Spring Cloud, the focus is on how to use microservices reasonably. The following is a general architecture diagram of the Internet, in which each link is the core part of microservices.

clipboard.png

(1), structure decomposition

Gateway cluster: data aggregation, identity authentication for access clients, anti-message replay and anti-data tampering, service authentication for function calls, desensitization of response data, traffic and concurrency control, etc.

Business cluster: In general, the gateways for mobile access and browser access need to be isolated to prevent business coupling

Local Cache: Since the client may need to call multiple service aggregations to access the business, the local cache effectively reduces the frequency of service calls and also prompts the access speed. The local cache generally uses the automatic expiration method, and a certain data delay is allowed in business scenarios.

Service layer: Atomic service layer, which implements basic addition, deletion, modification and query functions. If you need to rely on other services, you need to actively call in the Service layer

Remote Cache: Access the DB in front of a layer of distributed cache, reduce the number of DB interactions, and improve the TPS of the system

DAL: Data access layer. If the amount of data in a single table is too large, the data needs to be sub-database sub-table processing through the DAL layer.

MQ: Message queues are used to decouple the dependencies between services, and asynchronous calls can be performed through MQ

Database master-slave: the final stage in the service process, used to improve the TPS of the system

(2) Matters needing attention

The service startup method is recommended to use the jar method to start, the startup speed is fast, and it is easier to monitor

Cache, cache, cache, use cache as much as possible in the system where cache can be used, and rational use of cache can effectively improve the TPS of the system

Service splitting should be reasonable, and try to avoid service cyclic dependencies caused by service splitting

Set the thread pool reasonably to avoid system abnormality caused by setting too large or too small

If you want to learn Java performance optimization, engineering, high performance and distributed, simple language. Friends of microservices, Spring, MyBatis, and Netty source code analysis can add 575745314. In the group, there are Ali Daniel's live broadcast technology and Java large-scale Internet technology videos to share with you for free.

6. Summary

Dubbo was born in the Alibaba department. It is the core framework of Alibaba's service-oriented governance and is widely used in various Internet companies in China. It only needs to be configured through spring to complete the service, and there is no intrusion into the application. The purpose of the design is to serve its own business. Although Dubbo once suspended the maintenance version for internal reasons, the maturity of the framework itself and the completeness of the documentation can fully meet the business needs of major Internet companies. If we need to use the configuration center and distributed tracing, we need to integrate these contents by ourselves, which invisibly increases the difficulty of using Dubbo.

Spring Cloud is a product of the well-known Spring family, focusing on the research and development of enterprise-level open source frameworks. Since its development, Spring Cloud is still developing at a high speed. Almost all aspects of service governance are considered, and it is very convenient and simple to develop.

Dubbo restarted maintenance in 2017 and released the updated version 2.5.6, while Spring Cloud has been updated very quickly and has now been updated to Finchley.M2. Therefore, enterprises need to choose an appropriate architecture to solve business problems according to their own R&D level and stage. Both Dubbo and Spring Cloud are effective tools for implementing microservices.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324896868&siteId=291194637