You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@flink.apache.org by GitBox <gi...@apache.org> on 2022/09/14 02:30:58 UTC

[GitHub] [flink] jiangjiguang opened a new pull request, #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

jiangjiguang opened a new pull request, #20830:
URL: https://github.com/apache/flink/pull/20830

   <!--
   *Thank you very much for contributing to Apache Flink - we are happy that you want to help us improve Flink. To help the community review your contribution in the best possible way, please go through the checklist below, which will get the contribution into a shape in which it can be best reviewed.*
   
   *Please understand that we do not do this to make contributions to Flink a hassle. In order to uphold a high standard of quality for code contributions, while at the same time managing a large number of contributions, we need contributors to prepare the contributions well, and give reviewers enough contextual information for the review. Please also understand that contributions that do not follow this guide will take longer to review and thus typically be picked up with lower priority by the community.*
   
   ## Contribution Checklist
   
     - Make sure that the pull request corresponds to a [JIRA issue](https://issues.apache.org/jira/projects/FLINK/issues). Exceptions are made for typos in JavaDoc or documentation files, which need no JIRA issue.
     
     - Name the pull request in the form "[FLINK-XXXX] [component] Title of the pull request", where *FLINK-XXXX* should be replaced by the actual issue number. Skip *component* if you are unsure about which is the best component.
     Typo fixes that have no associated JIRA issue should be named following this pattern: `[hotfix] [docs] Fix typo in event time introduction` or `[hotfix] [javadocs] Expand JavaDoc for PuncuatedWatermarkGenerator`.
   
     - Fill out the template below to describe the changes contributed by the pull request. That will give reviewers the context they need to do the review.
     
     - Make sure that the change passes the automated tests, i.e., `mvn clean verify` passes. You can set up Azure Pipelines CI to do that following [this guide](https://cwiki.apache.org/confluence/display/FLINK/Azure+Pipelines#AzurePipelines-Tutorial:SettingupAzurePipelinesforaforkoftheFlinkrepository).
   
     - Each pull request should address only one issue, not mix up code from multiple issues.
     
     - Each commit in the pull request has a meaningful commit message (including the JIRA id)
   
     - Once all items of the checklist are addressed, remove the above text and this checklist, leaving only the filled out template below.
   
   
   **(The sections below can be removed for hotfixes of typos)**
   -->
   
   ## What is the purpose of the change
   The PR uses byte array api instead of ByteBuffer api to improve performance  and compatible with DirectByteBuffer which does not have byte array backed  when reading parquet DataPage V2
   
   ## Brief change log
     - Use the byte array api instead of ByteBuffer api.
   
   ## Verifying this change
   I have done a test to compare byte array api and ByteBuffer api on parquet-mr project.
   The result is:
   [Unpack8ValuesByteArray spent time] 80 ms
   [Unpack8ValuesByteBuffer spent time] 133 ms
   
   The test code is:
   package org.apache.parquet.column.values.bitpacking;
   
   import java.nio.ByteBuffer;
   
   public class ByteBufferTest {
     private static final BytePacker bytePacker = Packer.LITTLE_ENDIAN.newBytePacker(7);
   
     private static final int COUNT = 100000;
   
     public static void main(String[] args) {
       byte  [] in  = new byte[1008];
       int [] out = new int[1152];
       int [] out1 = new int[1152];
       int [] out2 = new int[1152];
   
       int res = 0;
   
       for(int i = 0; i < in.length; i++) {
         in[i] = (byte) i;
       }
   
       for(int i = 0; i < COUNT; i++) {
         res += unpack8ValuesBytes(in, out, i % out.length);
       }
   
       res = 0;
       long t1 = System.currentTimeMillis();
       for(int i = 0; i < COUNT; i++) {
         res += unpack8ValuesBytes(in, out1, i % out.length);
       }
       long t2 = System.currentTimeMillis();
       System.out.println("[Unpack8ValuesByteArray spent time] " + (t2-t1) + " ms");
   
       ByteBuffer byteBuffer = ByteBuffer.wrap(in);
   
       for(int i = 0; i < COUNT; i++) {
         res += unpack8ValuesByteBuffer(byteBuffer, out, i % out.length);
       }
   
       res = 0;
       long t3 = System.currentTimeMillis();
       for(int i = 0; i < COUNT; i++) {
         res += unpack8ValuesByteBuffer(byteBuffer, out2, i % out.length);
       }
       long t4 = System.currentTimeMillis();
       System.out.println("[Unpack8ValuesByteBuffer spent time] " + (t4-t3) + " ms");
   
       for (int i=0; i<out1.length; i++) {
         if(out1[i] != out2[i]) {
           System.out.println("diff: " + out1[i] + " " + out2[i]);
         }
       }
     }
   
     private static int unpack8ValuesBytes(byte [] in, int [] out, int ctr) {
       for(int i = 0, j = 0; i < in.length; i+=7, j+=8) {
         bytePacker.unpack8Values(in, i, out, j);
       }
       return out[ctr];
     }
     private static int unpack8ValuesByteBuffer(ByteBuffer in, int [] out, int ctr) {
       for(int i = 0, j = 0; i < in.capacity(); i+=7, j+=8) {
         bytePacker.unpack8Values(in, i, out, j);
       }
       return out[ctr];
     }
   }
   
   
   
   ## Does this pull request potentially affect one of the following parts:
   
     - Dependencies (does it add or upgrade a dependency): no
     - The public API, i.e., is any changed class annotated with `@Public(Evolving)`: no
     - The serializers: no
     - The runtime per-record code paths (performance sensitive): no
     - Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: no
     - The S3 file system connector: no
   
   ## Documentation
   
     - Does this pull request introduce a new feature? (yes / no)
     - If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1288481471

   ![image](https://user-images.githubusercontent.com/12368495/197461285-91ad97a8-7c56-4037-ae31-39383dac4fe9.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1290030142

   @luoyuxia I have rebased the master
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1289904570

   @jiangjiguang Also, could you please help rebase the master?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1288480519

   ![image](https://user-images.githubusercontent.com/12368495/197461152-ede7d0cb-cd71-4f41-82f6-37947f350ddd.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #20830:
URL: https://github.com/apache/flink/pull/20830#discussion_r1003945031


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/RunLengthDecoder.java:
##########
@@ -265,8 +265,16 @@ void readNextGroup() {
                     while (valueIndex < this.currentCount) {
                         // values are bit packed 8 at a time, so reading bitWidth will always work
                         ByteBuffer buffer = in.slice(bitWidth);
-                        this.packer.unpack8Values(
-                                buffer, buffer.position(), this.currentBuffer, valueIndex);
+                        if (buffer.hasArray()) {
+                            this.packer.unpack8Values(

Review Comment:
   Could you please add some comments in here to expain why we change it?
   Now, we use a deprecated method, we may need some comments for it so that the others can know the context when come to this method for the case that the method is deleted by a higher parquet version in some days and flink needs to upgrad to the  higher parquet version.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wuchong merged pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
wuchong merged PR #20830:
URL: https://github.com/apache/flink/pull/20830


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1246598222

   @flinkbot run azure re-run the last Azure build


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1288495452

   @luoyuxia  packer is made by  this.packer = Packer.LITTLE_ENDIAN.newBytePacker(bitWidth); so it impossible to run the  abstract parent class BytePacker'method
   
   ![image](https://user-images.githubusercontent.com/12368495/197463560-66bd57c0-d834-46e6-8512-df6dc6dcde3a.png)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] flinkbot commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
flinkbot commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1246158997

   <!--
   Meta data
   {
     "version" : 1,
     "metaDataEntries" : [ {
       "hash" : "2999364405adb168991870423494a699e4ce6074",
       "status" : "UNKNOWN",
       "url" : "TBD",
       "triggerID" : "2999364405adb168991870423494a699e4ce6074",
       "triggerType" : "PUSH"
     } ]
   }-->
   ## CI report:
   
   * 2999364405adb168991870423494a699e4ce6074 UNKNOWN
   
   <details>
   <summary>Bot commands</summary>
     The @flinkbot bot supports the following commands:
   
    - `@flinkbot run azure` re-run the last Azure build
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] lsyldliu commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
lsyldliu commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1276054394

   @jiangjiguang Thanks for contribution, I will review it as soon as posssible


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1291378801

   @wuchong Could you please help merge this pr, thanks~


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on a diff in pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on code in PR #20830:
URL: https://github.com/apache/flink/pull/20830#discussion_r1002916628


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/RunLengthDecoder.java:
##########
@@ -265,8 +265,16 @@ void readNextGroup() {
                     while (valueIndex < this.currentCount) {
                         // values are bit packed 8 at a time, so reading bitWidth will always work
                         ByteBuffer buffer = in.slice(bitWidth);
-                        this.packer.unpack8Values(
-                                buffer, buffer.position(), this.currentBuffer, valueIndex);
+                        if (buffer.hasArray()) {
+                            this.packer.unpack8Values(

Review Comment:
   @luoyuxia This BytePacker is only abstract parent class, and unpack8Values will not run this method.
   I have debug code, it run Packer7 class which is code generated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on a diff in pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on code in PR #20830:
URL: https://github.com/apache/flink/pull/20830#discussion_r1004038649


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/RunLengthDecoder.java:
##########
@@ -265,8 +265,16 @@ void readNextGroup() {
                     while (valueIndex < this.currentCount) {
                         // values are bit packed 8 at a time, so reading bitWidth will always work
                         ByteBuffer buffer = in.slice(bitWidth);
-                        this.packer.unpack8Values(
-                                buffer, buffer.position(), this.currentBuffer, valueIndex);
+                        if (buffer.hasArray()) {
+                            this.packer.unpack8Values(

Review Comment:
   @luoyuxia Good idea. I have added comments.  Besides, I have connected parquet-mr community to suggest remote the deprecated flag and change to use byte array default.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] wuchong commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
wuchong commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1253508513

   @lsyldliu do you want to review this?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #20830:
URL: https://github.com/apache/flink/pull/20830#discussion_r1002872635


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/RunLengthDecoder.java:
##########
@@ -265,8 +265,16 @@ void readNextGroup() {
                     while (valueIndex < this.currentCount) {
                         // values are bit packed 8 at a time, so reading bitWidth will always work
                         ByteBuffer buffer = in.slice(bitWidth);
-                        this.packer.unpack8Values(
-                                buffer, buffer.position(), this.currentBuffer, valueIndex);
+                        if (buffer.hasArray()) {
+                            this.packer.unpack8Values(

Review Comment:
   I'm wondering why this changes will improve perfermance. IIUC, from the code
   ```java
   public void unpack8Values(final byte[] input, final int inPos, final int[] output, final int outPos) {
       unpack8Values(ByteBuffer.wrap(input), inPos, output, outPos);
     }
   ```
    the method just delegates to `unpack8Values` and it needs extra `ByteBuffer.wrap(input)`.
   Could you please explain a little bit?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] luoyuxia commented on a diff in pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
luoyuxia commented on code in PR #20830:
URL: https://github.com/apache/flink/pull/20830#discussion_r1003942184


##########
flink-formats/flink-parquet/src/main/java/org/apache/flink/formats/parquet/vector/reader/RunLengthDecoder.java:
##########
@@ -265,8 +265,16 @@ void readNextGroup() {
                     while (valueIndex < this.currentCount) {
                         // values are bit packed 8 at a time, so reading bitWidth will always work
                         ByteBuffer buffer = in.slice(bitWidth);
-                        this.packer.unpack8Values(
-                                buffer, buffer.position(), this.currentBuffer, valueIndex);
+                        if (buffer.hasArray()) {
+                            this.packer.unpack8Values(

Review Comment:
   Thanks for explanation. Make sense to me.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [flink] jiangjiguang commented on pull request #20830: [FLINK-29271]Change to byte array from bytebuffer to improve performance and compatible direct byte buffers

Posted by GitBox <gi...@apache.org>.
jiangjiguang commented on PR #20830:
URL: https://github.com/apache/flink/pull/20830#issuecomment-1278564947

   @lsyldliu Is there a progress ?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@flink.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org