In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to call HTTP instead of RPC between services. Many people may not know much about it. In order to make you understand better, the editor has summarized the following for you. I hope you can get something from this article.
RPC (Remote Procedure Call)-remote procedure call, which is a protocol that requests services from remote computer programs over the network without knowing the underlying network technology.
What is RPC?
RPC (Remote Procedure Call)-remote procedure call, which is a protocol that requests services from remote computer programs over the network without knowing the underlying network technology. For example, if two different services An and B are deployed on two different machines, what if Service A wants to invoke a method in Service B? Using HTTP requests is fine, but it may be slow and some optimizations are not well done. The emergence of RPC is to solve this problem.
What is the principle of RPC?
Why not use HTTP instead of RPC for calls between services?
The service consumer (client) call invokes the service in a local invocation
After receiving the call, client stub is responsible for assembling methods, parameters, etc., into a message body that can be transmitted over the network.
Client stub finds the service address and sends the message to the server
Server stub decodes the message after receiving it.
Server stub calls the local service based on the decoding result
The local service executes and returns the result to server stub
Server stub packages the returned result into a message and sends it to the consumer
Client stub receives the message and decodes it
The service consumer gets the final result.
Here is another time sequence chart posted online:
Why not use HTTP instead of RPC for calls between services?
What problem did RPC solve?
From the content introduced by RPC above, generally speaking, RPC mainly solves the problem of making calls between different services in distributed or micro-service systems as simple as local calls.
Summary of common RPC frameworks?
RMI (included with JDK): RPC, which comes with JDK, has many limitations and is not recommended.
Dubbo: Dubbo is a high-performance and excellent service framework opened by Alibaba Company, which enables applications to realize the output and input functions of services through high-performance RPC, and can be seamlessly integrated with the Spring framework. At present, Dubbo has become the official component of Spring Cloud Alibaba.
GRPC: gRPC is a modern open source high-performance RPC framework that can run in any environment. It can effectively connect services within and across data centers through pluggable support for load balancing, tracking, health checking, and authentication. It also applies to the last mile of distributed computing to connect devices, mobile applications and browsers to back-end services.
Hessian: Hessian is a lightweight remotingonhttp tool that provides the functionality of RMI using simple methods. Compared with WebService,Hessian, it is simpler and faster. The binary RPC protocol is used, and because it uses the binary protocol, it is very suitable for sending binary data.
Thrift: Apache Thrift is Facebook's open source cross-language RPC communication framework, which has been donated to the Apache Foundation for management. Because of its cross-language features and excellent performance, it has been applied in many Internet companies. Capable companies will even develop a distributed service framework based on thrift, adding functions such as service registration and service discovery.
RPC is just a design.
RPC is just a concept, a design, to solve the problem of invocation between different services, it generally includes two transport protocols and serialization protocols.
The transportable protocol that implements RPC can be built directly on TCP or on HTTP protocol. Most RPC frameworks use TCP connections (gRPC uses HTTP2).
HTTP and TCP
Perhaps now many friends who are not familiar with the computer network have been fooled. In order to really understand it, we still need to briefly review the basic knowledge of the computer network:
We usually talk about the architecture of the five-layer protocol of computer network: application layer, transport layer, network layer, data link layer, physical layer.
The task of the application layer (application-layer) is to complete specific network applications through the interaction between application processes. HTTP is an application layer protocol, which transfers data (HTML files, picture files, query results, etc.) based on the TCP/IP communication protocol. The HTTP protocol works on the client-server architecture. As a HTTP client, the browser sends all requests to the HTTP server, the WEB server, through URL. After receiving the request, the Web server sends response information to the client. HTTP protocol is based on TCP protocol.
The main task of the transport layer (transport layer) is to provide general data transmission services for the communication between the two host processes. TCP is a transport layer protocol, which mainly solves how data is transmitted in the network. Compared with UDP,TCP, it provides connection-oriented and reliable data transmission service.
The main key lies in the difference between the TCP protocol used by HTTP and our custom TCP protocol in the message.
The TCP message of the http1.1 protocol contains too much information that may not be useful during transmission:
HTTP/1.0 200 OK Content-Type: text/plain Content-Length: 137582 Expires: Thu, 05 Dec 1997 16:00:00 GMT Last-Modified: Wed, 5 August 1996 15:55:28 GMT Server: Apache 0.84 Hello World
Using a custom TCP protocol for transport avoids the above problem and greatly reduces the overhead of transferring data. This is the real reason why RPC with a custom TCP protocol is usually used to make service invocations. In addition, the mature RPC framework also provides functions such as "automatic service registration and discovery", "intelligent load balancing", "visual service governance and operation and maintenance", "runtime traffic scheduling" and so on. These are also one of the reasons for choosing RPC for service registration and discovery.
A common misconception
Many articles will also mention that compared with the custom TCP message protocol, the additional overhead of the HTTP protocol lies in the establishment and disconnection of the connection, but this view has been denied. The following is taken from one of the answers:
First of all, we have to deny that compared with the custom TCP message protocol, the additional overhead of the HTTP protocol lies in the establishment and disconnection of the connection. HTTP protocol supports connection pool reuse, that is, the establishment of a certain number of connections continue to open, and do not frequently create and destroy connections. One thing to say is that HTTP can also use Protobuf, a binary coding protocol, to encode content, so the biggest difference between the two is in the transport protocol.
After reading the above, do you have any further understanding of how to call HTTP instead of RPC between services? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.