The difference between RPC framework and HTTP framework

The difference between RPC framework and HTTP framework

With the HTTP protocol, why do we need the RPC remote procedure call protocol?

Since RPC communicates directly through the custom TCP protocol, and the HTTP service uses the Http protocol (Http is on top of TCP), which is equivalent to an extra layer, RPC is more efficient than Http. http is a hypertext transfer protocol, and the information it contains is relatively bloated. In the past, gateways generally used http, and calls between services used rpc.

On the one hand, this is because the efficiency of the RPC framework is relatively high, and on the other hand, RPC includesRetry mechanism, routing strategy, load balancing strategy, high availability strategy, traffic control strategy, the above functions cannot be completed using http

我们通常采用的原则为:**向系统外部暴露采用HTTP,向系统内部暴露调用采用RPC方式。** 也就是说前后端之间(网关之前)用http,各个服务之间用rpc

the difference:

RPC is mainly used for system internal service calls, with high transmission efficiency (based on tcp) and low performance consumption (efficient binary transmission)

http is generally used before the gateway to provide system-to-system communication (bloated information contained in http), performance

1.Transmission protocol

  • RPC framework: based on TCP protocol or http protocol (google's grpc is implemented based on http2)
  • HTTP framework: based on http protocol

Since RPC communicates directly through the custom TCP protocol, and the HTTP service uses the Http protocol (Http is on top of TCP), which is equivalent to an extra layer, RPC is more efficient than Http.

2. Performance loss

  • RPC: efficient binary transfer
  • HTTP: Mostly implemented based on json, byte size and serialization are time-consuming.

3. Service calling function

  • RPC: comes with load balancing mechanism, flow control, etc.
  • HTTP: ngnix needs to be added to provide load balancing.

4. Use

  • RPC: After configuration, it can be called directly, calling the interfaces of other services just like calling local interfaces.
  • HTTP: You need to splice the URL of the http request and then initiate the request.

Every time HTTP is used in the project, URLs need to be spliced, which is not very convenient. Moreover, when the server where the resource is located changes during service operation, we need to modify the source code, then compile, package, and deploy, which is quite troublesome.

Personal opinion:

The http protocol appears for communication between systems (Client<—>Server), so some additional information needs to be set: communication protocol, request method, request parameters, etc. RPC, as the name suggests, is used for calls between services, so there is no need to introduce too much information like http. Therefore, the RPC protocol is relatively small, and RPC uses binary transmission, while http uses json to be used on the network. Medium transmission requires serialization, and RPC efficiency is relatively high. RPC also provides some mechanisms for calls between services: load balancing, flow control, etc.

Guess you like

Origin blog.csdn.net/qq_50876039/article/details/127137908