This is the 20th day of my participation in the Genwen Challenge

What is RPC?

Remote Process Call Remote procedure Call.

What is your understanding of RPC? The client calls the server as if it were calling a local function, using it directly and getting the result.

function addNum(a, b){
   return a+b;
}

var sum = addNum(2.3);
Copy the code

As with local calls, how does RPC allow a service to call a remote service as if it were calling a local function? What are the problems that need to be resolved during the invocation?

As shown in the figure:

Service1: Passes in the argument, passes through the RPC framework, and gets the result

Service2: Receives the parameter, executes the logic, and returns the result

The main responsibilities of RPC are:

  • Client side: serialization, deserialization, connection pool management, load balancing, failover, queue management, timeout management, asynchronous management, etc
  • Server side: server side components, server side packet queue, IO thread, worker thread, serialization deserialization, etc

Why use RPC?

Usually used more than a remote call scheme based on the Http protocol remote call scheme. Such as Http+Restful specification + serialization and deserialization constitute a complete remote call scheme.

Advantages:

  • Readability and cross-language support

Disadvantages:

  • The HTTP-based protocol is at the application layer and contains a large number of HTTP headers resulting in a small proportion of useful information
  • Interprocess invocation requires layer upon layer encapsulation of HTTP protocol, which leads to low efficiency
  • Using THE HTTP protocol, you also need to encapsulate various parameter names and values

RPC, understood as a framework, includes: interface specification, serialization and deserialization, communication protocol.

Advantages:

  • Cross-language support
  • Calling remote methods is just like calling local methods, and data transfer is more efficient
  • Supports a variety of protocols, and protocol privacy, high security

Disadvantages:

  • Poor readability because efficiency is improved by sacrificing readability

The RPC framework is used to mask the serialization, network transmission and other technical details during RPC calls. Let the caller only focus on the invocation and the service only focus on implementing the invocation.

In what scenarios might RPC be considered

The pros and cons of the two, in fact, more to stand in the perspective of the business scene to think about the choice of the corresponding technology. Readability and efficiency versus your business needs

If RPC is used, the scenario used is considered

  • Real-time communication chat IM system, through RPC to achieve real-time efficient message transmission
  • In the e-commerce system, there are many business functions and many business services are disassembled. The services are called each other, so RPC can be used internally
  • When the project is too large and requires decoupling services, scalability and flexible deployment, RPC is needed