Skip to content

Commit

Permalink
better way to estimate object size for sql (#2528)
Browse files Browse the repository at this point in the history
Since we mocked ClassLayout.parseClass() because we need to exclude org.openjdk.jol for license issues. Lets come up with another way to estimate class size
  • Loading branch information
jerrypeng authored and sijie committed Sep 6, 2018
1 parent 6fa95fa commit 90a7448
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pulsar-sql/presto-distribution/LICENSE
Expand Up @@ -359,6 +359,7 @@ The Apache Software License, Version 2.0
- jsr305-3.0.2.jar - jsr305-3.0.2.jar
* Objenesis * Objenesis
- objenesis-2.1.jar - objenesis-2.1.jar
- objenesis-2.6.jar
* Okio * Okio
- okio-1.13.0.jar - okio-1.13.0.jar
* Presto * Presto
Expand All @@ -379,6 +380,8 @@ The Apache Software License, Version 2.0
- snappy-java-1.1.1.3.jar - snappy-java-1.1.1.3.jar
* Bean Validation API * Bean Validation API
- validation-api-1.1.0.Final.jar - validation-api-1.1.0.Final.jar
* Objectsize
- objectsize-0.0.12.jar


Protocol Buffers License Protocol Buffers License
* Protocol Buffers * Protocol Buffers
Expand Down
14 changes: 14 additions & 0 deletions pulsar-sql/presto-distribution/pom.xml
Expand Up @@ -30,6 +30,8 @@
<properties> <properties>
<presto.version>0.206</presto.version> <presto.version>0.206</presto.version>
<airlift.version>0.170</airlift.version> <airlift.version>0.170</airlift.version>
<objenesis.version>2.6</objenesis.version>
<objectsize.version>0.0.12</objectsize.version>
<!-- Launcher properties --> <!-- Launcher properties -->
<main-class>com.facebook.presto.server.PrestoServer</main-class> <main-class>com.facebook.presto.server.PrestoServer</main-class>
<process-name>${project.artifactId}</process-name> <process-name>${project.artifactId}</process-name>
Expand Down Expand Up @@ -80,6 +82,18 @@
<scope>provided</scope> <scope>provided</scope>
</dependency> </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> </dependencies>


<build> <build>
Expand Down
Expand Up @@ -18,18 +18,36 @@
*/ */
package org.openjdk.jol.info; 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, * Mock class avoid a dependency on OpenJDK JOL,
* which is incompatible with the Apache License. * which is incompatible with the Apache License.
*/ */
public class ClassLayout { public class ClassLayout {


public static ClassLayout parseClass(Class<?> ignored) { private static final Logger log = Logger.get(ClassLayout.class);
return new ClassLayout();
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() { public int instanceSize() {
return 64; // random, means nothing return size;
} }
} }

0 comments on commit 90a7448

Please sign in to comment.