Skip to content
This repository has been archived by the owner on Oct 16, 2024. It is now read-only.

DL-45: DL should allow ByteBuffer based API and should avoid copying of arrays #21

Closed
wants to merge 2 commits into from

Conversation

arvindkandhare
Copy link
Contributor

This needs the bookkeeper pull request twitter-archive/bookkeeper#4 to be integrated first. Let's review both and then plan a commit plan.

@sijie
Copy link
Member

sijie commented Sep 10, 2016

the overall change looks good. Let me take a look at the bk change and plan how to merge this. @arvindkandhare

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantLock;

Copy link
Member

Choose a reason for hiding this comment

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

This looks good, just curious, What is the purpose to move this part down? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing specific :). I think my editor just sorted all the imports.

@sijie
Copy link
Member

sijie commented Nov 1, 2016

@arvindkandhare is the twitter/bookkeeper#4 change finalized?

@arvindkandhare
Copy link
Contributor Author

@sijie The BK changes are final and ready to be checked in once you are satisfied with them. This particular pull request still needs a couple of changes.

@sijie
Copy link
Member

sijie commented Nov 15, 2016

@arvindkandhare @jiazhai I will merge the bk change and produce a new version this week.

Copy link
Contributor

@leighst leighst left a comment

Choose a reason for hiding this comment

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

high level question - it looks like all of the savings come from avoiding ByteArrayOutputStream - is that correct?

this.payload = new byte[length];
in.readFully(payload);
this.payload = ByteBuffer.wrap(new byte[length]);
//TODO: Fix this
Copy link
Contributor

Choose a reason for hiding this comment

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

what do you want to fix here?

@@ -290,7 +290,8 @@ public static InputStream fromInputStream(InputStream src,
src.reset();
EnvelopedEntry entry = new EnvelopedEntry(version, statsLogger);
entry.readFully(new DataInputStream(src));
return new ByteArrayInputStream(entry.getDecompressedPayload());
return new ByteArrayInputStream(entry.getDecompressedPayload().array());
Copy link
Contributor

Choose a reason for hiding this comment

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

i think im missing something here, but it seems like a bad idea to use direct array access since the payload object could have been initialized with a ByteBuffer from anywhere. is this safe?

int dataOffset = HEADER_LEN;
int dataLen = buffer.size() - HEADER_LEN;

if (COMPRESSION_CODEC_LZ4 != codecCode) {
ByteBuffer recordSetBuffer = ByteBuffer.wrap(data, 0, buffer.size());
ByteBuffer recordSetBuffer = data;
Copy link
Contributor

Choose a reason for hiding this comment

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

i think it would be cleaner if you duplicate() the buffer.. its a little confusing to simply create a new reference.

this.payload = new byte[length];
in.readFully(payload);
this.payload = ByteBuffer.wrap(new byte[length]);
//TODO: Fix this
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@leighst The existing Stream based implementation in buffer.java involved an avoidable byte array copy. This change request is to fix this. We realized that this can be done in a better way. I/@jiazhai will update the pull request with the latest changes.

Copy link
Member

Choose a reason for hiding this comment

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

will sync with Arvind to get this done.

@sijie
Copy link
Member

sijie commented Jan 5, 2017

@arvindkandhare @jiazhai I was experimenting using netty-buffer for memory allocation and management. I got pretty good performance results on it. I will try to share more details with numbers in a few days. /cc @leighst

@asfbot
Copy link

asfbot commented Jan 5, 2017

Refer to this link for build results (access rights to CI server needed):
https://builds.apache.org/job/distributedlog-precommit-pullrequest/71/
--none--

@sijie
Copy link
Member

sijie commented Aug 15, 2017

in bookkeeper 4.5, the netty bytebuf is introduced, we might consider using bytebuf there to better integrate with the new bytebuf api.

@sijie
Copy link
Member

sijie commented Aug 18, 2017

closed this pull request since DL is using BK 4.5 now. we will pick up the ByteBuf API rather than ByteBuffer API here.

@sijie sijie closed this Aug 18, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants