Which Dubbo serialization protocol support? Hessian data structure? What is PB? Why PB efficiency is the highest?

Interview questions

dubbo which communications protocol support? What serialization protocol support? Talk about the data structure of the Hessian? PB know? Why PB efficiency is the highest?

Interviewer psychological analysis

On a question, talk about the basic working principle dubbo, and that is what you need to know, at least you know what layer dubbo divided, how then usually initiated rpc request, registration, discovery, access, these are basic.

Then you can ask a depth, such as the first step will be to ask the sequence of this agreement, it is how to go the usual time for the underlying RPC?

Face questions analysis

Serialization is the number of data structures or objects, converted into a binary string process, the deserialization is converted during serialization binary string generated in the object into a data structure or process.

dubbo support different communication protocols

  • dubbo agreement

The default is to take dubbo protocol, a single long connection, NIO asynchronous communication is carried out, based on the sequence agreement as hessian. Scenario is used: a small amount of data transfer (per request within 100kb), but the high concurrency.

In order to support high-concurrency scenarios, usually service providers on several machines, but there are hundreds of service consumers, may call amounted to hundreds of millions of times a day! This time with a long connection is the most appropriate, with each service is to maintain a long consumers can be connected, it may total of 100 connections. Then NIO connected directly behind the length-based asynchronous communication, may support high concurrent requests.

Long connection, popular point that is to establish a connection persists after sending a request, no need to establish a connection.

The short connection every time you want before sending the request, you need to re-establish a connection.

  • rmi protocol

Go Java binary serialization, multiple short connection, for a similar number of consumers and providers of circumstances, apply to transfer files, usually with less.

  • hessian agreement

Take hessian serialization protocol, a plurality of short connection, it is further adapted to provide the number of consumers more than the number of cases for file transfers, usually less used.

  • http protocol

Go json serialization.

  • webservice

走 SOAP 文本序列化。

dubbo 支持的序列化协议

dubbo 支持 hession、Java 二进制序列化、json、SOAP 文本序列化多种序列化协议。但是 hessian 是其默认的序列化协议。

说一下 Hessian 的数据结构

Hessian 的对象序列化机制有 8 种原始类型:

  • 原始二进制数据
  • boolean
  • 64-bit date(64 位毫秒值的日期)
  • 64-bit double
  • 32-bit int
  • 64-bit long
  • null
  • UTF-8 编码的 string

另外还包括 3 种递归类型:

  • list for lists and arrays
  • map for maps and dictionaries
  • object for objects

还有一种特殊的类型:

  • ref:用来表示对共享对象的引用。

为什么 PB 的效率是最高的?

可能有一些同学比较习惯于 JSON or XML 数据存储格式,对于 Protocol Buffer 还比较陌生。Protocol Buffer 其实是 Google 出品的一种轻量并且高效的结构化数据存储格式,性能比 JSONXML 要高很多。

其实 PB 之所以性能如此好,主要得益于两个:第一,它使用 proto 编译器,自动进行序列化和反序列化,速度非常快,应该比 XML 和 JSON 快上了 20~100 倍;第二,它的数据压缩效果好,就是说它序列化后的数据量体积小。因为体积小,传输起来带宽和速度上会有优化。

 

Guess you like

Origin blog.csdn.net/u014513171/article/details/93160950