-
Notifications
You must be signed in to change notification settings - Fork 62
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
793a132
70d6a07
ecbdc00
1b6f6e6
88b5a82
c03cd51
28a919e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,7 @@ | |
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.apache.hadoop.io.compress.CodecPool; | ||
import org.apache.hadoop.io.compress.CompressionCodec; | ||
import org.apache.hadoop.io.compress.CompressionInputStream; | ||
import org.apache.hadoop.io.compress.CompressionOutputStream; | ||
|
@@ -86,7 +87,16 @@ public CompressionInputStream createInputStream(InputStream in, | |
|
||
@Override | ||
public CompressionInputStream createInputStream(InputStream in) throws IOException { | ||
return createInputStream(in, createDecompressor()); | ||
// Ensure native-lzo library is loaded & initialized | ||
if (!isNativeLzoLoaded(getConf())) { | ||
throw new RuntimeException("native-lzo library not available"); | ||
} | ||
/*create a decompressor and tell LzoInputStream to reuse it | ||
* (return it to the pool when LzoInputStream is closed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing closing paren |
||
*/ | ||
|
||
return new LzopInputStream(in, CodecPool.getDecompressor(this), | ||
getConf().getInt(LZO_BUFFER_SIZE_KEY, DEFAULT_LZO_BUFFER_SIZE), true); | ||
} | ||
|
||
@Override | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ | |
import org.apache.commons.logging.Log; | ||
import org.apache.commons.logging.LogFactory; | ||
import org.apache.hadoop.io.compress.BlockDecompressorStream; | ||
import org.apache.hadoop.io.compress.CodecPool; | ||
import org.apache.hadoop.io.compress.Decompressor; | ||
|
||
public class LzopInputStream extends BlockDecompressorStream { | ||
|
@@ -47,11 +48,18 @@ public class LzopInputStream extends BlockDecompressorStream { | |
private int noUncompressedBytes = 0; | ||
private int noCompressedBytes = 0; | ||
private int uncompressedBlockSize = 0; | ||
private boolean reuseDecompressor; | ||
|
||
public LzopInputStream(InputStream in, Decompressor decompressor, | ||
int bufferSize) throws IOException { | ||
this(in, decompressor, bufferSize, false); | ||
} | ||
|
||
|
||
public LzopInputStream(InputStream in, Decompressor decompressor, int bufferSize, boolean reuseDecompressor) throws IOException { | ||
super(in, decompressor, bufferSize); | ||
readHeader(in); | ||
this.reuseDecompressor = reuseDecompressor; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is there any reason not to reuse it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Raghu and I discussed this. We thought that if the decompressor was not created explicitly by us, then we don't reuse it. No other particular reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just in case if the user could do some thing that affect the decompressor after we added to the pool for reuse. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, we thought LzopInputFormat should put it back CodecPool only it created. |
||
} | ||
|
||
|
||
|
@@ -83,7 +91,7 @@ private static void readFully( InputStream in, byte buf[], | |
* Read len bytes into buf, st LSB of int returned is the last byte of the | ||
* first word read. | ||
*/ | ||
private static int readInt(InputStream in, byte[] buf, int len) | ||
private static int readInt(InputStream in, byte[] buf, int len) | ||
throws IOException { | ||
readFully(in, buf, 0, len); | ||
int ret = (0xFF & buf[0]) << 24; | ||
|
@@ -331,6 +339,8 @@ public void close() throws IOException { | |
decompressor.decompress(b, 0, b.length); | ||
} | ||
super.close(); | ||
if(reuseDecompressor) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be done after 'verifyChecksum'. (in a finally clause, to be safe). |
||
CodecPool.returnDecompressor(decompressor); | ||
try { | ||
verifyChecksums(); | ||
} catch (IOException e) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you need this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's to be consistent with the other function createInputStream(in).
On Tue, Apr 24, 2012 at 10:20 AM, Raghu Angadi <
reply@reply.github.com
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the check !isNativeLzoLoaded(getConf() in both
createInputStream() functions since both will call createDecompressor()
eventually and createDecompressor() checks !isNativeLzoLoaded.
On Tue, Apr 24, 2012 at 10:22 AM, Yu Xu yu@twitter.com wrote:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, you can keep the check. just make the other createInputStream() invoke this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We couldn't make createInputStream(in) to invoke createInputStream(in,
decompressor) because we need to pass a flag to LzopInputStream constructor
tell it whether it needs to return/reuse the decompressor. The reason we
had to introduce a new flag in LzopInputStream's constructor was discussed
yesterday that we cannot create a decompressor in LzopInputStream's
constructor before the super.() call.
On Tue, Apr 24, 2012 at 11:36 AM, Raghu Angadi <
reply@reply.github.com