Location>code7788 >text

RPC and HTTP protocols

Popularity:250 ℃/2024-07-31 20:17:30

Difference between RPC and HTTP

service discovery

  • HTTP, know the domain name of the service, you can get the IP address of the service through DNS resolution, so as to access it.
  • RPC requires a specialized intermediate service to store the service name and IP information (registry, nacos, consul). To access a service, you have to register to the intermediate service at the same time, and then get the IP and port information of the service you want to use.

underlying link form

  • By default, HTTP/1.1 keeps a TCP link alive after it has been established at the bottom of the hierarchy, and subsequent requests and responses take this link back.
  • RPC protocol, and http, the same place is, through the establishment of TCP long link for data interaction, the difference is, RPC will generally establish a link pool, a large number of requests, will establish multiple links in the link pool. When you need it, you take it from the link pool, and when you don't need it, you put it back to the link pool.

Transmission content

  • RPC and HTTP protocols have a request header and a request body, but the content of the request header is inconsistent, due to the inconsistency of the data format of the request body, the request header will be stored in the request body parsing, in order to solve the body parsing, the request body will be different
  • Generally messages are structured information, but the TCP transfer is a binary string of 01 (computers only recognize 0 and 1), so before transferring the data from the application layer, the structure is converted to binary, a process calledserializeIn turn, the message sent from the transport layer is binary, and the process of converting the binary data into a structure is calleddeserialization
  • In general, the HTTP protocol in order to do enough generalization, will add more information in the request header, all the content will be on the large side, the whole message body will be larger than RPC. But not absolutely, if the underlying protocol of RPC using http, then the opposite is true!

summarize

  1. TCP and UDP are transport layer protocols, while RPC and http define different message formats and can be considered as application layer protocols.

  2. HTTP: hyper text transfer protocol, a protocol derived from the creation of the browser.

  3. RPC protocol: romote procedure call (remote procedure call protocol), he is not a protocol, but a way to call. RPC itself has many ways to realize, the underlying protocol is not necessarily based on TCP, can be UDP, http protocols

  4. Pure bare TCP can send and receive data, but he it is an unbounded data stream, the upper layer (application layer) needs to define the message format, used to define the message boundary

  5. Historically speaking, RPC actually appeared earlier than HTTP, HTTP is mainly used in B/S architecture, RPC is mainly used in C/S architecture, and now slowly there are signs of convergence.

  6. HTTP/2.0 is optimized over HTTP/1.0 and outperforms RPC.