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
Open
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
Binary file added ivy/ivy-2.2.0.jar
Binary file not shown.
12 changes: 11 additions & 1 deletion src/java/com/hadoop/compression/lzo/LzopCodec.java
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())) {
Copy link

Choose a reason for hiding this comment

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

do you need this?

Copy link
Author

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

wrote:

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

@OverRide
public CompressionInputStream
src/java/com/twitter/elephantbird/mapreduce/input/LzoBinaryBlockRecordReader.java(InputStream
in) throws IOException {

  • return createInputStream(in, createDecompressor());
  • // Ensure native-lzo library is loaded & initialized
  • if (!isNativeLzoLoaded(getConf())) {

do you need this?


Reply to this email directly or view it on GitHub:
https://github.com/kevinweil/hadoop-lzo/pull/1/files#r727564

Copy link
Author

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:

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

wrote:

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

@OverRide
public CompressionInputStream
src/java/com/twitter/elephantbird/mapreduce/input/LzoBinaryBlockRecordReader.java(InputStream
in) throws IOException {

  • return createInputStream(in, createDecompressor());
  • // Ensure native-lzo library is loaded & initialized
  • if (!isNativeLzoLoaded(getConf())) {

do you need this?


Reply to this email directly or view it on GitHub:
https://github.com/kevinweil/hadoop-lzo/pull/1/files#r727564

Copy link

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.

Copy link
Author

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

wrote:

@@ -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())) {

I see, you can keep the check. just make the other createInputStream()
invoke this one.


Reply to this email directly or view it on GitHub:
https://github.com/kevinweil/hadoop-lzo/pull/1/files#r728050

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.

Choose a reason for hiding this comment

The 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
12 changes: 11 additions & 1 deletion src/java/com/hadoop/compression/lzo/LzopInputStream.java
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;

Choose a reason for hiding this comment

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

is there any reason not to reuse it?

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link
Author

Choose a reason for hiding this comment

The 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.

Copy link

Choose a reason for hiding this comment

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

yeah, we thought LzopInputFormat should put it back CodecPool only it created.
actually it would just fine to always reuse. It will simplify the patch a lot. That way we can add the same for LzopOutputFormat as well.

}


@@ -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)
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).

CodecPool.returnDecompressor(decompressor);
try {
verifyChecksums();
} catch (IOException e) {