You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directmemory.apache.org by no...@apache.org on 2012/11/03 23:01:48 UTC

svn commit: r1405430 - in /directmemory/lightning/trunk: ./ lightning-core/ lightning-core/src/test/java/org/apache/directmemory/lightning/

Author: noctarius
Date: Sat Nov  3 22:01:47 2012
New Revision: 1405430

URL: http://svn.apache.org/viewvc?rev=1405430&view=rev
Log:
Spliptted benchmark into sequential and concurrent versions

Added:
    directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/AbstractLightningBenchmark.java
      - copied, changed from r1405131, directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java
    directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ConcurrentLightningBenchmark.java
    directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/CustomBenchmark.java
      - copied, changed from r1405131, directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java
    directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/SequentialLightningBenchmark.java
Removed:
    directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java
Modified:
    directmemory/lightning/trunk/lightning-core/pom.xml
    directmemory/lightning/trunk/pom.xml

Modified: directmemory/lightning/trunk/lightning-core/pom.xml
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/pom.xml?rev=1405430&r1=1405429&r2=1405430&view=diff
==============================================================================
--- directmemory/lightning/trunk/lightning-core/pom.xml (original)
+++ directmemory/lightning/trunk/lightning-core/pom.xml Sat Nov  3 22:01:47 2012
@@ -50,12 +50,26 @@
       <groupId>com.carrotsearch</groupId>
       <artifactId>hppc</artifactId>
     </dependency>
+      <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+      </dependency>
 
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>com.carrotsearch</groupId>
+      <artifactId>junit-benchmarks</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>com.h2database</groupId>
+      <artifactId>h2</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 
   <profiles>

Copied: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/AbstractLightningBenchmark.java (from r1405131, directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java)
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/AbstractLightningBenchmark.java?p2=directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/AbstractLightningBenchmark.java&p1=directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java&r1=1405131&r2=1405430&rev=1405430&view=diff
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java (original)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/AbstractLightningBenchmark.java Sat Nov  3 22:01:47 2012
@@ -39,275 +39,87 @@ import org.apache.directmemory.lightning
 import org.apache.directmemory.lightning.io.SerializerOutputStream;
 import org.apache.directmemory.lightning.metadata.Attribute;
 import org.apache.directmemory.lightning.metadata.PropertyDescriptor;
-import org.junit.Ignore;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
-@Ignore
-public class Benchmark
-{
+import com.carrotsearch.junitbenchmarks.AbstractBenchmark;
 
-    private static final int WARMUP_ROUNDS = 100000;
+public abstract class AbstractLightningBenchmark
+    extends AbstractBenchmark
+{
 
-    private static final int BENCHMARK_ROUNDS = 800000;
+    private static Serializer serializer;
 
-    @Test
-    public void benchmarkLightningSerialization()
-        throws Exception
+    @BeforeClass
+    public static void initializeLightning()
     {
         long buildStartTime = System.nanoTime();
-        Serializer serializer =
+        serializer =
             Lightning.newBuilder().debugCacheDirectory( new File( "target" ) ).serializerDefinitions( new BenchmarkSerializerDefinition() ).build();
         long nanos = TimeUnit.NANOSECONDS.toMillis( System.nanoTime() - buildStartTime );
         System.out.println( "Lightning Serializer build time: " + nanos + " ms" );
+    }
 
-        long size = 0;
-        for ( int i = 0; i < WARMUP_ROUNDS; i++ )
-        {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            OutputStreamTarget target = new OutputStreamTarget( baos );
-            SerializerOutputStream out = new SerializerOutputStream( serializer, target );
-            Foo foo = buildRandomFoo();
-            out.writeObject( foo );
-
-            assertNotNull( baos );
-            assertNotNull( out );
-            assertNotNull( baos.toByteArray() );
-            size = baos.toByteArray().length;
-        }
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
-
-        long time = 0;
-        for ( int i = 0; i < BENCHMARK_ROUNDS; i++ )
-        {
-            Foo foo = buildRandomFoo();
-
-            long startTime = System.nanoTime();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            OutputStreamTarget target = new OutputStreamTarget( baos );
-            SerializerOutputStream out = new SerializerOutputStream( serializer, target );
-            out.writeObject( foo );
-
-            time += System.nanoTime() - startTime;
-            assertNotNull( baos.toByteArray() );
-        }
-
-        double avg = time / (double) BENCHMARK_ROUNDS;
-        System.out.println( "Lightning Serialization Avg: " + String.format( "%5.2f", avg ) + " ns, runs: "
-            + BENCHMARK_ROUNDS + ", size: " + size + " bytes" );
-
-        System.runFinalization();
-        System.gc();
+    @Test
+    public void benchmarkLightningSerialization()
+        throws Exception
+    {
+        Foo foo = buildRandomFoo();
 
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OutputStreamTarget target = new OutputStreamTarget( baos );
+        SerializerOutputStream out = new SerializerOutputStream( serializer, target );
+        out.writeObject( foo );
+        assertNotNull( baos.toByteArray() );
     }
 
     @Test
     public void benchmarkLightningDeserialization()
         throws Exception
     {
-        Serializer serializer =
-            Lightning.newBuilder().serializerDefinitions( new BenchmarkSerializerDefinition() ).build();
-
-        long size = 0;
-        for ( int i = 0; i < WARMUP_ROUNDS; i++ )
-        {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            OutputStreamTarget target = new OutputStreamTarget( baos );
-            SerializerOutputStream out = new SerializerOutputStream( serializer, target );
-            Foo foo = buildRandomFoo();
-            out.writeObject( foo );
-
-            assertNotNull( baos );
-            assertNotNull( out );
-            assertNotNull( baos.toByteArray() );
-            size = baos.toByteArray().length;
-
-            ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
-            InputStreamSource source = new InputStreamSource( bais );
-            SerializerInputStream in = new SerializerInputStream( serializer, source );
-            Object value = in.readObject();
-            assertNotNull( value );
-            assertEquals( foo, value );
-        }
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
-
-        long time = 0;
-        for ( int i = 0; i < BENCHMARK_ROUNDS; i++ )
-        {
-            Foo foo = buildRandomFoo();
-
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            OutputStreamTarget target = new OutputStreamTarget( baos );
-            SerializerOutputStream out = new SerializerOutputStream( serializer, target );
-            out.writeObject( foo );
-
-            long startTime = System.nanoTime();
-            ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
-            InputStreamSource source = new InputStreamSource( bais );
-            SerializerInputStream in = new SerializerInputStream( serializer, source );
-            Object value = in.readObject();
-            time += System.nanoTime() - startTime;
-            assertNotNull( value );
-            assertEquals( foo, value );
-        }
-
-        double avg = time / (double) BENCHMARK_ROUNDS;
-        System.out.println( "Lightning Deserialization Avg: " + String.format( "%5.2f", avg ) + " ns, runs: "
-            + BENCHMARK_ROUNDS + ", size: " + size + " bytes" );
+        Foo foo = buildRandomFoo();
 
-        System.runFinalization();
-        System.gc();
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        OutputStreamTarget target = new OutputStreamTarget( baos );
+        SerializerOutputStream out = new SerializerOutputStream( serializer, target );
+        out.writeObject( foo );
+
+        ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+        InputStreamSource source = new InputStreamSource( bais );
+        SerializerInputStream in = new SerializerInputStream( serializer, source );
+        Object value = in.readObject();
+        assertNotNull( value );
+        assertEquals( foo, value );
     }
 
     @Test
     public void benchmarkJavaSerialization()
         throws Exception
     {
-        long size = 0;
-        for ( int i = 0; i < WARMUP_ROUNDS; i++ )
-        {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream out = new ObjectOutputStream( baos );
-            Foo foo = buildRandomFoo();
-            out.writeObject( foo );
-
-            assertNotNull( baos );
-            assertNotNull( out );
-            assertNotNull( baos.toByteArray() );
-            size = baos.toByteArray().length;
-        }
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
-
-        long time = 0;
-        for ( int i = 0; i < BENCHMARK_ROUNDS; i++ )
-        {
-            Foo foo = buildRandomFoo();
-
-            long startTime = System.nanoTime();
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream out = new ObjectOutputStream( baos );
-            out.writeObject( foo );
+        Foo foo = buildRandomFoo();
 
-            time += System.nanoTime() - startTime;
-            assertNotNull( baos.toByteArray() );
-        }
-
-        double avg = time / (double) BENCHMARK_ROUNDS;
-        System.out.println( "Java Serialization Avg: " + String.format( "%5.2f", avg ) + " ns, runs: "
-            + BENCHMARK_ROUNDS + ", size: " + size + " bytes" );
-
-        System.runFinalization();
-        System.gc();
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+        out.writeObject( foo );
+        assertNotNull( baos.toByteArray() );
     }
 
     @Test
     public void benchmarkJavaDeserialization()
         throws Exception
     {
-        long size = 0;
-        for ( int i = 0; i < WARMUP_ROUNDS; i++ )
-        {
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream out = new ObjectOutputStream( baos );
-            Foo foo = buildRandomFoo();
-            out.writeObject( foo );
-
-            assertNotNull( baos );
-            assertNotNull( out );
-            assertNotNull( baos.toByteArray() );
-            size = baos.toByteArray().length;
-
-            ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
-            ObjectInputStream in = new ObjectInputStream( bais );
-            Object value = in.readObject();
-            assertNotNull( value );
-            assertEquals( foo, value );
-        }
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
+        Foo foo = buildRandomFoo();
 
-        long time = 0;
-        for ( int i = 0; i < BENCHMARK_ROUNDS; i++ )
-        {
-            Foo foo = buildRandomFoo();
-
-            ByteArrayOutputStream baos = new ByteArrayOutputStream();
-            ObjectOutputStream out = new ObjectOutputStream( baos );
-            out.writeObject( foo );
-
-            long startTime = System.nanoTime();
-            ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
-            ObjectInputStream in = new ObjectInputStream( bais );
-            Object value = in.readObject();
-
-            time += System.nanoTime() - startTime;
-            assertNotNull( value );
-            assertEquals( foo, value );
-        }
-
-        double avg = time / (double) BENCHMARK_ROUNDS;
-        System.out.println( "Java Deserialization Avg: " + String.format( "%5.2f", avg ) + " ns, runs: "
-            + BENCHMARK_ROUNDS + ", size: " + size + " bytes" );
+        ByteArrayOutputStream baos = new ByteArrayOutputStream();
+        ObjectOutputStream out = new ObjectOutputStream( baos );
+        out.writeObject( foo );
+
+        ByteArrayInputStream bais = new ByteArrayInputStream( baos.toByteArray() );
+        ObjectInputStream in = new ObjectInputStream( bais );
+        Object value = in.readObject();
 
-        System.runFinalization();
-        System.gc();
-
-        try
-        {
-            Thread.sleep( 5000 );
-        }
-        catch ( Exception e )
-        {
-        }
+        assertNotNull( value );
+        assertEquals( foo, value );
     }
 
     private static final Random RANDOM = new Random( System.nanoTime() );

Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ConcurrentLightningBenchmark.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ConcurrentLightningBenchmark.java?rev=1405430&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ConcurrentLightningBenchmark.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/ConcurrentLightningBenchmark.java Sat Nov  3 22:01:47 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.directmemory.lightning;
+
+import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
+import com.carrotsearch.junitbenchmarks.Clock;
+import com.carrotsearch.junitbenchmarks.annotation.AxisRange;
+import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
+
+@AxisRange( min = 0, max = 1 )
+@BenchmarkMethodChart( filePrefix = "concurrent-benchmark" )
+@BenchmarkOptions( benchmarkRounds = 4000000, warmupRounds = 200000, clock = Clock.NANO_TIME, concurrency = BenchmarkOptions.CONCURRENCY_AVAILABLE_CORES )
+public class ConcurrentLightningBenchmark
+    extends AbstractLightningBenchmark
+{
+}

Copied: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/CustomBenchmark.java (from r1405131, directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java)
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/CustomBenchmark.java?p2=directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/CustomBenchmark.java&p1=directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java&r1=1405131&r2=1405430&rev=1405430&view=diff
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/Benchmark.java (original)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/CustomBenchmark.java Sat Nov  3 22:01:47 2012
@@ -43,7 +43,7 @@ import org.junit.Ignore;
 import org.junit.Test;
 
 @Ignore
-public class Benchmark
+public class CustomBenchmark
 {
 
     private static final int WARMUP_ROUNDS = 100000;
@@ -188,6 +188,7 @@ public class Benchmark
     }
 
     @Test
+    @Ignore
     public void benchmarkJavaSerialization()
         throws Exception
     {
@@ -244,6 +245,7 @@ public class Benchmark
     }
 
     @Test
+    @Ignore
     public void benchmarkJavaDeserialization()
         throws Exception
     {

Added: directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/SequentialLightningBenchmark.java
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/SequentialLightningBenchmark.java?rev=1405430&view=auto
==============================================================================
--- directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/SequentialLightningBenchmark.java (added)
+++ directmemory/lightning/trunk/lightning-core/src/test/java/org/apache/directmemory/lightning/SequentialLightningBenchmark.java Sat Nov  3 22:01:47 2012
@@ -0,0 +1,32 @@
+/*
+ * 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.directmemory.lightning;
+
+import com.carrotsearch.junitbenchmarks.BenchmarkOptions;
+import com.carrotsearch.junitbenchmarks.Clock;
+import com.carrotsearch.junitbenchmarks.annotation.AxisRange;
+import com.carrotsearch.junitbenchmarks.annotation.BenchmarkMethodChart;
+
+@AxisRange( min = 0, max = 1 )
+@BenchmarkMethodChart( filePrefix = "sequential-benchmark" )
+@BenchmarkOptions( benchmarkRounds = 2000000, warmupRounds = 200000, clock = Clock.NANO_TIME, concurrency = BenchmarkOptions.CONCURRENCY_SEQUENTIAL )
+public class SequentialLightningBenchmark
+    extends AbstractLightningBenchmark
+{
+}

Modified: directmemory/lightning/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directmemory/lightning/trunk/pom.xml?rev=1405430&r1=1405429&r2=1405430&view=diff
==============================================================================
--- directmemory/lightning/trunk/pom.xml (original)
+++ directmemory/lightning/trunk/pom.xml Sat Nov  3 22:01:47 2012
@@ -66,6 +66,7 @@
     <hppc.version>0.4.1</hppc.version>
     <asm.version>4.0</asm.version>
     <reflectasm.version>1.01</reflectasm.version>
+    <guava.version>13.0.1</guava.version>
 
     <junit.version>4.10</junit.version>
 
@@ -99,6 +100,11 @@
         <artifactId>hppc</artifactId>
         <version>${hppc.version}</version>
       </dependency>
+      <dependency>
+        <groupId>com.google.guava</groupId>
+        <artifactId>guava</artifactId>
+        <version>${guava.version}</version>
+      </dependency>
 
       <dependency>
         <groupId>junit</groupId>
@@ -106,6 +112,18 @@
         <version>${junit.version}</version>
         <scope>test</scope>
       </dependency>
+      <dependency>
+        <groupId>com.carrotsearch</groupId>
+        <artifactId>junit-benchmarks</artifactId>
+        <version>0.4.0</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>com.h2database</groupId>
+        <artifactId>h2</artifactId>
+        <version>1.3.164</version>
+        <scope>test</scope>
+      </dependency>
       <!-- Core dependencies -->
 
       <!-- Integration dependencies -->