RPC and HTTP difference

RPC (ie Remote Procedure Call, Remote Procedure Call ) and  HTTP (HyperText Transfer Protocol, Hypertext Transfer Protocol ) is the most essential difference between them is that RPC major work on top of TCP protocol , while working primarily on the HTTP service HTTP protocol we all know that on top of the HTTP protocol is TCP transport layer protocol, so the efficiency of view, then, RPC is of course to be superior.

1, RPC service

(1) RPC architecture

A complete RPC architecture which includes four core components, which are Client, Server, Client Stub and Server Stub, Stub we can understand this as a stub. Respectively, to talk about these components:

  • 1) client (Client), caller services.

  •  2) the server (Server), a true service provider.

  •  3) the client stub, the storage 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.

  •  4) the server stub, receiving a message sent from the client, the message is unpacked and a local method call.

  

 

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 a service order processing system, and declare all of its interfaces (this is specifically referring to Java in the interface), then the entire project will be packaged as a jar package, the server side of the introduction of the second party library, then realized the corresponding 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 jar package size, because every time when packaged released, jar too many packets will always affect the efficiency. In addition will also decouple client and server and improve the portability of the code.

(2) synchronous calls and asynchronous call

  • What is a synchronous call?

Synchronous call that the client waits for the call to perform complete and return the results.

  • What is an asynchronous call?

Asynchronous call 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 to Java in callable and runnable interfaces, we performed asynchronously, if you need to know the result of the implementation, you can use the callable interface, and can get to the asynchronous execution result information by Future class. If you do not care about the results of implementation, directly runnable interfaces on it, because it does not return a result, of course, callable also possible, Future we do not get it.

(3) the 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) Thrift Facebook 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.

2, HTTP service

(1) HTTP Interface

 Compared RPC, HTTP interface development is what 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 of solving the initial information islands frequently used; the advantage that a simple , direct , easy development . Use of existing transmission http protocol. Do background interface development when the need to write an interface documentation, identify what is strictly for input or output? Make it clear that each interface request method, request parameters as well as matters that need attention.
      Such as this 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,

  • The first is long link, do not always have to like http communication as to what the 3-way handshake, reducing network overhead;
  • The second is the RPC framework generally have a registry, there is a wealth of monitoring and management;
  • Release, off the assembly line interfaces, dynamic expansion of the caller is not aware, unified operation.

(2)restful:

Corresponding Chinese style is rest; Restful web service is a common application of rest, the rest is in compliance with the style of web services; rest-style web service is a ROA (The Resource-Oriented Architecture) ( resource-oriented architecture ). Why is there Restful?
    1) Prior to the operation of Restful:
    http://127.0.0.1/user/query GET query based on user id user data
    new user POST http://127.0.0.1/user/save
    http://127.0.0.1/user / update POST modify user information
    http://127.0.0.1/user/delete GET / POST delete user information
    2) RESTful usage:
    http://127.0.0.1/user the above mentioned id GET query user data according to user
    http: //127.0. 0.1 / user POST new user
    http://127.0.0.1/user PUT modify user information
    http://127.0.0.1/user dELETE delete user information
    before the operation is not a problem, the great God think there is a problem, what have problem? interface or address every time you request, described are doing, such as when a query with the query, the new time with the save, in fact, there is no need, I use the get request is to query using post request, is the new request, my intention is clear, there is no need to do description, which is why have restful.

3, summary

    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 higher efficiency 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.

Published 13 original articles · won praise 1 · views 7802

Guess you like

Origin blog.csdn.net/weixin_40482816/article/details/104018464