Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is RPC in Python

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "what is RPC in Python". In daily operation, I believe many people have doubts about what RPC is in Python. The editor consulted all kinds of materials and sorted out simple and easy-to-use methods of operation. I hope it will be helpful for you to answer the doubts about "what is RPC in Python?" Next, please follow the editor to study!

In today's computer applications, it is difficult to withstand the pressure of products on the performance of a single machine, so it is necessary to constantly expand multiple machines to improve the overall performance. At the same time, in order to make full use of the computers in these clusters, we need to divide them from the architecture to provide different services, and the services call each other to complete the function of the whole product.

# RPC is invented and exists to solve the problem of information exchange between services

RPC (Remote Procedure Call)-- remote procedure call, which is a protocol that requests services from remote computer programs through the network without knowing the underlying network technology. (the design idea of RPC is to make the communication details in the remote call transparent to the user, and the calling parties do not need to care about the specific implementation of the network communication. Therefore, the implementation of RPC needs to be encapsulated.

Process:

The caller (Caller, also known as client, Client) initiates the call in the form of a local call

After receiving the call, Client stub (client stub, which can be understood as an auxiliary helper) is responsible for packaging and coding the called method name, parameters, etc., into a message body that can be transmitted over the network in a specific format.

Client stub sends the message body to the peer (server) over the network

Server stub (server stub, which can also be understood as an auxiliary assistant) receives the message through the network and unpacks and decodes the message according to the corresponding format to obtain the method name and parameters.

Server stub makes local calls based on method name and parameters

The callee (Callee, also known as Server) local call executes and returns the result to server stub

Server stub packages the return value into a message and sends it to the peer (client) over the network.

After receiving the message, Client stub unpacks and decodes it and returns it to Client.

Client gets the final result of this RPC call.

Use the RPC method

Declare the interface form of the RPC call ret = the name of the recommend_article (channel_id, user_id) interface the parameter int channel_id passed when the recommend_article call, and the int user_id interface returns the data int list [article_id, article_id,....]

Generate the calling code (including the method of converting parameters to binary transmission, the method of network transmission transceiver) the rpc framework will provide a tool for generating code (compiler) use the compiler to generate code callers in different languages python-> use the compiler to generate python code according to the above interface description, java-> use the compiler to generate java code based on the above interface

Need to supplement the code on the called side of the server to supplement the logic function executed on the called side on the calling side, need to supplement the code called on the calling code.

Common framework

GRPC (Google)

GRPC is a high-performance RPC framework open source by Google.

GRPC supports multilingual gRPC natively implemented in C, Java and Go, while the C version of the implementation supports C++, C #, Node, ObjC, Python, Ruby, PHP and other development languages after encapsulation.

GRPC supports multiple platforms including: Linux, Android, iOS, MacOS, Windows

GRPC's message protocol is serialized using Google's own open source Protocol Buffers protocol mechanism (proto3)

The transmission of gRPC uses the HTTP/2 standard and supports bi-directional streaming and connection multiplexing.

At this point, the study of "what is RPC in Python" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report