Understanding Dubbo’s Network Transport Layer and Hessian2 Serialization

This article explains Dubbo’s network transport architecture, the Dubbo protocol with Hessian2 serialization, details the encoding/decoding process using Netty, and proposes optimization techniques such as reducing array copies, leveraging Netty 4 decoders, compressing binary data, and adopting alternative high‑performance serialization formats.

Qunar Tech Salon
Qunar Tech Salon
Qunar Tech Salon
Understanding Dubbo’s Network Transport Layer and Hessian2 Serialization

1. Dubbo Network Transport Layer

Dubbo’s transport layer depends on the serialization layer and handles one‑way message transmission. When a consumer calls a provider, method names and parameters are sent as binary data, decoded by a unified protocol, allowing upper‑level models to work with objects without worrying about transport details.

The transport layer supports multiple protocols (Dubbo, RMI, Hessian, WebService, HTTP) and serialization methods (Hessian2, dubbo, JSON, Java native).

2. Dubbo Protocol

Dubbo uses its own protocol with a fixed‑length header and variable‑length body; the header records serialization type, request status, and data length, while the body contains the serialized request/response object.

When Netty is the transport framework, the client and server correspond to NettyClient and NettyServer. The default codec is DubboCountCodec, whose inner DubboCodec implements the protocol’s encode/decode logic.

During a request, the consumer’s parameters are encoded by InternalEncoder before being sent.

On the provider side, InternalDecoder assembles possibly fragmented packets into a complete Dubbo protocol message using an internal ChannelBuffer, then decodes it.

Because Netty may deliver incomplete or multiple Dubbo packets, InternalDecoder uses a buffer to handle both scenarios, rolling back the read index when more input is needed.

3. Hessian2 Serialization Protocol

Hessian2, an open‑source binary serialization protocol from Caucho, is used by Dubbo via the com.alibaba.caucho.hessian.io package. After the Dubbo header is processed, objects are serialized/deserialized with Hessian2Output and Hessian2Input.

3.1 String Serialization and Deserialization

Strings dominate the binary payload. Hessian2 encodes characters in UTF‑8, splitting long strings into chunks marked by ‘S’ (final chunk) or ‘R’ (non‑final chunk), each followed by a 16‑bit length indicating character count.

During serialization, Hessian2Output.printString iterates over characters, writes encoded bytes to a buffer; during deserialization, Hessian2Input.readString parses the marker, reads the length, and reconstructs characters via parseChar / parseUTF8Char.

4. Optimization Points

4.1 Reduce Array Copies

Dubbo’s InternalDecoder copies the packet into a ChannelBuffer, which is then copied again by HessianInput. Removing the internal 256‑byte cache in HessianInput and deserializing directly from the ChannelBuffer eliminates redundant copies.

4.2 Use Netty 4 ByteToMessageDecoder

Netty 4’s ByteToMessageDecoder provides a reusable cumulation buffer, reducing memory copies and simplifying decoder code; Dubbo’s decoder can be refactored to extend this class for better performance.

4.3 Compress Binary Data

Hessian2 supports compression. In a test, raw Java serialization produced 10 320 bytes, Hessian2 6 844 bytes, and compressed Hessian2 3 915 bytes (57 % of uncompressed). Compression roughly doubles serialization time, so it should be used only when network bandwidth is a bottleneck.

4.4 Choose Alternative Serialization

Newer serializers such as Kryo, FST (Java‑only) and cross‑language formats like ProtoBuf or Thrift outperform Hessian2. Projects like Dubbox already replace Hessian2 with Kryo/FST to boost Dubbo performance.

5. References

Dubbo‑2.5.4 – GitHub Dubbo Protocol Reference – dubbo.io Hessian Serialization – caucho.com Dubbox Serialization Benchmarks – dangdangdotcom.github.io
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

backendPerformanceRPCDubboserializationNettyhessian2
Qunar Tech Salon
Written by

Qunar Tech Salon

Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.