[ 
https://issues.apache.org/jira/browse/HADOOP-17901?focusedWorklogId=648485&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-648485
 ]

ASF GitHub Bot logged work on HADOOP-17901:
-------------------------------------------

                Author: ASF GitHub Bot
            Created on: 09/Sep/21 09:42
            Start Date: 09/Sep/21 09:42
    Worklog Time Spent: 10m 
      Work Description: pbacsko opened a new pull request #3411:
URL: https://github.com/apache/hadoop/pull/3411


   …6951.
   
   Change-Id: I628380b6d29a2796d9d67bd38b423cdb1830bf04
   
   <!--
     Thanks for sending a pull request!
       1. If this is your first time, please read our contributor guidelines: 
https://cwiki.apache.org/confluence/display/HADOOP/How+To+Contribute
       2. Make sure your PR title starts with JIRA issue id, e.g., 
'HADOOP-17799. Your PR title ...'.
   -->
   
   ### Description of PR
   
   HADOOP-16951 introduced a performance regression to Text.append(). The 
backing array is not increased as intended, which resulted in a lot of 
unnecessary new arrays.
   
   ### How was this patch tested?
   
   Tried the change on a cluster, where a mapper successfully read a large text 
file (1.1GB) without slowing down.
   Executed unit tests, which all passed.
   
   ### For code changes:
   
   - [x] Does the title or this PR starts with the corresponding JIRA issue id 
(e.g. 'HADOOP-17799. Your PR title ...')?
   - [ ] Object storage: have the integration tests been executed and the 
endpoint declared according to the connector-specific documentation?
   - [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)?
   - [ ] If applicable, have you updated the `LICENSE`, `LICENSE-binary`, 
`NOTICE-binary` files?
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

            Worklog Id:     (was: 648485)
    Remaining Estimate: 0h
            Time Spent: 10m

> Performance degradation in Text.append() after HADOOP-16951
> -----------------------------------------------------------
>
>                 Key: HADOOP-17901
>                 URL: https://issues.apache.org/jira/browse/HADOOP-17901
>             Project: Hadoop Common
>          Issue Type: Bug
>          Components: common
>            Reporter: Peter Bacsko
>            Assignee: Peter Bacsko
>            Priority: Critical
>         Attachments: HADOOP-17901-001.patch
>
>          Time Spent: 10m
>  Remaining Estimate: 0h
>
> We discovered a serious performance degradation in {{Text.append()}}.
> The problem is that the logic which intends to increase the size of the 
> backing array does not work as intended.
> It's very difficult to spot, so I added extra logs to see what happens.
> Let's add 4096 bytes of textual data in a loop:
> {noformat}
>   public static void main(String[] args) {
>     Text text = new Text();
>     String toAppend = RandomStringUtils.randomAscii(4096);
>     for(int i = 0; i < 100; i++) {
>       text.append(toAppend.getBytes(), 0, 4096);
>     }
>   }
> {noformat}
> With some debug printouts, we can observe:
> {noformat}
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:append(251)) - 
> length: 24576,  len: 4096, utf8ArraySize: 4096, bytes.length: 30720
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:append(253)) - length 
> + (length >> 1): 36864
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:append(254)) - length 
> + len: 28672
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:ensureCapacity(287)) 
> - >>> enhancing capacity from 30720 to 36864
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:append(251)) - 
> length: 28672,  len: 4096, utf8ArraySize: 4096, bytes.length: 36864
> 2021-09-08 13:35:29,528 INFO  [main] io.Text (Text.java:append(253)) - length 
> + (length >> 1): 43008
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:append(254)) - length 
> + len: 32768
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:ensureCapacity(287)) 
> - >>> enhancing capacity from 36864 to 43008
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:append(251)) - 
> length: 32768,  len: 4096, utf8ArraySize: 4096, bytes.length: 43008
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:append(253)) - length 
> + (length >> 1): 49152
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:append(254)) - length 
> + len: 36864
> 2021-09-08 13:35:29,529 INFO  [main] io.Text (Text.java:ensureCapacity(287)) 
> - >>> enhancing capacity from 43008 to 49152
> ...
> {noformat}
> After a certain number of {{append()}} calls, subsequent capacity increments 
> are small.
> It's because the difference between two {{length + (length >> 1)}} values is 
> always 6144 bytes. Because the size of the backing array is trailing behind 
> the calculated value, the increment will also be 6144 bytes. This means that 
> new arrays are constantly created.
> Suggested solution: don't calculate the capacity in advance based on length. 
> Instead, pass the required minimum to {{ensureCapacity()}}. Then the 
> increment should depend on the actual size of the byte array if the desired 
> capacity is larger.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to