This is the 14th day of my participation in the August More Text Challenge. For details, see:August is more challenging

  • 📢 welcome to like: 👍 collect ⭐ message 📝 If there is any mistake please correct it, send roses, hand left fragrance!
  • 📢 This article is written by Webmote.
  • 📢 author’s motto: life lies in tossing about, when you do not toss about life, life will start tossing you, let us work together! 💪 💪 💪

Preface 🎏

Net Remoting, Web Service, and even DCom all implemented similar functions more or less, but they either did not pay attention to the codec of data, or pay attention to the universality of communication protocol. As a result, when they are popular, they often feel either less than ideal or difficult to use.

At present, popular RPC technologies, such as Thrift, GRPC, Dubbo, etc., are designed for distributed application communication with high concurrency and high performance of Internet e-commerce. Their codec performance is excellent, and their communication efficiency is also good.

🎏 01. Why use RPC?

Many friends have great doubts about using RPC communication for microservices. Don’t you like to use webApi directly?

Yes, everything is not absolute, when your business performance requirements are not very high, it is true that HTTP WebAPI is enough, after all, a little performance is not as good as the business to complete faster.

From the perspective of splitting into microservices, due to the business granularity of splitting, it is inevitable that functions previously handled by one service will now be federated by multiple services. Let’s draw a picture of what’s going on, okay?

Yes, if the previous business A needs to call the database for each data, assuming that it needs to call the database three times, then after splitting into microservices, the interfaces of each microservice need to be called separately through the network, and these interfaces need to call their respective databases through the network.

This is just a general complex scenario, and there are many more complex businesses that may have longer invocation chains.

So those extra network calls, each with a delay, might add up to something more objective. Of course, that’s the price you pay for increasing your scalability.

🎏 02. call link of RPC

  1. RPC serializes the binary stream according to the specified protocol
  2. Network transport (TCP or HTTP2)
  3. Deserialize the binary stream, hand it over to the dynamic proxy with parameters such as the specified method, and get a return value (some protocols can define no return value).
  4. The return value is serialized back to the caller over the network.
  5. The caller deserializes to get the return value.

Therefore, from the above link can also be seen, the main performance can be optimized is the network transmission and serialization, deserialization.

In the network transmission, the current excellent library has Netty, the ability of children’s shoes can be on this basis to define their own protocols to achieve the communication layer.

Of course, the ones that already exist are better, such as Thrift, Dubbo, GRPC.

If we do protocol encapsulation, it is recommended to support asynchronous IO, and async mode is supported in c#, which can greatly improve throughput.

In terms of serialization performance, there is a basic priority: XML < JSON < Protobuf, thrift.

Serializing JSON with slightly larger amounts of data is a significant performance penalty, which has been tested in previous projects.

Of course, there are some features of these protocols that need to be selected for appropriate scenarios. For example, you can simply use JSON, because for Protobuf and Thrift, they all need to define IDL, which is relatively cumbersome, and of course this hassle is for performance design purposes.

🎏 03.Thrift introduction

Thrift is a software framework for the development of scalable, cross-language services. It combines a powerful software stack and code generation engine, To build in C++, Java, Python, PHP, Ruby, Erlang, Perl, Haskell, C#, Cocoa, JavaScript, node.js, Smalltalk, And OCaml programming languages seamlessly integrated, efficient services.

Originally developed by Facebook, Thrift is currently a top project of the Apache Foundation.

Thrift allows you to define a simple IDL interface file of data types and service interfaces to be used as input files for compiler generation to easily generate programming languages for RPC client and server communication.

🎏 04. Introduction to GRPC

Developed by Google, gRPC is a language-neutral, platform-neutral, open source remote procedure call (RPC) system.

GRPC uses Protobuf to define the interface so that it has more strict interface constraints. Protobuf can serialize data into binary encoding, which greatly reduces the amount of data to be transmitted and thus greatly improves performance.

GRPC uses Http 2.0 protocol, compared with webAPI which uses Http protocol in communication efficiency, it still has certain advantages.

🎏 05. Summary

In fact, there are a lot of content, I want to write more, but the strength and time do not allow, temporarily to this, what is wrong with the follow-up can also modify and add, thank you for seeing here!

Routine summary, rational view!

Knot is what, knot is I want you to like but can not get the loneliness. 😳 😳 😳

👓 all see this, still care to point a like?

👓 all points like, still care about a collection?

Do you care about a comment when you have collected 👓?