RPC theory

RPC overview

What is RPC

RPC (Remote Procedure Call) remote procedure call protocol, a protocol that requests services from a remote computer through the network without needing to understand the underlying network technology. RPC assumes the existence of certain protocols, such as TPC/UDP, etc., to carry information and data between communication programs. In the OSI network seven-layer model, RPC spans the transport layer and the application layer. RPC makes it easier to develop applications including network distributed multi-programs.

What is the process?
Processes are business processing, computing tasks, or, to put it more bluntly, they are programs, which call remote processes just like calling local methods.

What is the difference with local call

Insert picture description here
Remote calling is like a long-distance relationship.
Insert picture description here
Local calling is separated by thousands of mountains and rivers . The girl is by your side. The
remote calling needs to go through the network, so the response is several orders of magnitude slower and not so reliable.

RPC mode

RPC adopts the client/server model and is implemented through the request-response message model
Insert picture description here

The three processes of RPC

1: Communication protocol
For example: if you need to find someone to work in a foreign country, then you can fly there directly or call or use the Internet to find someone. The process of finding someone is the communication protocol.
2: Addressing
Since you are looking for someone to work, you must know where the address is, you need to find the detailed address when you fly there, you need to know the phone number to make a call, and the Internet needs to know the IP
3: Data serialization
In other words, languages ​​need to be interoperable to allow others to work, and a language that everyone understands is needed to communicate.

Why use RPC

1: Servicing/microservice
2: Distributed system architecture
3: Reusable services
4: Interactive calls between systems

The difference between RPC and other protocols

RMI remote method invocation is a specific implementation of RPC. Both webservice and restfull are RPC, but the organization of messages and message protocols are different.

RPC usage scenarios

Contrast with MQ:
MQ has an intermediate node queue, which can store messages.
RPC features:
synchronous calls. For scenarios that need to wait for the return result, you can use RPC
message MQ features:
asynchronous one-way messages, no need to wait for message processing to complete
If you need to get results synchronously, RPC is more suitable. If you want to use simple, RPC is also suitable. RPC operation is based on interfaces, and the operation is simple. The method used simulates the call of local methods. Asynchronous programming is more complicated.
Insert picture description here

RPC process

Insert picture description here
1: Call client sub during client processing, just like calling a local method, pass in parameters
2: client sub groups the parameters into a message, and then send a message to the server through a system call
3: The client's local operating system sends the message From the client to the server
4: The server passes the received data packet to the server sub
5: The server sub unmarshals the received data as a parameter
6: The server sub then calls the server process, and the result of the process execution is reversed The same steps in the direction respond to the client

sub (stub): The stub in distributed computing is a piece of code that converts the parameters passed between client and server during remote procedure call (RPC)

Issues to be addressed:
1: Development of client sub and server sub
2: Parameter marshalling and unmarshalling
3: How to send messages
4: How to express process results and how to deal with abnormal situations
5: How to implement secure access control

RPC core concept terminology

1: client, client
2: server, server
3: calls, request
4: replier, response
5: services, a network service is composed of one or more remote assemblies
6: programs, a remote program implements one or more Remote process
7: procedures, the parameters and results of the process, process are defined in the program protocol specification
8: version, for compatible program protocol changes, a server may support multiple versions of remote programs

RPC protocol

In the process of RPC call, the message needs to be grouped and then sent. The receiver needs to ungroup the message as a parameter, and the process result also needs to be grouped and ungrouped; which parts of the message are composed and the form of the message constitute the message protocol.
The RPC protocol specifies the format of request messages and response messages. On top of TCP, we can choose or customize the message protocol to achieve RPC interaction

RPC framework

The RPC program development framework that encapsulates parameter marshalling, message unmarshalling, and low-level network communication can be written directly on this basis, focusing only on the process code
. Commonly used RPC frameworks in the java field are:
traditional webservice frameworks: apache CXF, apache Axis2
Emerging microservice frameworks: Dubbo, springcloud, apache Thrift, ICE, GRPC, etc.

Service exposure

The remote provider needs to provide service invocation-related information in some form, including but not limited to service interface definitions, data structures or intermediate service definition files, web service WSDL files; service callers need to obtain remote services through certain channels Call related information
Insert picture description here

Remote proxy object

The service used by the service caller is actually the local proxy of the remote service. To put it
bluntly, at least two types of dynamic code generation are provided in java through dynamic proxy implementation , one is jdk dynamic proxy, and the other is bytecode generation:
dynamic The proxy is more convenient to use than bytecode generation, but the performance is not as good as bytecode generation, and bytecode generation is worse in code readability

communication

The communication of the RPC framework has nothing to do with the specific protocol, RPC can be based on HTTP or TCP protocol
Insert picture description here

Serialization

Transmission method and serialization will directly affect the performance of RPC
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_34365173/article/details/105909740
RPC
RPC