当前位置:网站首页>RPC protocol details
RPC protocol details
2022-07-05 18:29:00 【Knock the little crisp of the code】
One 、 What is? RPC agreement
Remote procedure call protocol , It is a way of requesting services over a network from a remote computer program , You don't need to know the protocols of the underlying network technology .
The specific calling process is :
1. Serving consumers (client client ) Call the service that needs to be consumed by calling the local service ;
2. Client stub (client stub) After receiving the call request, it is responsible for putting the method 、 Serialization of input parameter information ( assemble ) To be a message body capable of network transmission ;
3. Client stub (client stub) Find the remote service address , And send the message to the server through the network ;
4. Server stub (server stub) Decode the message upon receipt ( Deserialization operation );
5. Server stub (server stub) Call the local service according to the decoding result for relevant processing ;
6. The local service executes the specific business logic and returns the processing result to the server stub (server stub);
7. Server stub (server stub) Repackage the returned results into messages ( serialize ) And send it to the consumer through the Internet ;
8. Client stub (client stub) Message received , And decode it ( Deserialization );
9. Service consumers get the end result ;
and RPC The goal of the framework is to achieve the 2-9 The steps are well sealed , That is to call 、 code / The decoding process is encapsulated , Let the user feel like calling a local service to call a remote service .
Two 、 Realization RPC Problems to be solved
Communication problems
The remote invocation , There must be communication between the two machines . Mainly through the establishment between the client and the server TCP Connect , All the data exchanged by the remote procedure call is transferred in this connection . Connections can be on-demand , It will be broken after the call , It can also be a long connection , Multiple remote procedure calls share the same connection .
Usually this connection can be on-demand ( When it needs to be called, establish the connection first , It will be broken immediately after the call ), It can also be a long connection ( Keep the client and server connected for a long time , No matter whether there is a packet sent at this time , It can cooperate with heartbeat detection mechanism to regularly detect whether the established connection is alive and effective ), Multiple remote procedure calls share the same connection .
Service addressing
above-mentioned ,RPC It is local oriented . Then the user makes a local call , How to find the corresponding remote call , need RPC Implement at the bottom . Need to manage ip, port , Service list and other information . It's common to use zookeeper To manage .
For producers :
When the service starts , Register your services to the Registration Center ;
When the producer hangs up , The registry logs out of the stopped service ;
The producer sends heartbeat to the registration center regularly , If the heartbeat is abnormal , The registry also unregisters producer services .
For consumers :
Subscribe to the service of the registry , obtain ip, Port and other service information ;
When producers go online and offline , The registry will notify the caller ;
After the service is offline , Consumers no longer consume the service .
Network transmission
When A The application on the machine initiates a RPC Invocation time , Call method and its input parameter information need to go through the underlying network protocol, such as TCP Transferred to the B machine , Because the network protocol is based on binary , All the parameter data we transmit needs to be serialized first (Serialize) Or group (marshal) Only in binary form can it be transmitted in the network . Then the binary data after serialization or marshalling is sent to B machine .
When B The machine received A After the request from the application of the machine , It also needs to deserialize the received parameters and other information ( The reverse operation of serialization ), To restore binary information to an in memory representation , Then find the corresponding method ( Part of addressing ) Make a local call ( It's usually through the generation of agents Proxy To call , Usually there will be JDK A dynamic proxy 、CGLIB A dynamic proxy 、Javassist Bytecode generation technology, etc ), Then get the return value of the call .
The service call
B The machine makes local calls ( Through agency Proxy And reflection calls ) Then we get the return value , At this time, you need to send the return value back to A machine , It also needs to be serialized , And then send the binary data back to A machine , And when A After the machine receives these return values , Then deserialize again , Revert to in memory expression , Give it to A The application on the machine carries out relevant processing , Generally, business logic processing operations .
3、 ... and 、RPC And REST The difference between ?
RPC And REST The biggest difference is RPC Provides better abstraction ,RPC Even completely hide the details of network transmission , and REST No, . say concretely ,REST As a minimum, it is required to provide URL And request parameters , and RPC Hide the implementation details related to network transmission . On the other hand ,RPC It can be based on any network communication protocol , and REST Usually based on HTTP( perhaps HTTPS) agreement .RPC The caller doesn't care if the specific agreement is :HTTP、TCP Or any other custom protocol .
Four 、 Advantages and disadvantages
advantage :
Help the client communicate with the server through the procedure call of traditional high-level language .
It can be used in distributed environment and local environment .
Support process oriented and thread oriented models .
Hide the internal messaging mechanism from users .
Code can be rewritten and redeveloped with minimal effort .
Provide abstraction , That is to hide the message transmission nature of network communication from users .
Omit many protocol layers to improve performance .
shortcoming :
The client and server use different execution environments for their routines , And resources ( for example , file ) The use of is also more complex . therefore ,RPC Systems are not always suitable for transmitting large amounts of data .
RPC Very prone to failure , Because it involves communication systems , Another computer and another process .
RPC There is no uniform standard ; It can be realized in many ways .
RPC Just based on Interaction , therefore , In terms of hardware architecture , It does not provide any flexibility .
Reference article :
RPC Protocol analysis [ Easy to understand ]
Thousand words take you to know what is RPC agreement
边栏推荐
- 第十届全球云计算大会 | 华云数据荣获“2013-2022十周年特别贡献奖”
- Is it safe for golden sun to open an account? Can I open an account free of 5 in case?
- To solve the stubborn problem of Lake + warehouse hybrid architecture, xinghuan Technology launched an independent and controllable cloud native Lake warehouse integrated platform
- SAP 特征 特性 说明
- Wu Enda team 2022 machine learning course, coming
- sample_rate(采樣率),sample(采樣),duration(時長)是什麼關系
- Sibling components carry out value transfer (there is a sequence displayed)
- Login and connect CDB and PDB
- 怎么自动安装pythn三方库
- Record a case of using WinDbg to analyze memory "leakage"
猜你喜欢

Copy the linked list with random pointer in the "Li Kou brush question plan"

About Statistical Power(统计功效)
![Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]](/img/b2/d019c3f0b85a6c0d334a092fa6c23c.png)
Whether to take a duplicate subset with duplicate elements [how to take a subset? How to remove duplicates?]

node_exporter内存使用率不显示

LeetCode 6111. Spiral matrix IV

ConvMAE(2022-05)

Trust counts the number of occurrences of words in the file

Failed to virtualize table with JMeter

Use QT to traverse JSON documents and search sub objects

The main thread anr exception is caused by too many binder development threads
随机推荐
The 11th China cloud computing standards and Applications Conference | China cloud data has become the deputy leader unit of the cloud migration special group of the cloud computing standards working
Nacos distributed transactions Seata * * install JDK on Linux, mysql5.7 start Nacos configure ideal call interface coordination (nanny level detail tutorial)
小林coding的内存管理章节
Memory management chapter of Kobayashi coding
About Estimation with Cross-Validation
文章中的逻辑词
Wu Enda team 2022 machine learning course, coming
U-Net: Convolutional Networks for Biomedical Images Segmentation
Simulate the hundred prisoner problem
LeetCode 6109. 知道秘密的人数
The origin of PTS, DTS and duration of audio and video packages
关于服装ERP,你想知道的都在这里了
彻底理解为什么网络 I/O 会被阻塞?
Access the database and use redis as the cache of MySQL (a combination of redis and MySQL)
pytorch yolov5 训练自定义数据
含重复元素取不重复子集[如何取子集?如何去重?]
Gimp 2.10 tutorial "suggestions collection"
Use of print function in MATLAB
Introduction to Resampling
基于can总线的A2L文件解析(3)