What is RPC? RPC (Remote Procedure Call) is a protocol that requests services from a remote computer program over the network without having to understand the underlying network technology. For example, if two different services A and B are deployed on two different machines, what should service A do if it wants to call a method in service B? Using HTTP requests is certainly possible, but it may be slow and some optimizations are not good. The emergence of RPC is to solve this problem. What is the RPC principle?
Here is another online timing diagram: What problem does RPC solve? From the above introduction to RPC, in general, RPC mainly solves the problem of making calls between different services in a distributed or microservice system as simple as local calls. Summary of common RPC frameworks?
Since we have HTTP, why use RPC for service calls? RPC is just a design RPC is just a concept and a design to solve the calling problem between different services. It generally includes two protocols: transmission protocol and serialization protocol. The transport protocol for implementing RPC can be built directly on top of TCP or HTTP. Most RPC frameworks use TCP connections (gRPC uses HTTP2). HTTP and TCP Maybe many friends who are not familiar with computer networks have been confused. If you want to really understand it, you need to briefly review the basic knowledge of computer networks: The five-layer protocol architecture of computer networks that we usually talk about is: application layer, transport layer, network layer, data link layer, and physical layer. The task of the application layer is to complete specific network applications through the interaction between application processes. HTTP belongs to the application layer protocol, which transmits data (HTML files, image files, query results, etc.) based on the TCP/IP communication protocol. The HTTP protocol works on the client-server architecture. The browser, as an HTTP client, sends all requests to the HTTP server, i.e., the WEB server, through the URL. After receiving the request, the Web server sends a response message to the client. The HTTP protocol is built on the TCP protocol. The main task of the transport layer is to provide general data transmission services for the communication between two host processes. TCP is a transport layer protocol that mainly solves how data is transmitted in the network. Compared with UDP, TCP provides a connection-oriented, reliable data transmission service. The key lies in the difference in messages between the TCP protocol used by HTTP and our custom TCP protocol. The TCP message of http1.1 protocol contains too much information that may be useless during transmission:
Using a custom TCP protocol for transmission will avoid the above problem and greatly reduce the overhead of transmitting data. This is the real reason why RPC with a custom TCP protocol is usually used to call services. In addition, mature RPC frameworks also provide "automatic service registration and discovery", "intelligent load balancing", "visual service governance and operation and maintenance", "runtime traffic scheduling" and other functions, which can also be regarded as one of the reasons for choosing RPC for service registration and discovery! A common misconception Many articles also mention that the HTTP protocol has an increased overhead in connection establishment and disconnection compared to the custom TCP message protocol, but this view has been denied. The following is an answer from a certain forum: First of all, we must deny that the HTTP protocol has an increased overhead in connection establishment and disconnection compared to the custom TCP message protocol. The HTTP protocol supports connection pool reuse, which means that a certain number of connections are established without disconnection, and connections are not frequently created and destroyed. The second thing to say is that HTTP can also use Protobuf, a binary encoding protocol, to encode content, so the biggest difference between the two is still in the transmission protocol. Off topic In addition, it is also important to note that Spring Cloud Netflix does not use the RPC framework to call between different services, but uses the HTTP protocol for calling. Although the speed is not as fast as RPC, using the HTTP protocol will also bring many other benefits (you can refer to relevant information for yourself). |
>>: 5G commercialization has arrived, how far are 6G and the "terahertz era"?
Documentation is often neglected in IT work. When...
I received the latest promotional email from Host...
RAKsmart has also launched the most important 11....
[[398109]] On May 7, the three major operators is...
HTTP status code is the response status code retu...
ICMP ICMP (Internet Control Message Protocol) is ...
HPE (NYSE: HPE) today announced the acquisition o...
[[356547]] To see the current status of a SaaS co...
As the use of wireless devices continues to soar ...
The overall flow chart is as follows: 1. URL pars...
edgeNAT has newly launched the Korean three-netwo...
Ding Ling, a modern Chinese feminist writer, publ...
According to public data, the scale of layoffs at...
[51CTO.com original article] [Fuzhou, China, Marc...
[[188974]] Chinese consumer finance practitioners...