sijie closed pull request #2528:  better way to estimate object size for sql
URL: https://github.com/apache/incubator-pulsar/pull/2528
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pulsar-sql/presto-distribution/LICENSE 
b/pulsar-sql/presto-distribution/LICENSE
index 51d4923335..d7f2fc889c 100644
--- a/pulsar-sql/presto-distribution/LICENSE
+++ b/pulsar-sql/presto-distribution/LICENSE
@@ -359,6 +359,7 @@ The Apache Software License, Version 2.0
     - jsr305-3.0.2.jar
   * Objenesis
     - objenesis-2.1.jar
+    - objenesis-2.6.jar
   * Okio
     - okio-1.13.0.jar
   * Presto
@@ -379,6 +380,8 @@ The Apache Software License, Version 2.0
     - snappy-java-1.1.1.3.jar
   * Bean Validation API
     - validation-api-1.1.0.Final.jar
+  * Objectsize
+    - objectsize-0.0.12.jar
 
 Protocol Buffers License
  * Protocol Buffers
diff --git a/pulsar-sql/presto-distribution/pom.xml 
b/pulsar-sql/presto-distribution/pom.xml
index ab55b3d0bc..a355777b45 100644
--- a/pulsar-sql/presto-distribution/pom.xml
+++ b/pulsar-sql/presto-distribution/pom.xml
@@ -30,6 +30,8 @@
     <properties>
         <presto.version>0.206</presto.version>
         <airlift.version>0.170</airlift.version>
+        <objenesis.version>2.6</objenesis.version>
+        <objectsize.version>0.0.12</objectsize.version>
         <!-- Launcher properties -->
         <main-class>com.facebook.presto.server.PrestoServer</main-class>
         <process-name>${project.artifactId}</process-name>
@@ -80,6 +82,18 @@
             <scope>provided</scope>
         </dependency>
 
+        <dependency>
+            <groupId>org.objenesis</groupId>
+            <artifactId>objenesis</artifactId>
+            <version>${objenesis.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>com.twitter.common</groupId>
+            <artifactId>objectsize</artifactId>
+            <version>${objectsize.version}</version>
+        </dependency>
+
     </dependencies>
 
     <build>
diff --git 
a/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
 
b/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
index 16feb2988b..2a8bfa3b47 100644
--- 
a/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
+++ 
b/pulsar-sql/presto-distribution/src/main/java/org/openjdk/jol/info/ClassLayout.java
@@ -18,18 +18,36 @@
  */
 package org.openjdk.jol.info;
 
+import com.twitter.common.objectsize.ObjectSizeCalculator;
+import io.airlift.log.Logger;
+import org.objenesis.ObjenesisStd;
+
 /**
  * Mock class avoid a dependency on OpenJDK JOL,
  * which is incompatible with the Apache License.
  */
 public class ClassLayout {
 
-    public static ClassLayout parseClass(Class<?> ignored) {
-        return new ClassLayout();
+    private static final Logger log = Logger.get(ClassLayout.class);
+
+    private int size;
+    private static final int DEFAULT_SIZE = 64;
+
+    private ClassLayout(int size) {
+        this.size = size;
+    }
+
+    public static ClassLayout parseClass(Class<?> clazz) {
+        long size = DEFAULT_SIZE;
+        try {
+            size = ObjectSizeCalculator.getObjectSize(new 
ObjenesisStd().newInstance(clazz));
+        } catch (Throwable th) {
+            log.info("Error estimating size of class %s",clazz, th);
+        }
+        return new ClassLayout(Math.toIntExact(size));
     }
 
-    // TODO find a better estimate of class size
     public int instanceSize() {
-        return 64; // random, means nothing
+        return size;
     }
 }
\ No newline at end of file


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to