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

reuse decompressor to reduce memory consumption #1

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

yuxutw
Copy link

@yuxutw yuxutw commented Apr 23, 2012

currently we create a new decompressor for each lzo RecordReader. Each lzo decompressor currently uses 0.5MB memory(two 256K buffers) and we can run out of memory when we create many lzo record readers.

@@ -331,6 +339,8 @@ public void close() throws IOException {
decompressor.decompress(b, 0, b.length);
}
super.close();
if(reuseDecompressor)
Copy link

Choose a reason for hiding this comment

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

should be done after 'verifyChecksum'. (in a finally clause, to be safe).

@rangadi
Copy link

rangadi commented Apr 24, 2012

+1. thanks Yu.

@@ -86,7 +87,11 @@ public CompressionInputStream createInputStream(InputStream in,

@Override
public CompressionInputStream createInputStream(InputStream in) throws IOException {
return createInputStream(in, createDecompressor());
/* create a decompressor and tell LzoInputStream to reuse it
* (return it to the pool when LzoInputStream is closed.

Choose a reason for hiding this comment

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

missing closing paren

yuxutw added 2 commits April 24, 2012 16:15
simplify decompressor reuse (reuse decompressors for both cases)
@@ -111,6 +112,9 @@ public void close() throws IOException {
}
closed = true;
}
//return the compressor to the pool for later reuse;
//the returnCompressor handles nulls.
CodecPool.returnCompressor(compressor);
Copy link

Choose a reason for hiding this comment

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

for correctness, this should be inside 'if (!closed)' check.

@rangadi
Copy link

rangadi commented Apr 25, 2012

+1. thanks for multiple iterations.

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.

3 participants