Skip to content

Optimize pipe request serialization buffer sizing#18233

Open
luoluoyuyu wants to merge 2 commits into
apache:masterfrom
luoluoyuyu:pipe-tablet-serialization-size
Open

Optimize pipe request serialization buffer sizing#18233
luoluoyuyu wants to merge 2 commits into
apache:masterfrom
luoluoyuyu:pipe-tablet-serialization-size

Conversation

@luoluoyuyu

Copy link
Copy Markdown
Member

Description


This PR has:

  • been self-reviewed.
    • concurrent read
    • concurrent write
    • concurrent read and write
  • added documentation for new or modified features or behaviors.
  • added Javadocs for most classes and all non-trivial methods.
  • added or updated version, license, or notice information
  • added comments explaining the "why" and the intent of the code wherever would not be obvious
    for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold
    for code coverage.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR

@luoluoyuyu
luoluoyuyu force-pushed the pipe-tablet-serialization-size branch from 44dc635 to 793b0a6 Compare July 17, 2026 06:45

@jt2594838 jt2594838 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May add some performance results.


static int calculateSerializedSize(
final List<ByteBuffer> insertNodeBuffers, final List<ByteBuffer> tabletBuffers) {
return Integer.BYTES * 3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments to explain what the 3 is. The same below.

Comment on lines +155 to +160
static int calculateSerializedSize(
final List<ByteBuffer> insertNodeBuffers, final List<ByteBuffer> tabletBuffers) {
return Integer.BYTES * 3
+ insertNodeBuffers.stream().mapToInt(ByteBuffer::limit).sum()
+ tabletBuffers.stream().mapToInt(ByteBuffer::limit).sum();
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to use limit - position.
Where are the sizes of the buffers recorded? The sizes do not seem to be counted in the size.

Comment on lines +168 to +170
private static int serializedStringSize(final String value) {
return Integer.BYTES + (value == null ? 0 : value.getBytes(TSFileConfig.STRING_CHARSET).length);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move to a util.

Comment on lines -89 to +96
req.body = insertNode.serializeToByteBuffer();
try (final PublicBAOS byteArrayOutputStream =
new PublicBAOS(calculateSerializedSize(insertNode));
final DataOutputStream outputStream = new DataOutputStream(byteArrayOutputStream)) {
insertNode.serialize(outputStream);
req.body = ByteBuffer.wrap(byteArrayOutputStream.getBuf(), 0, byteArrayOutputStream.size());
} catch (final IOException e) {
throw new RuntimeException(e);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May pass the size to serializeToByteBuffer().
It would be even better to let the InsertNode handle this itself.

Comment on lines +283 to +290
@Override
protected int serializedAttributesSize() {
int size = PlanNodeType.BYTES + Integer.BYTES;
for (final InsertTabletNode insertTabletNode : insertTabletNodeList) {
size += insertTabletNode.baseSubSerializedSizeForPipe();
}
return size + parentInsertTabletNodeIndexList.size() * Integer.BYTES;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels weird that this method does not seem to be made for Pipe exclusively, but it calls a method that seems to be.

Check the consistency of semantics and rename methods accordingly.

Comment on lines +392 to +412
switch (dataType) {
case BOOLEAN:
return Byte.BYTES + Byte.BYTES;
case INT32:
case DATE:
return Byte.BYTES + Integer.BYTES;
case INT64:
case TIMESTAMP:
return Byte.BYTES + Long.BYTES;
case FLOAT:
return Byte.BYTES + Float.BYTES;
case DOUBLE:
return Byte.BYTES + Double.BYTES;
case TEXT:
case STRING:
case BLOB:
case OBJECT:
return Byte.BYTES + ReadWriteIOUtils.sizeToWrite((Binary) values[index]);
default:
throw new UnSupportedDataTypeException(UNSUPPORTED_DATA_TYPE + dataType);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use enhanced-switch and explicitly list all branches.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use org.apache.tsfile.enums.TSDataType#getDataTypeSize

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May consider caching the serialized size to avoid duplicated calculation when serialization is called multiple times.

Comment on lines +585 to +586
size += Integer.BYTES;
size += Byte.BYTES;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add some comments for these. The same below.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants