Dubbo
A brief introduction to Dubbo? (What is Dubbo?)
Dubbo is a service invocation.
Why do you say that?
Dubbo is an RPC distributed framework open-source by Ali
So what is RPC?
That is, different applications are deployed on different servers. Applications cannot be called directly because they are not in the same memory space. They need to be called through network communication or transfer the data to be called. And RPC hides the details of the remote call, making it as easy to call a remote service as it is to call a local service.
What components does Dubbo have?
Dotted purple lines: functions performed when Dubbo is started Blue and blue lines: functions performed while the program is running, dotted lines are asynchronous operations, solid lines are synchronous operations
Provider: Provider of a service. In the case of SOA development, this is the interface to the database, and the service is primarily on the producer side
Consumer: invokes the service provider. The front-end Controller is mainly on this side, where you can call methods in the producer remotely, and update the call list of the consumer in real time when the producer changes. See the following introduction for details
Container: Starts, loads, and runs the service provider. Dubbo container, which depends on the Spring container. The important thing to note here is that Dubbo relies on the Spring container. It must be used in conjunction with Spring
Registry: indicates the Registry. The list of all available services is registered with Registry when the Container starts. Function: Tell the Consumer what service is provided and where the service provider is located.
Monitor: Monitoring center: The monitoring center counts the invocation times and invocation time of each service
How does it work?
0. Start: At startup of Dubbo Provider, or start the container, and will create the corresponding directory structure, such as code of common interface called com. LearnDubbo. Demo. DemoService, Will create/dubbo/com. LearnDubbo. Demo. DemoService directory, and then create will directory, again in will directory into your URL address.
1.Register: After startup, the system will go to the registry to Register all available services. The subscription/dubbo/com. LearnDubbo. Demo. DemoService URL directory of all providers and consumers.
2.Subscribe: Consumer not only registers itself with… In the /consumers/ directory, also subscribes… /providers directory, which obtains the URL string information of the Provider on it in real time. When a service consumer startup: in dubbo/com. LearnDubbo. Demo. DemoService directory to create directory/consumers, and in/consumers into your URL address.
3. Notify: When the Provider changes, the registry will push the message to Consummer. That is, the registry will observe the Provider, in this case using the Observer mode in design pattern. For example, in the Zookeeper registry, Dubbo has the doSubscribe method in ZookeeperRegistry, which is a producer subscription and listener.
Invoke: Invoke the Provider function based on the Provider address obtained. This is the only way to synchronize, because the consumer needs to get the data from the producer to proceed, but Dubbo is an RPC framework, and the core of RPC is to know only the interface and not the internal implementation. Therefore, in the Consumer side, the proxy design mode is used to create a proxy object of the Provider side class and obtain the real functions of the Provider through the proxy object to protect the real functions of the Provider.
5. Monitor: The Consumer and Provider send statistics to the Monitor every minute, including access times and frequency
Why is Dubbo more efficient than SpringCould
First, what protocol does Dubbo support? Performance comparison of dubbo protocols:
Thrift protocol:
Thrift’s native protocol performs well, six times better than Dubbo’s native
Dubbo protocol:
Definition: The default protocol, the use of a single long connection and NIO asynchronous communication, the use of thread pools to process requests concurrently, can reduce handshakes and increase concurrency efficiency
Scope of application: the incoming and outgoing parameter packets are small (less than 100K is recommended), there are more consumers than providers, a single consumer cannot overwhelm providers, try not to use dubbo protocol to transfer large files or large strings. Application scenario: General remote service method invocation
Hession protocol: Definition: used to integrate Hessian services. Hessian uses Http communication at the bottom and Servlet to expose the service. The data packets of incoming and outgoing parameters are larger, the number of providers is larger than that of consumers, the pressure of providers is larger, and files can be transmitted. Application scenario: Page transfer, file transfer, or interoperate with the native Hessian service.
Various protocols trade-offs: www.cnblogs.com/barrywxx/p/…
Case tests:
It can be seen that the efficiency of Dubbo communication is higher than that of SpringCould, so why is it higher?
There are two ways to communicate between SpringCloud services
- RestTemplate way
- The way to Feign
Either way, it is an HTTP interface that invokes the service through the REST interface, with parameters and results being serialized and deserialized by Jackson by default.
In other words, SpringCould is an Http request.
Dubbo as we all know is RPC distributed framework, the default is based on dubbo custom binary protocol for transmission, the message body is relatively simple, transmission data is much smaller.
Case tests:
Conclusion: The efficiency of RPC request is about 1.6 times that of HTTP request, and the performance is much higher than that of HTTP request, because HTTP protocol contains a large number of request headers and response headers.
Zookeeper:
How does Zookeeper work? (Working principle)
Zookeeper maintains a hierarchical data structure similar to a standard file system. Each subdirectory entry in the file system is called a Znode node. This znode can also have children. Each node can store data and the client can perform getChildren, getData,exists methods on these nodes. You can also set the watch (similar to listening) on the ZNode Tree path. When a node create, delete, or update occurs on the watch path, the system notifies the client. After being notified, the client can obtain data and perform service logic operations. Zookeeper is used to maintain and monitor data status changes on storage nodes to implement data-based cluster management.
Why use ZooKeeper as the dubbo registry? Can I choose something else?
Zookeeper’s data model consists of a series of Znode data nodes, similar to a file system. All ZooKeeper data is stored in the memory, providing high performance. Zookeeper also supports clustering to achieve high availability. Based on the characteristics of ZooKeeper, it also supports event monitoring (when the exposed party of the service changes, it can push), so ZooKeeper is suitable for dubbo registry. Redis and Simple can also be used as registries for Dubbo.
What were the main things done with ZooKeeper in the project? (role)
To serve as a registry; Zookeeper is mainly set up on the server, and then configured in the spring-managed Dubbo configuration file (both exposed and consumer need to configure).