drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From paul-rogers <...@git.apache.org>
Subject [GitHub] drill pull request #611: Drill-4800: Improve parquet reader performance
Date Fri, 04 Nov 2016 17:13:08 GMT
Github user paul-rogers commented on a diff in the pull request:

    https://github.com/apache/drill/pull/611#discussion_r86588911
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/store/parquet/columnreaders/VarLenBinaryReader.java
---
    @@ -43,43 +51,153 @@ public VarLenBinaryReader(ParquetRecordReader parentReader, List<VarLengthColumn
       public long readFields(long recordsToReadInThisPass, ColumnReader<?> firstColumnStatus)
throws IOException {
     
         long recordsReadInCurrentPass = 0;
    -    int lengthVarFieldsInCurrentRecord;
    -    long totalVariableLengthData = 0;
    -    boolean exitLengthDeterminingLoop = false;
    +
         // write the first 0 offset
         for (VarLengthColumn<?> columnReader : columns) {
           columnReader.reset();
         }
     
    +    //if(useAsyncTasks){
    +    //  recordsReadInCurrentPass = determineSizesParallel(recordsToReadInThisPass);
    +    //} else {
    +      recordsReadInCurrentPass = determineSizesSerial(recordsToReadInThisPass);
    +    //}
    +    if(useAsyncTasks){
    +      readRecordsParallel(recordsReadInCurrentPass);
    +    }else{
    +      readRecordsSerial(recordsReadInCurrentPass);
    +    }
    +    return recordsReadInCurrentPass;
    +  }
    +
    +
    +  private long determineSizesSerial(long recordsToReadInThisPass) throws IOException
{
    +    int lengthVarFieldsInCurrentRecord = 0;
    +    boolean exitLengthDeterminingLoop = false;
    +    long totalVariableLengthData = 0;
    +    long recordsReadInCurrentPass = 0;
         do {
    -      lengthVarFieldsInCurrentRecord = 0;
           for (VarLengthColumn<?> columnReader : columns) {
    -        if ( !exitLengthDeterminingLoop ) {
    -          exitLengthDeterminingLoop = columnReader.determineSize(recordsReadInCurrentPass,
lengthVarFieldsInCurrentRecord);
    +        if (!exitLengthDeterminingLoop) {
    +          exitLengthDeterminingLoop =
    +              columnReader.determineSize(recordsReadInCurrentPass, lengthVarFieldsInCurrentRecord);
             } else {
               break;
             }
           }
           // check that the next record will fit in the batch
    -      if (exitLengthDeterminingLoop || (recordsReadInCurrentPass + 1) * parentReader.getBitWidthAllFixedFields()
+ totalVariableLengthData
    -          + lengthVarFieldsInCurrentRecord > parentReader.getBatchSize()) {
    +      if (exitLengthDeterminingLoop ||
    +          (recordsReadInCurrentPass + 1) * parentReader.getBitWidthAllFixedFields()
    +              + totalVariableLengthData + lengthVarFieldsInCurrentRecord > parentReader.getBatchSize())
{
    +        break;
    +      }
    +      for (VarLengthColumn<?> columnReader : columns) {
    +        columnReader.updateReadyToReadPosition();
    +        columnReader.currDefLevel = -1;
    +      }
    +      recordsReadInCurrentPass++;
    +      totalVariableLengthData += lengthVarFieldsInCurrentRecord;
    +    } while (recordsReadInCurrentPass < recordsToReadInThisPass);
    +
    +    return recordsReadInCurrentPass;
    +  }
    +
    +
    +  public long determineSizesParallel(long recordsToReadInThisPass ) throws IOException
{
    +    boolean doneReading = false;
    +    int lengthVarFieldsInCurrentRecord = 0;
    +    boolean exitLengthDeterminingLoop = false;
    +    long totalVariableLengthData = 0;
    +    long recordsReadInCurrentPass = 0;
    +
    +    do {
    +    doneReading = readPagesParallel();
    +
    +    if (!doneReading) {
    +      lengthVarFieldsInCurrentRecord = 0;
    +      for (VarLengthColumn<?> columnReader : columns) {
    +        doneReading = columnReader.processPageData((int) recordsReadInCurrentPass);
    +        if(doneReading) {
    +          break;
    +        }
    +        lengthVarFieldsInCurrentRecord += columnReader.dataTypeLengthInBits;
    +        doneReading = columnReader.checkVectorCapacityReached();
    +        if(doneReading) {
    +          break;
    +        }
    +      }
    +    }
    +
    +    exitLengthDeterminingLoop = doneReading;
    +
    +      // check that the next record will fit in the batch
    +      if (exitLengthDeterminingLoop ||
    +          (recordsReadInCurrentPass + 1) * parentReader.getBitWidthAllFixedFields()
    +              + totalVariableLengthData + lengthVarFieldsInCurrentRecord > parentReader.getBatchSize())
{
             break;
           }
    -      for (VarLengthColumn<?> columnReader : columns ) {
    +      for (VarLengthColumn<?> columnReader : columns) {
             columnReader.updateReadyToReadPosition();
             columnReader.currDefLevel = -1;
           }
           recordsReadInCurrentPass++;
           totalVariableLengthData += lengthVarFieldsInCurrentRecord;
         } while (recordsReadInCurrentPass < recordsToReadInThisPass);
     
    +    return recordsReadInCurrentPass;
    +  }
    +
    +  public boolean readPagesParallel() {
    +
    +    boolean isDone = false;
    +    ArrayList<Future<Boolean>> futures = Lists.newArrayList();
    +    for (VarLengthColumn<?> columnReader : columns) {
    +      Future<Boolean> f = columnReader.readPageAsync();
    +      futures.add(f);
    +    }
    +    for (Future<Boolean> f : futures) {
    +      try {
    +        isDone = isDone || f.get().booleanValue();
    +      } catch (Exception e) {
    +        f.cancel(true);
    +        handleAndRaise(null, e);
    +      }
    +    }
    +    return isDone;
    +  }
    +
    +
    +  private void readRecordsSerial(long recordsReadInCurrentPass) {
         for (VarLengthColumn<?> columnReader : columns) {
           columnReader.readRecords(columnReader.pageReader.valuesReadyToRead);
         }
         for (VarLengthColumn<?> columnReader : columns) {
    -      columnReader.valueVec.getMutator().setValueCount((int) recordsReadInCurrentPass);
    +      columnReader.valueVec.getMutator().setValueCount((int)recordsReadInCurrentPass);
         }
    -    return recordsReadInCurrentPass;
    +  }
    +
    +  private void readRecordsParallel(long recordsReadInCurrentPass){
    +    ArrayList<Future<Integer>> futures = Lists.newArrayList();
    +    for (VarLengthColumn<?> columnReader : columns) {
    +      Future<Integer> f = columnReader.readRecordsAsync(columnReader.pageReader.valuesReadyToRead);
    +      futures.add(f);
    +    }
    +    for (Future f : futures) {
    +      try {
    +        f.get();
    +      } catch (Exception e) {
    +        f.cancel(true);
    --- End diff --
    
    Ditto about future failure handling.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message