RPC calls and the difference between HTTP calls

For a long time did not figure out how to take RPC (ie Remote Procedure Call, Remote Procedure Call) and the difference between HTTP calls, not all service and then write a client calls it? Allow me here to the fans laugh ~ Naive! This article briefly explain two forms of C / S structure, to talk about their most essential difference is that RPC is mainly based on TCP / IP protocol, and the HTTP service is mainly based on the HTTP protocol, we all know that HTTP protocol is on top of TCP transport layer protocol, so the efficiency of view, then, RPC is certainly superior to it! Let's talk about the specific RPC service and the HTTP service.

Seven layer OSI network model

Before say the difference between RPC and HTTP, I feel it is necessary to look at the OSI seven-layer network architecture model (although practical applications are basically five), it can be divided into the following layers: (top to bottom)

  • First layer: an application layer. It defines an interface for communication and data transmission in the network;
  • The second layer: the presentation layer. Define different transmission format encoding and decoding data system specification, and the like;
  • The third layer: the session layer. Manage user sessions controls establish a logical connection between the user and interruptions;
  • Fourth layer: the transport layer. Manages the network end to end data transmission;
  • The fifth layer: the network layer. How to transfer data between network devices is defined;
  • Sixth layer: the link layer. Above the network layer packet is encapsulated into the data frames, to facilitate physical layer transmission;
  • Seventh layer: a physical layer. This layer is the transmission of these binary data.

The actual application process, which is not a five-layer structure protocol and session layer, presentation layer. It should be said that they are in the application layer merged. We should focus on the application layer and the transport layer both levels. Because HTTP is an application layer protocol, while TCP is the transport layer protocol. Okay, got it after hierarchical model of the network, we can better understand why RPC service compared to some of the HTTP service to Nice!

RPC Service

From three angles to introduce the RPC service: namely RPC architecture, synchronous and asynchronous invocation popular RPC framework.

RPC architecture

Let us talk about the basic architecture of RPC service bar. Allow me shamefully ha ~ Pirates a picture we can clearly see that a complete RPC architecture which includes four core components, which are Client, Server, Client Stub and Server Stub, Stub we can understand this as stub. Respectively, to talk about these components:

  • Client (Client), caller services.
  • Server (Server), a true service provider.
  • Client stub, storing the address of the message server, the client request parameters and then packaged into a network message, and then sent to the serving network via the remote.
  • Server stub, the client receives a message sent from, the message is unpacked, and native method calls.

RPC is mainly used in large-scale enterprises which, because many large enterprises inside the system, line of business complexity and efficiency advantages of a very important piece, this time RPC advantage is more obvious. The actual development of which is to do so, use maven to manage the project in general. For example, we have an order processing system service, declare all of its interfaces (this is specifically referring in Java interface), then the entire project will be packaged as a jarpackage, the server side of the introduction of the second party library, and then implement the appropriate function, the client side only need to introduce this library you can call a second party. Why do this? Primarily to reduce the client side of the jarpacket size, because every time when packaged released, jartoo many packets will always affect the efficiency. In addition it will also decouple client and server and improve the portability of the code.

Synchronous calls and asynchronous calls

What is a synchronous call? What is an asynchronous call? 同步调用That is, the client waits for the call to perform complete and return the results. 异步调用That is, the client does not wait for the call to return to complete the implementation of the results, but can still receive notification of results returned by the callback function and so on. If the client does not care about the result, it can become a one-way call. This process is somewhat similar in Java callableand runnableinterfaces, we performed asynchronously, if you need to know the result of execution, you can use callablethe interface, and can Futureobtain information on the results of asynchronous execution class. If you do not care about the result of the implementation of the direct use of runnablethe interface on it, because it does not return a result, of course, callablealso possible, we do not get Futureit.

Popular RPC framework

RPC popular open-source framework, or more. We focus on the following three ways:

  1. gRPC is Google recently released open source software, based on the latest HTTP2.0 protocol, and supports many common programming languages. We know HTTP2.0 is based on a binary protocol upgraded version of HTTP, the current major browsers are supported to be at full speed. The RPC framework is based on the HTTP protocol implementation, to support the use of the underlying Netty framework.
  2. Facebook's Thrift is an open source project, is primarily a cross-language services development framework. It IDL definition file has a code generator to automatically generate the definition of its service code frame. As long as the user secondary development on the line prior to, for the underlying RPC communications are transparent. But this need for users to learn a language, then the characteristics of a particular field, or have a certain cost.
  3. Dubbo Ali Group is a very well-known open source RPC framework that is widely used in many Internet companies and enterprise applications. And serialization framework agreement can be plug and distinct characteristics. The same remote interface is based on Java Interface, and relying on spring framework to facilitate the development. Can be easily packaged into a single file, separate processes running, and now the concept of micro-services agreement.

偷偷告诉你Within the group for much of dubbo you, now used more called HSF, also known as "very comfortable." Later there may be open source, we wait and see.

HTTP Service

In fact, a long time ago, I model for enterprise development has been characterized as HTTP interface development, that is, we often say that for RESTful service interface. Indeed, much in the interface for the case where less system interact with the system, a communication means for solving initial islands frequently used information; which was simple, direct, and facilitate the development. Use of existing transmission http protocol. We remember before undergraduate internship in the company to do background development time, mainly to develop interface, but also to write a large portion interface documentation, indicating what is strictly for input or output? Make it clear that each interface request method, request parameters as well as matters that need attention. For example, the following example:
POST http://www.httpexample.com/restful/buyer/info/share
interfaces may return a JSON string or XML document. The client then returns again to deal with this information, which can be developed relatively quickly. But for large enterprises, more internal subsystem, under a lot of interfaces, the benefits of RPC frames on the show, is the first long link, do not always communicate the same to be like http three times what the handshake, It reduces network overhead; second is generally RPC framework registry, there is a wealth of monitoring and management; publish, off the assembly line interfaces, dynamic expansion of the caller is not aware, unified operation.

to sum up

RPC service and the HTTP service is still there are many differences, in general, RPC services mainly for large enterprises, and the HTTP service is mainly aimed at small businesses, because of the higher efficiency of RPC, and HTTP services development will be faster iterations . In short, the choice of what kind of framework is not in accordance with the market and decide what's popular, but to conduct a complete assessment of the entire project, so carefully compare the two development framework for the impact of the project, and finally decide what is best for this project. Be sure not to use the RPC and RPC with each project, but to local conditions, specific conditions.

Guess you like

Origin www.cnblogs.com/findbetterme/p/11200999.html