Comparison of RPC service and HTTP service

Source: Internet
Author: User

It's been a long time since the difference between RPC (that is, remote Procedure call, remoted Procedure calls) and HTTP calls, is it not all about writing a service and calling it on the client? Here please allow me to be fascinated by one laugh ~naive! This article briefly introduces the two forms of C/S architecture, first of all, their most essential difference is that RPC is mainly based on TCP/IP protocol, and HTTP service is mainly based on the HTTP protocol , we all know that the HTTP protocol is on the Transport Layer protocol TCP, So in terms of efficiency, RPC is, of course, more of a win! Here's a concrete talk about RPC services and HTTP services.

OSI Network Seven layer model

Before I say the difference between RPC and HTTP, I think it's important to understand the OSI seven-layer network architecture model (although it's basically five-tier in practice), it can be divided into the following layers: (Top to bottom)

  • First layer: Application layer. Defines an interface for communicating and transmitting data in a network;
  • Second layer: Presentation layer. Define the transmission format, encoding and decoding specifications of the data in different systems;
  • Third layer: Session layer. Manage user's sessions and control the creation and interruption of logical connections between users;
  • Layer Fourth: Transport layer. Manage the end-to-end data transfer in the network;
  • Layer Fifth: Network layer. Define how data is transferred between network devices;
  • Layer Sixth: Link layer. The packet of the above network layer is encapsulated into a data frame, which facilitates the transfer of the physical layer;
  • Layer seventh: Physical layer. This layer is primarily the transfer of these binary data.

In the actual application process, there is no representation layer and session layer in the five layer protocol structure. It should be said that they merged with the application layer. We should focus on the application layer and the transport layer of the two levels. Because HTTP is an application-layer protocol, TCP is the transport-layer protocol . Well, knowing the hierarchical model of the network, we can better understand why the RPC service is a little nicer than the HTTP service!

RPC Service

The RPC service is described in three ways: RPC schema, synchronous asynchronous invocation, and popular RPC framework.

RPC Schema

Let's talk about the basic architecture of the RPC service. Allow me to steal a picture with shame. We can clearly see that a complete RPC architecture contains four core components, namely, client ,Server,client Stub , and Server stub, this stub can be understood as stubs. Say these components separately:

    • Client", the caller of the service.
    • service side (Server), true service provider.
    • The client stub, which stores the address message on the server, packages the client's request parameters into a network message, and then sends it to the service provider remotely over the network.
    • server stub, receive the message sent by the client, unpack the message, and invoke the local method.

RPC is mainly used in large enterprises, because large enterprises inside a wide range of systems, business lines complex, and efficiency advantages of a very important piece, this time the advantages of RPC is more obvious. This is done in real-world development, and projects are generally managed using MAVEN. For example, we have a system service that deals with orders, first declaring all of its interfaces (this is specifically referred to in Javainterface), and then package the entire project as ajarPackage, the server side of the introduction of this two-party library, and then implement the corresponding functions, the client side also only need to introduce this two-party library can be called. Why did you do this? Mainly to reduce the client side of thejarPackage size, because each time the package is released,jarToo many packages can always affect efficiency. In addition, the client and the server are decoupled to improve the portability of the code.

Synchronous calls and asynchronous calls

What is a synchronous call? What is an asynchronous call? 同步调用 is that the client waits for the call to finish and returns the result. 异步调用is that the client does not wait for the call execution to complete the return result, but can still receive a notification of the return result through the callback function. If the client does not care about the result, it can become a one-way call. This process is somewhat similar to the one in JavacallableAndrunnableinterface, when we execute asynchronously, if we need to know the result of the execution, we can use thecallableinterface, and can beFutureClass gets the result information to the asynchronous execution. If you do not care about the results of execution, use directlyrunnableInterface is OK, because it doesn't return results, of course,callableIt's also possible, we're not going to getFutureYou can do it.

The popular RPC framework

The current popular open source RPC framework is still much more. Here are three types of highlights:

  1. GRPC is Google's latest open source software, based on the newest HTTP2.0 protocol and supports many common programming languages. We know that HTTP2.0 is a binary-based version of the HTTP protocol that is currently being supported by major browsers. This RPC framework is implemented based on the HTTP protocol, and the underlying use of the Netty framework is supported.
  2. Thrift is an open source project for Facebook, primarily a cross-language service development framework. It has a code generator that automatically generates a service code framework for the IDL definition file it defines. As long as the user has two times before the development of the line, for the underlying RPC communication, etc. are transparent. However, this is a certain cost for the user to learn the specific domain language.
  3. Dubbo is an extremely well-known RPC framework for Alibaba Group's Open source, which is widely used in many Internet companies and enterprise applications. Both the Protocol and the serialization framework are pluggable and distinctive. The same remote interface is based on Java Interface and is easy to develop with the spring framework. It can be conveniently packaged into a single file, run independently, and be consistent with the current microservices concept.

偷偷告诉你The group has not how to use Dubbo , now with more than the name of HSF, aka "Good comfortable". There may be open source behind, and we'll wait and see.

HTTP Service

In fact, a long time ago, my model for enterprise development has been defined as the development of HTTP interfaces, which is what we often call the RESTful style of service interface. Indeed, for a small number of interfaces, systems and systems with less interaction, the solution of the early days of information is often used in a means of communication, the advantages are simple, direct, easy to develop. Transfer using the ready-made HTTP protocol. We remember before the undergraduate internship in the background development of the company, the main is to develop the interface, but also to write a large portion of the interface document, strictly indicate what is the input and output? Make clear the request method for each interface, as well as the things to be aware of when requesting parameters. For example, the following:
POST http://www.httpexample.com/restful/buyer/info/share
The interface may return a JSON string or an XML document. The client then processes the returned information so that it can be developed in a relatively rapid manner. But for large enterprises, the internal subsystem is more, the interface is very large, the benefits of the RPC framework is shown, the first is the long link, do not have to each communication like HTTP to 3 times to shake a handshake or something, reduce the network overhead; Next is the RPC framework generally has a registration center, has a wealth of monitoring and management , release, downline interface, dynamic expansion, etc., is a non-aware, unified operation for the caller.

Summarize

The RPC service and HTTP service still have a lot of different points, in general, the RPC service is mainly for large enterprises, and the HTTP service is mainly for small enterprises, because RPC is more efficient, and HTTP service development iterations will be faster. In short, the choice of what kind of framework is not based on what is popular in the market, but the entire project to be fully evaluated, so that in careful comparison of the two development frameworks for the overall impact of the project, and finally decide what is the most suitable for this project. Be sure not to use RPC for each project with RPC, but to adapt to local conditions, specific analysis.

Comparison of RPC service and HTTP service

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.