avro-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thiruvalluvan M. G. (JIRA)" <j...@apache.org>
Subject [jira] Commented: (AVRO-392) Binary Decoder Performance and flexibility overhaul
Date Sat, 06 Feb 2010 03:59:27 GMT

    [ https://issues.apache.org/jira/browse/AVRO-392?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12830449#action_12830449

Thiruvalluvan M. G. commented on AVRO-392:

bq. Can anyone come up with a use case where inputStream() combined with remaining() to detect
how far ahead it read and the means to retrieve those bytes, is not sufficient?

private GenericDatumReader<X> reader;
int f(InputStream in) {
    if (some_condition) {
         BinaryDecoder d = new BinaryDecoder(in);
         X x = reder.read(null, d);
         return f2(x);
    } else {
        // Do something else with in.
        return 100;

void f2(InputStream in) {
    if (some_condition) {
    // dome something more with in.

Now the decision to do use Avro is local to f(). But to make it work with the overshoot-Binary
decoder, it must somehow return a new InputStream.  For the same reason, f2, which is not
even aware of Avro, must return an InputStream. If the InputStream gets passed for n levels,
all n levels should somehow return the new InputStream, which I think is a pain.

If the original InputStream is a field in a class, it cannot be final.

Assume that one is willing to return InputStream all the way. This InputStream is actually
InputStreamByteSource. The further users of this inputstream will go though additional function
call overhead due to InputStreamByteSource for the rest of its lifetime. With the current
implementation, it means single-byte IO.

If Avro is a small part of project, it would pollute the design for small performance improvement
for them. With the old BinaryDecoder, they have a choice - clean interface or performance.

Agreed InputStream is bad for performance and people should not use it, if they can. But it
is the most common binary input interface in Java and is not going to go away anytime soon.

Bq. One option is to make a "DirectBinaryDecoder" class that has the same capabilities as
the old one, and supports only InputStream construction.
Name doesn't matter to me. You can trivially support init(byte[], int, int) with a ByteArrayInputStream.
We could move out the inputStream() method out of Decoder.

> Binary Decoder Performance and flexibility overhaul
> ---------------------------------------------------
>                 Key: AVRO-392
>                 URL: https://issues.apache.org/jira/browse/AVRO-392
>             Project: Avro
>          Issue Type: Improvement
>          Components: java
>            Reporter: Scott Carey
>            Assignee: Scott Carey
>            Priority: Critical
>             Fix For: 1.3.0
>         Attachments: AVRO-392-preview.patch, AVRO-392.patch, AVRO-392.patch, AVRO-392.patch
> BinaryDecoder has room for significant performance improvement.  [AVRO-327|https://issues.apache.org/jira/browse/AVRO-327]
has some preliminary work here, but in order to satisfy some use cases there is much more
work to do.
> I am opening a new ticket because the scope of the changes needed to do this the right
way are larger.
> I have done a large bulk of a new implementation that abstracts a 'ByteSource' from the
BinaryDecoder.  Currently BinaryDecoder is tightly coupled to InputStream.  The ByteSource
can wrap an InputStream, FileChannel, or byte[] in this version, but could be extended to
support other channel types, sockets, etc.  This abstraction allows the BinaryDecoder to buffer
data from various sources while supporting interleaved access to the underlying data and greater
flexibility going forward.
> The performance of this abstraction has been heavily tuned so that maximum performance
can be achieved even for slower ByteSource implementations.
> For readers that must interleave reads on a stream with the decoder, this includes a
> {code}
> public InputStream inputStream();
> {code}
> method on the decoder that can serve interleaved reads.  
> Additionally it will be necessary to have a constructor on BinaryDecoder that allows
two BinaryDecoders to share a stream (and buffer).
> Performance results on this new version is better than previous prototypes:
> *current trunk BinaryDecoder*
> {noformat}
> ReadInt: 983 ms, 30.497877855999185 million entries/sec
> ReadLongSmall: 1058 ms, 28.336666040111496 million entries/sec
> ReadLong: 1518 ms, 19.75179889508437 million entries/sec
> ReadFloat: 657 ms, 45.61031157924184 million entries/sec
> ReadDouble: 761 ms, 39.387756709704355 million entries/sec
> ReadBoolean: 331 ms, 90.4268145647456 million entries/sec
> RepeaterTest: 7718 ms, 3.886725782038378 million entries/sec
> NestedRecordTest: 1884 ms, 15.91964611687992 million entries/sec
> ResolverTest: 8296 ms, 3.616055866616717 million entries/sec
> MigrationTest: 21216 ms, 1.4139999570144013 million entries/sec
> {noformat}
> *buffering BinaryDecoder*
> {noformat}
> ReadInt: 187 ms, 160.22131904871262 million entries/sec
> ReadLongSmall: 372 ms, 80.4863521975457 million entries/sec
> ReadLong: 613 ms, 48.882385721129246 million entries/sec
> ReadFloat: 253 ms, 118.16606270679061 million entries/sec
> ReadDouble: 275 ms, 108.94314257389068 million entries/sec
> ReadBoolean: 222 ms, 134.85327963176064 million entries/sec
> RepeaterTest: 3335 ms, 8.993007936329503 million entries/sec
> NestedRecordTest: 1152 ms, 26.0256943004597 million entries/sec
> ResolverTest: 4213 ms, 7.120659335077578 million entries/sec
> MigrationTest: 15310 ms, 1.9594884898992941 million entries/sec
> {noformat}
> Performance is 2x to 5x the throughput of trunk on most tests.  

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message