You are viewing a plain text version of this content. The canonical link for it is here.
Posted to distributedlog-commits@bookkeeper.apache.org by si...@apache.org on 2017/08/30 04:49:43 UTC

[distributedlog] branch master updated: ISSUE #157: Introduce JMH for micro benchmarking

This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/distributedlog.git


The following commit(s) were added to refs/heads/master by this push:
     new 02058d6  ISSUE #157: Introduce JMH for micro benchmarking
02058d6 is described below

commit 02058d661d6fbc38e13c9f96556972df0a09ad54
Author: Jia Zhai <zh...@apache.org>
AuthorDate: Tue Aug 29 21:49:36 2017 -0700

    ISSUE #157: Introduce JMH for micro benchmarking
    
    Descriptions of the changes in this PR:
    
    - add a `tests/jmh` and `tests/jmh-0.4` module for micro-benchmarking
    - `tests/jmh` is to benchmark latest master
    - `tests/jmh-0.4` is to benchmark `0.4.0-incubating`
    - add benchmark for compression
    
    Author: Jia Zhai <zh...@apache.org>
    
    Reviewers: Sijie Guo <si...@apache.org>
    
    This closes #158 from zhaijack/tests, closes #157
---
 .../resources/distributedlog/findbugsExclude.xml   |  23 +++++
 pom.xml                                            |   7 ++
 tests/jmh-0.4/pom.xml                              | 104 +++++++++++++++++++++
 .../distributedlog/tests/CompressionBenchmark.java |  99 ++++++++++++++++++++
 tests/jmh/pom.xml                                  | 104 +++++++++++++++++++++
 .../distributedlog/tests/CompressionBenchmark.java |  99 ++++++++++++++++++++
 tests/pom.xml                                      |  46 +++++++++
 7 files changed, 482 insertions(+)

diff --git a/distributedlog-build-tools/src/main/resources/distributedlog/findbugsExclude.xml b/distributedlog-build-tools/src/main/resources/distributedlog/findbugsExclude.xml
new file mode 100644
index 0000000..025fe64
--- /dev/null
+++ b/distributedlog-build-tools/src/main/resources/distributedlog/findbugsExclude.xml
@@ -0,0 +1,23 @@
+<!--
+    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.
+//-->
+<FindBugsFilter>
+  <Match>
+    <!-- generated code, we can't be held responsible for findbugs in it //-->
+    <Class name="~org\.apache\.distributedlog\.tests\.generated.*" />
+  </Match>
+</FindBugsFilter>
diff --git a/pom.xml b/pom.xml
index 2712b92..bf2a57d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -92,6 +92,7 @@
     <module>distributedlog-benchmark</module>
     <module>distributedlog-tutorials</module>
     <module>distributedlog-core-twitter</module>
+    <module>tests</module>
   </modules>
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -108,6 +109,7 @@
     <freebuilder.version>1.12.3</freebuilder.version>
     <guava.version>20.0</guava.version>
     <jetty.version>8.1.19.v20160209</jetty.version>
+    <jmh.version>1.19</jmh.version>
     <jmock.version>2.8.2</jmock.version>
     <junit.version>4.8.1</junit.version>
     <libthrift.version>0.5.0-1</libthrift.version>
@@ -127,6 +129,7 @@
     <maven-assembly-plugin.version>2.2.1</maven-assembly-plugin.version>
     <maven-checkstyle-plugin.version>2.17</maven-checkstyle-plugin.version>
     <maven-compiler-plugin.version>3.1</maven-compiler-plugin.version>
+    <maven-deploy-plugin.version>2.7</maven-deploy-plugin.version>
     <maven-jar-plugin.version>2.2</maven-jar-plugin.version>
     <maven-javadoc-plugin.version>2.8</maven-javadoc-plugin.version>
     <maven-shade-plugin.version>2.4.3</maven-shade-plugin.version>
@@ -181,6 +184,9 @@
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>findbugs-maven-plugin</artifactId>
         <version>${findbugs-maven-plugin.version}</version>
+        <configuration>
+          <excludeFilterFile>${session.executionRootDirectory}/distributedlog-build-tools/src/main/resources/distributedlog/findbugsExclude.xml</excludeFilterFile>
+        </configuration>
       </plugin>
       <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
@@ -235,6 +241,7 @@
             <exclude>OWNERS</exclude>
             <exclude>CONFIG.ini</exclude>
             <exclude>**/**.md</exclude>
+            <exclude>**/**.iml</exclude>
             <exclude>scripts/dev/reviewers</exclude>
             <exclude>**/dependency-reduced-pom.xml</exclude>
             <exclude>**/org/apache/distributedlog/thrift/*</exclude>
diff --git a/tests/jmh-0.4/pom.xml b/tests/jmh-0.4/pom.xml
new file mode 100644
index 0000000..7e43acb
--- /dev/null
+++ b/tests/jmh-0.4/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.distributedlog.tests</groupId>
+    <artifactId>tests-parent</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent> 
+  <artifactId>jmh-test-0.4</artifactId>
+  <name>Apache DistributedLog :: Tests :: JMH Benchmark (0.4.0-incubating)</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.distributedlog</groupId>
+      <artifactId>distributedlog-core_2.11</artifactId>
+      <version>0.4.0-incubating</version>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-core</artifactId>
+      <version>${jmh.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-generator-annprocess</artifactId>
+      <version>${jmh.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <!--
+        Name of the benchmark Uber-JAR to generate.
+      -->
+    <uberjar.name>jmh-benchmarks-0.4.0</uberjar.name>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>${maven-shade-plugin.version}</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <finalName>${uberjar.name}</finalName>
+              <transformers>
+                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                  <mainClass>org.openjdk.jmh.Main</mainClass>
+                </transformer>
+              </transformers>
+              <filters>
+                <filter>
+                  <!--
+                    Shading signed JARs will fail without this.
+                    http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
+                  -->
+                  <artifact>*:*</artifact>
+                  <excludes>
+                    <exclude>META-INF/*.SF</exclude>
+                    <exclude>META-INF/*.DSA</exclude>
+                    <exclude>META-INF/*.RSA</exclude>
+                  </excludes>
+                </filter>
+              </filters>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/tests/jmh-0.4/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java b/tests/jmh-0.4/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java
new file mode 100644
index 0000000..af66212
--- /dev/null
+++ b/tests/jmh-0.4/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.distributedlog.tests;
+
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.stats.OpStatsLogger;
+import org.apache.distributedlog.io.CompressionCodec;
+import org.apache.distributedlog.io.CompressionCodec.Type;
+import org.apache.distributedlog.io.CompressionUtils;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+/**
+ * Benchmarking serialization and deserilization.
+ */
+@BenchmarkMode({ Mode.Throughput })
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Thread)
+public class CompressionBenchmark {
+
+    @Param({ "10", "100", "1000", "10000" })
+    int size;
+
+    byte[] entry;
+    byte[] compressedLz4;
+    byte[] compressedNone;
+    CompressionCodec codecLz4;
+    CompressionCodec codecNone;
+    OpStatsLogger opStatsLogger;
+
+    @Setup
+    public void prepare() {
+        Random r = new Random(System.currentTimeMillis());
+        this.entry = new byte[this.size];
+        r.nextBytes(entry);
+
+        this.codecLz4 = CompressionUtils.getCompressionCodec(Type.LZ4);
+        this.codecNone = CompressionUtils.getCompressionCodec(Type.NONE);
+        this.opStatsLogger = NullStatsLogger.INSTANCE.getOpStatsLogger("");
+        this.compressedLz4 = codecLz4.compress(entry, 0, entry.length, opStatsLogger);
+        this.compressedNone = codecNone.compress(entry, 0, entry.length, opStatsLogger);
+    }
+
+
+    @Benchmark
+    public void testCompressLZ4() throws Exception {
+        testCompress(codecLz4);
+    }
+
+    @Benchmark
+    public void testCompressNone() throws Exception {
+        testCompress(codecNone);
+    }
+
+    private void testCompress(CompressionCodec codec) {
+        codec.compress(entry, 0, entry.length, opStatsLogger);
+    }
+
+    @Benchmark
+    public void testDecompressLZ4() throws Exception {
+        testDecompress(codecLz4, compressedLz4);
+    }
+
+    @Benchmark
+    public void testDecompressNone() throws Exception {
+        testDecompress(codecNone, compressedNone);
+    }
+
+    private void testDecompress(CompressionCodec codec, byte[] compressed) {
+        codec.decompress(compressed, 0, compressed.length, opStatsLogger);
+    }
+
+}
diff --git a/tests/jmh/pom.xml b/tests/jmh/pom.xml
new file mode 100644
index 0000000..ed051d6
--- /dev/null
+++ b/tests/jmh/pom.xml
@@ -0,0 +1,104 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.distributedlog.tests</groupId>
+    <artifactId>tests-parent</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+    <relativePath>..</relativePath>
+  </parent> 
+  <artifactId>jmh-test</artifactId>
+  <name>Apache DistributedLog :: Tests :: JMH Benchmark</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.distributedlog</groupId>
+      <artifactId>distributedlog-core</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-core</artifactId>
+      <version>${jmh.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.openjdk.jmh</groupId>
+      <artifactId>jmh-generator-annprocess</artifactId>
+      <version>${jmh.version}</version>
+      <scope>provided</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.slf4j</groupId>
+      <artifactId>slf4j-log4j12</artifactId>
+      <version>${slf4j.version}</version>
+    </dependency>
+  </dependencies>
+
+  <properties>
+    <!--
+        Name of the benchmark Uber-JAR to generate.
+      -->
+    <uberjar.name>jmh-benchmarks</uberjar.name>
+  </properties>
+
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-shade-plugin</artifactId>
+        <version>${maven-shade-plugin.version}</version>
+        <executions>
+          <execution>
+            <phase>package</phase>
+            <goals>
+              <goal>shade</goal>
+            </goals>
+            <configuration>
+              <finalName>${uberjar.name}</finalName>
+              <transformers>
+                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
+                  <mainClass>org.openjdk.jmh.Main</mainClass>
+                </transformer>
+              </transformers>
+              <filters>
+                <filter>
+                  <!--
+                    Shading signed JARs will fail without this.
+                    http://stackoverflow.com/questions/999489/invalid-signature-file-when-attempting-to-run-a-jar
+                  -->
+                  <artifact>*:*</artifact>
+                  <excludes>
+                    <exclude>META-INF/*.SF</exclude>
+                    <exclude>META-INF/*.DSA</exclude>
+                    <exclude>META-INF/*.RSA</exclude>
+                  </excludes>
+                </filter>
+              </filters>
+            </configuration>
+          </execution>
+        </executions>
+      </plugin>
+      <plugin>
+        <groupId>org.codehaus.mojo</groupId>
+        <artifactId>findbugs-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </build>
+</project>
diff --git a/tests/jmh/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java b/tests/jmh/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java
new file mode 100644
index 0000000..af66212
--- /dev/null
+++ b/tests/jmh/src/main/java/org/apache/distributedlog/tests/CompressionBenchmark.java
@@ -0,0 +1,99 @@
+/*
+ *
+ * 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.distributedlog.tests;
+
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.apache.bookkeeper.stats.NullStatsLogger;
+import org.apache.bookkeeper.stats.OpStatsLogger;
+import org.apache.distributedlog.io.CompressionCodec;
+import org.apache.distributedlog.io.CompressionCodec.Type;
+import org.apache.distributedlog.io.CompressionUtils;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Param;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+
+/**
+ * Benchmarking serialization and deserilization.
+ */
+@BenchmarkMode({ Mode.Throughput })
+@OutputTimeUnit(TimeUnit.MILLISECONDS)
+@State(Scope.Thread)
+public class CompressionBenchmark {
+
+    @Param({ "10", "100", "1000", "10000" })
+    int size;
+
+    byte[] entry;
+    byte[] compressedLz4;
+    byte[] compressedNone;
+    CompressionCodec codecLz4;
+    CompressionCodec codecNone;
+    OpStatsLogger opStatsLogger;
+
+    @Setup
+    public void prepare() {
+        Random r = new Random(System.currentTimeMillis());
+        this.entry = new byte[this.size];
+        r.nextBytes(entry);
+
+        this.codecLz4 = CompressionUtils.getCompressionCodec(Type.LZ4);
+        this.codecNone = CompressionUtils.getCompressionCodec(Type.NONE);
+        this.opStatsLogger = NullStatsLogger.INSTANCE.getOpStatsLogger("");
+        this.compressedLz4 = codecLz4.compress(entry, 0, entry.length, opStatsLogger);
+        this.compressedNone = codecNone.compress(entry, 0, entry.length, opStatsLogger);
+    }
+
+
+    @Benchmark
+    public void testCompressLZ4() throws Exception {
+        testCompress(codecLz4);
+    }
+
+    @Benchmark
+    public void testCompressNone() throws Exception {
+        testCompress(codecNone);
+    }
+
+    private void testCompress(CompressionCodec codec) {
+        codec.compress(entry, 0, entry.length, opStatsLogger);
+    }
+
+    @Benchmark
+    public void testDecompressLZ4() throws Exception {
+        testDecompress(codecLz4, compressedLz4);
+    }
+
+    @Benchmark
+    public void testDecompressNone() throws Exception {
+        testDecompress(codecNone, compressedNone);
+    }
+
+    private void testDecompress(CompressionCodec codec, byte[] compressed) {
+        codec.decompress(compressed, 0, compressed.length, opStatsLogger);
+    }
+
+}
diff --git a/tests/pom.xml b/tests/pom.xml
new file mode 100644
index 0000000..e3a0478
--- /dev/null
+++ b/tests/pom.xml
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+   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.
+-->
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <packaging>pom</packaging>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.distributedlog</groupId>
+    <artifactId>distributedlog</artifactId>
+    <version>0.5.0-SNAPSHOT</version>
+  </parent>
+  <groupId>org.apache.distributedlog.tests</groupId>
+  <artifactId>tests-parent</artifactId>
+  <name>Apache BookKeeper :: Tests</name>
+  <modules>
+    <module>jmh</module>
+    <module>jmh-0.4</module>
+  </modules>
+  <build>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-deploy-plugin</artifactId>
+        <version>${maven-deploy-plugin.version}</version>
+        <configuration>
+          <skip>true</skip>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
+</project>

-- 
To stop receiving notification emails like this one, please contact
['"distributedlog-commits@bookkeeper.apache.org" <di...@bookkeeper.apache.org>'].