[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

classic Classic list List threaded Threaded
25 messages Options
12
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
GitHub user zzcclp opened a pull request:

    https://github.com/apache/carbondata/pull/1982

    [CARBONDATA-2184]Improve memory reuse for heap memory in `HeapMemoryAllocator`

    The description in [SPARK-21860](https://issues.apache.org/jira/browse/SPARK-21860):
    In `HeapMemoryAllocator`, when allocating memory from pool, and the key of pool is memory size.
    Actually some size of memory ,such as 1025bytes,1026bytes,......1032bytes, we can think they are the same,because we allocate memory in multiples of 8 bytes.
    In this case, we can improve memory reuse.
   
    Be sure to do all of the following checklist to help us incorporate
    your contribution quickly and easily:
   
     - [ ] Any interfaces changed?  No
     
     - [ ] Any backward compatibility impacted?  No
     
     - [ ] Document update required?  No
   
     - [ ] Testing done
            Please provide details on
            - Whether new unit test cases have been added or why no new tests are required?
            - How it is tested? Please attach test report.
            - Is it a performance related change? Please attach the performance test report.
            - Any additional information to help reviewers in testing this change.
           
     - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.
   


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zzcclp/carbondata CARBONDATA-2184

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/carbondata/pull/1982.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1982
   
----
commit d5911880c37c463ed752d82343035a15f96aa81e
Author: Zhang Zhichao <441586683@...>
Date:   2018-02-17T16:55:04Z

    [CARBONDATA-2184]Improve memory reuse for heap memory in `HeapMemoryAllocator`
   
    The description in [SPARK-21860|https://issues.apache.org/jira/browse/SPARK-21860]:
    In `HeapMemoryAllocator`, when allocating memory from pool, and the key of pool is memory size.
    Actually some size of memory ,such as 1025bytes,1026bytes,......1032bytes, we can think they are the same,because we allocate memory in multiples of 8 bytes.
    In this case, we can improve memory reuse.

----


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Success with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/3754/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Success with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/2514/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user zzcclp closed the pull request at:

    https://github.com/apache/carbondata/pull/1982


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
GitHub user zzcclp reopened a pull request:

    https://github.com/apache/carbondata/pull/1982

    [CARBONDATA-2184]Improve memory reuse for heap memory in `HeapMemoryAllocator`

    The description in [SPARK-21860](https://issues.apache.org/jira/browse/SPARK-21860):
    In `HeapMemoryAllocator`, when allocating memory from pool, and the key of pool is memory size.
    Actually some size of memory ,such as 1025bytes,1026bytes,......1032bytes, we can think they are the same,because we allocate memory in multiples of 8 bytes.
    In this case, we can improve memory reuse.
   
    Be sure to do all of the following checklist to help us incorporate
    your contribution quickly and easily:
   
     - [ ] Any interfaces changed?  No
     
     - [ ] Any backward compatibility impacted?  No
     
     - [ ] Document update required?  No
   
     - [x] Testing done
            Please provide details on
            - Whether new unit test cases have been added or why no new tests are required?
            - How it is tested? Please attach test report.
            - Is it a performance related change? Please attach the performance test report.
            - Any additional information to help reviewers in testing this change.
           
     - [ ] For large changes, please consider breaking it into sub-tasks under an umbrella JIRA.
   


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zzcclp/carbondata CARBONDATA-2184

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/carbondata/pull/1982.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1982
   
----
commit d5911880c37c463ed752d82343035a15f96aa81e
Author: Zhang Zhichao <441586683@...>
Date:   2018-02-17T16:55:04Z

    [CARBONDATA-2184]Improve memory reuse for heap memory in `HeapMemoryAllocator`
   
    The description in [SPARK-21860|https://issues.apache.org/jira/browse/SPARK-21860]:
    In `HeapMemoryAllocator`, when allocating memory from pool, and the key of pool is memory size.
    Actually some size of memory ,such as 1025bytes,1026bytes,......1032bytes, we can think they are the same,because we allocate memory in multiples of 8 bytes.
    In this case, we can improve memory reuse.

----


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user zzcclp commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    @chenliang613 @jackylk please review, thanks.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r169526789
 
    --- Diff: core/src/main/java/org/apache/carbondata/core/memory/HeapMemoryAllocator.java ---
    @@ -44,38 +44,49 @@ private boolean shouldPool(long size) {
       }
     
       @Override public MemoryBlock allocate(long size) throws OutOfMemoryError {
    -    if (shouldPool(size)) {
    +    int numWords = (int) ((size + 7) / 8);
    --- End diff --
   
    I think it is better to add a CarbonProperty to let user to enable this feature or not


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user zzcclp commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r169532810
 
    --- Diff: core/src/main/java/org/apache/carbondata/core/memory/HeapMemoryAllocator.java ---
    @@ -44,38 +44,49 @@ private boolean shouldPool(long size) {
       }
     
       @Override public MemoryBlock allocate(long size) throws OutOfMemoryError {
    -    if (shouldPool(size)) {
    +    int numWords = (int) ((size + 7) / 8);
    --- End diff --
   
    do you mean the reuse feature or  adjust the memory size?


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r169836980
 
    --- Diff: core/src/main/java/org/apache/carbondata/core/memory/HeapMemoryAllocator.java ---
    @@ -44,38 +44,49 @@ private boolean shouldPool(long size) {
       }
     
       @Override public MemoryBlock allocate(long size) throws OutOfMemoryError {
    -    if (shouldPool(size)) {
    +    int numWords = (int) ((size + 7) / 8);
    --- End diff --
   
    I mean the reuse feature


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user zzcclp commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r170810291
 
    --- Diff: core/src/main/java/org/apache/carbondata/core/memory/HeapMemoryAllocator.java ---
    @@ -44,38 +44,49 @@ private boolean shouldPool(long size) {
       }
     
       @Override public MemoryBlock allocate(long size) throws OutOfMemoryError {
    -    if (shouldPool(size)) {
    +    int numWords = (int) ((size + 7) / 8);
    --- End diff --
   
    Done


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Failed  with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/3917/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Failed with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/2673/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Success with Spark 2.1.0, Please check CI http://136.243.101.176:8080/job/ApacheCarbonPRBuilder1/3918/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Success with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/2674/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user zzcclp commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    @jackylk please help to review, thanks.


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user ravipesala commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    SDV Build Success , Please check CI http://144.76.159.231:8080/job/ApacheSDVTests/3692/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r170828032
 
    --- Diff: core/src/main/java/org/apache/carbondata/core/memory/HeapMemoryAllocator.java ---
    @@ -23,59 +23,81 @@
     import java.util.Map;
     import javax.annotation.concurrent.GuardedBy;
     
    +import org.apache.carbondata.core.util.CarbonProperties;
    +
     /**
      * Code ported from Apache Spark {org.apache.spark.unsafe.memory} package
      * A simple {@link MemoryAllocator} that can allocate up to 16GB using a JVM long primitive array.
      */
     public class HeapMemoryAllocator implements MemoryAllocator {
     
    -  @GuardedBy("this") private final Map<Long, LinkedList<WeakReference<MemoryBlock>>>
    +  @GuardedBy("this") private final Map<Long, LinkedList<WeakReference<long[]>>>
           bufferPoolsBySize = new HashMap<>();
     
    -  private static final int POOLING_THRESHOLD_BYTES = 1024 * 1024;
    +  private int poolingThresholdBytes = 1024 * 1024;
    --- End diff --
   
    This assignment is not required


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata pull request #1982: [CARBONDATA-2184]Improve memory reuse for hea...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user jackylk commented on a diff in the pull request:

    https://github.com/apache/carbondata/pull/1982#discussion_r170828257
 
    --- Diff: core/src/test/java/org/apache/carbondata/core/memory/MemoryAllocatorUnitTest.java ---
    @@ -0,0 +1,46 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +
    +package org.apache.carbondata.core.memory;
    +
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +public class MemoryAllocatorUnitTest {
    +
    +  @Test
    +  public void testHeapMemoryReuse() {
    +    MemoryAllocator heapMem = new HeapMemoryAllocator();
    +    // The size is less than `HeapMemoryAllocator.POOLING_THRESHOLD_BYTES`,
    +    // allocate new memory every time.
    +    MemoryBlock onheap1 = heapMem.allocate(513);
    +    Object obj1 = onheap1.getBaseObject();
    +    heapMem.free(onheap1);
    +    MemoryBlock onheap2 = heapMem.allocate(514);
    +    Assert.assertNotEquals(obj1, onheap2.getBaseObject());
    +
    +    // The size is greater than `HeapMemoryAllocator.POOLING_THRESHOLD_BYTES`,
    +    // reuse the previous memory which has released.
    +    MemoryBlock onheap3 = heapMem.allocate(1024 * 1024 + 1);
    +    Assert.assertEquals(onheap3.size(), 1024 * 1024 + 1);
    +    Object obj3 = onheap3.getBaseObject();
    +    heapMem.free(onheap3);
    +    MemoryBlock onheap4 = heapMem.allocate(1024 * 1024 + 7);
    +    Assert.assertEquals(onheap4.size(), 1024 * 1024 + 7);
    +    Assert.assertEquals(obj3, onheap4.getBaseObject());
    +  }
    +}
    --- End diff --
   
    please add one testcase to test if not pooling (set threshold to -1)


---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user ravipesala commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    SDV Build Success , Please check CI http://144.76.159.231:8080/job/ApacheSDVTests/3693/



---
Reply | Threaded
Open this post in threaded view
|

[GitHub] carbondata issue #1982: [CARBONDATA-2184]Improve memory reuse for heap memor...

qiuchenjian-2
In reply to this post by qiuchenjian-2
Github user CarbonDataQA commented on the issue:

    https://github.com/apache/carbondata/pull/1982
 
    Build Success with Spark 2.2.1, Please check CI http://88.99.58.216:8080/job/ApacheCarbonPRBuilder/2686/



---
12