DL-45: DL should allow ByteBuf based API to avoid copying bytes array#151
DL-45: DL should allow ByteBuf based API to avoid copying bytes array#151sijie wants to merge 19 commits intoapache:masterfrom
Conversation
- registerSuccessEvent and registerFailureEvent needs TimeUnit - change HashedWheelTimer to netty 4 - change channelFactory to eventLoopGroup
|
/cc @leighst for review This change doesn't include any benchmark result. I will have a subsequent change to have a micro-benchmark result to compare the serialization/deserialization performance. |
eolivelli
left a comment
There was a problem hiding this comment.
Great improvement, basically it is the switch to pooled and reference counted bytebufs
| } | ||
|
|
||
| @Override | ||
| protected void finalize() throws Throwable { |
There was a problem hiding this comment.
Just to be curious, why are you using finalize?
I think that finalize is bad and legacy mechanism in Java and could lead in general to problems
There was a problem hiding this comment.
I know finalize is not a reliable and recommended way to release resource. However if I don't do finalize, there is no other way for me to release resources. or I have to change every classes that explicitly release the byte buf, this is going to a big change. also it is going to hard to change public structure like LogRecord to release references. it is going to break the API.
I will have a subsequent change to improve this. because I don't want to mix them in a big pull request.
There was a problem hiding this comment.
+1 on this, seems like its not something we should do lightly
how are you planning to solve it?
hellostreaming
left a comment
There was a problem hiding this comment.
+1.
Thanks for the great work.
| EnvelopedEntry entry = new EnvelopedEntry(version, statsLogger); | ||
| entry.readFully(new DataInputStream(src)); | ||
| return new ByteArrayInputStream(entry.getDecompressedPayload()); | ||
| public static ByteBuf fromEnvlopedBuf(ByteBuf src, StatsLogger statsLogger) |
| } | ||
| int flags = src.readInt(); | ||
| int codecCode = flags & COMPRESSION_CODEC_MASK; | ||
| int originDataLen = src.readInt(); |
| this.buffer = new Buffer(initialBufferSize * 6 / 5); | ||
| this.writer = new LogRecord.Writer(new DataOutputStream(buffer)); | ||
| this.buffer = PooledByteBufAllocator.DEFAULT.buffer( | ||
| Math.min(Math.max(initialBufferSize * 6 / 5, HEADER_LENGTH), MAX_LOGRECORDSET_SIZE), |
There was a problem hiding this comment.
I don't remember what was exactly the reason that we used *6/5. We can probably remove it.
|
|
||
| if (Type.NONE == codec) { | ||
| // update version | ||
| buffer.setByte(0, CURRENT_VERSION); |
There was a problem hiding this comment.
can you avoid these magic numbers and use constants or field size variables? or a relative setter? (set(dataLen))
There was a problem hiding this comment.
added CONSTANTS for the offsets.
| } | ||
|
|
||
| @Override | ||
| protected void finalize() throws Throwable { |
There was a problem hiding this comment.
+1 on this, seems like its not something we should do lightly
how are you planning to solve it?
| @@ -184,7 +192,23 @@ protected void setTransactionId(long txid) { | |||
| * @return payload of this log record. | |||
| */ | |||
| public byte[] getPayload() { | |||
There was a problem hiding this comment.
why is this still necessary? back compat?
There was a problem hiding this comment.
I kept it there for back compat.
|
@leighst : I address your comments. also removed the #finalize() approach.
|
|
FYI. the new compression codec shows much better result. this patch: 0.4.0-incubating |
Descriptions of the changes in this PR:
This change leverages the
ByteBufapi introduced in bookkeeper 4.5.0. It will avoid copying bytes array between LogRecord and LogRecordSet/Entry, and avoid copying bytes from DL to BK client.This change also bump the lz4 library to
1.3.0to leverage theByteBufferbinding.