Fundamentals 6 min read

Understanding DBLE Network Module: TCP/IP Stack, MySQL Protocol, and BIO vs NIO

This article introduces the fundamentals of network I/O for the DBLE database system, covering the TCP/IP protocol stack, the MySQL application‑layer protocol, and the performance differences between BIO and NIO approaches, laying the groundwork for deeper source‑code analysis.

Aikesheng Open Source Community
Aikesheng Open Source Community
Aikesheng Open Source Community
Understanding DBLE Network Module: TCP/IP Stack, MySQL Protocol, and BIO vs NIO

Preface

For computer science, knowledge of computer networking is essential. While many developers focus on high‑level frameworks, low‑level network I/O handling is crucial for middleware and framework developers. DBLE's network module is written entirely with native JDK code, and studying its source helps understand high‑performance network I/O.

This article is the first in the "DBLE Network Module Source Code Analysis" series and explains basic network I/O concepts.

1. TCP/IP Protocol Stack

The TCP/IP protocol simplifies the OSI model’s seven layers into four: link, network, transport, and application. Data is encapsulated layer by layer, as illustrated below.

Each upper‑layer protocol’s data becomes the payload for the next lower layer, forming a layered encapsulation structure.

2. MySQL Protocol

The MySQL protocol operates at the application layer of the TCP/IP stack, meaning its data is carried as the TCP payload. Because TCP is a stream‑oriented protocol, it suffers from packet‑sticking (粘包) and splitting (拆包) issues that must be resolved at the application layer.

Common solutions include:

Fixed‑length messages.

Delimiter characters (e.g., carriage return).

Message headers that specify total length.

More complex application‑layer protocols.

MySQL solves the problem by using fixed‑length messages combined with a length field in the header, as shown below.

https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_basic_packets.html

Since DBLE can connect like a MySQL client, it must be able to parse MySQL packets; the handling logic will be explored in later source‑code analyses.

3. BIO and NIO

DBLE achieves high performance through high‑efficiency network I/O. It uses NIO (non‑blocking I/O) with I/O multiplexing for both front‑end client connections and back‑end MySQL connections.

When connection counts are low, a BIO + multi‑threaded approach can be fast, but as connections grow, thread‑switching overhead outweighs the benefits, degrading performance.

NIO, by contrast, allows a small number of threads to manage many connections without creating a dedicated thread per connection, and combined with asynchronous request processing, it forms the secret of DBLE’s high performance.

Next Issue Preview

This article covered basic network I/O concepts—TCP/IP stack, MySQL protocol, and BIO/NIO—preparing readers for the next piece, which will dive into DBLE’s actual network handling source code.

backendNetworkNIOMySQLTCP/IPBIO
Aikesheng Open Source Community
Written by

Aikesheng Open Source Community

The Aikesheng Open Source Community provides stable, enterprise‑grade MySQL open‑source tools and services, releases a premium open‑source component each year (1024), and continuously operates and maintains them.

0 followers
Reader feedback

How this landed with the community

login 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.