Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-455] Lazily create uncompressedData #457

Merged
merged 3 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
public class RssShuffleDataIterator<K, C> extends AbstractIterator<Product2<K, C>> {

private static final Logger LOG = LoggerFactory.getLogger(RssShuffleDataIterator.class);
private final RssConf rssConf;

private Iterator<Tuple2<Object, Object>> recordsIterator = null;
private SerializerInstance serializerInstance;
Expand All @@ -69,13 +70,7 @@ public RssShuffleDataIterator(
this.shuffleReadClient = shuffleReadClient;
this.shuffleReadMetrics = shuffleReadMetrics;
this.codec = Codec.newInstance(rssConf);
// todo: support off-heap bytebuffer
Copy link
Contributor

Choose a reason for hiding this comment

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

We would better not remove this todo comment.

this.uncompressedData = ByteBuffer.allocate(
(int) rssConf.getSizeAsBytes(
RssClientConfig.RSS_WRITER_BUFFER_SIZE,
xianjingfeng marked this conversation as resolved.
Show resolved Hide resolved
RssSparkConfig.RSS_WRITER_BUFFER_SIZE.defaultValueString()
)
);
this.rssConf = rssConf;
}

public Iterator<Tuple2<Object, Object>> createKVIterator(ByteBuffer data, int size) {
Expand Down Expand Up @@ -120,10 +115,20 @@ public boolean hasNext() {
shuffleReadMetrics.incRemoteBytesRead(compressedDataLength);

int uncompressedLen = compressedBlock.getUncompressLength();
if (uncompressedData == null || uncompressedData.capacity() < uncompressedLen) {
if (uncompressedData == null) {
// todo: support off-heap bytebuffer
uncompressedData = ByteBuffer.allocate(
(int) rssConf.getSizeAsBytes(
RssClientConfig.RSS_WRITER_BUFFER_SIZE,
Copy link
Contributor

Choose a reason for hiding this comment

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

this should be RSS_READER_BUFFER_SIZE?
And for this if block, the bufferSize should be max(readBufferSize, uncompressedLen)?

Could you add a test case for this scenario?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think the purpose of using RSS_WRITER_BUFFER_SIZE may be to avoid allocate memory for multiple times.Let's remove it.

Copy link
Member

Choose a reason for hiding this comment

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

Yes. The initial uncompressedData size is hard to set. I prefer to remove it.

RssSparkConfig.RSS_WRITER_BUFFER_SIZE.defaultValueString()
)
);
} else if (uncompressedData.capacity() < uncompressedLen) {
uncompressedData = ByteBuffer.allocate(uncompressedLen);
} else {
uncompressedData.clear();
}
uncompressedData.clear();

long startDecompress = System.currentTimeMillis();
codec.decompress(compressedData, uncompressedLen, uncompressedData, 0);
unCompressedBytesLength += compressedBlock.getUncompressLength();
Expand Down