You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/07/15 12:12:02 UTC
[1/3] camel git commit: CAMEL-XXX Add JMH benchmarks for TypeConverter
Repository: camel
Updated Branches:
refs/heads/master 1131374e2 -> 32edf80c5
CAMEL-XXX Add JMH benchmarks for TypeConverter
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/d7c29069
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/d7c29069
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/d7c29069
Branch: refs/heads/master
Commit: d7c2906937186c7113ca01838f2496eb08b2bcdc
Parents: 1131374
Author: Lachowicz, Marcin <la...@gmail.com>
Authored: Thu Jul 13 17:32:31 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 15 13:34:02 2017 +0200
----------------------------------------------------------------------
.../camel/itest/jmh/TypeConverterTest.java | 105 +++++++++++++++----
.../src/test/resources/sample_soap.xml | 33 ++++++
2 files changed, 116 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/d7c29069/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
index c51c8f8..912225e 100644
--- a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
+++ b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
@@ -16,14 +16,20 @@
*/
package org.apache.camel.itest.jmh;
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.Scanner;
import java.util.concurrent.TimeUnit;
+import org.w3c.dom.Document;
+
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
-import org.openjdk.jmh.annotations.Measurement;
import org.openjdk.jmh.annotations.Mode;
import org.openjdk.jmh.annotations.Scope;
import org.openjdk.jmh.annotations.Setup;
@@ -43,21 +49,22 @@ public class TypeConverterTest {
@Test
public void launchBenchmark() throws Exception {
Options opt = new OptionsBuilder()
- // Specify which benchmarks to run.
- // You can be more specific if you'd like to run only one benchmark per test.
- .include(this.getClass().getName() + ".*")
- // Set the following options as needed
- .mode(Mode.All)
- .timeUnit(TimeUnit.MICROSECONDS)
- .warmupTime(TimeValue.seconds(1))
- .warmupIterations(2)
- .measurementTime(TimeValue.seconds(1))
- .measurementIterations(2)
- .threads(2)
- .forks(1)
- .shouldFailOnError(true)
- .shouldDoGC(true)
- .build();
+ // Specify which benchmarks to run.
+ // You can be more specific if you'd like to run only one benchmark per test.
+ .include(this.getClass().getName() + ".*")
+ // Set the following options as needed
+ .mode(Mode.SampleTime)
+ .timeUnit(TimeUnit.MILLISECONDS)
+ .warmupTime(TimeValue.seconds(1))
+ .warmupIterations(2)
+ .measurementTime(TimeValue.seconds(5))
+ .measurementIterations(3)
+ .threads(1)
+ .forks(1)
+ .shouldFailOnError(true)
+ .shouldDoGC(true)
+ .measurementBatchSize(100000)
+ .build();
new Runner(opt).run();
}
@@ -65,17 +72,25 @@ public class TypeConverterTest {
// The JMH samples are the best documentation for how to use it
// http://hg.openjdk.java.net/code-tools/jmh/file/tip/jmh-samples/src/main/java/org/openjdk/jmh/samples/
@State(Scope.Thread)
- public static class BenchmarkState {
+ public static class BenchmarkCamelContextState {
+ Integer someInteger = 12345;
+ String someIntegerString = String.valueOf(someInteger);
+ String xmlAsString;
+ byte[] xmlAsBytes;
+
CamelContext camel;
@Setup(Level.Trial)
- public void initialize() {
+ public void initialize() throws IOException {
camel = new DefaultCamelContext();
try {
camel.start();
} catch (Exception e) {
// ignore
}
+
+ xmlAsString = getResourceAsString("sample_soap.xml");
+ xmlAsBytes = xmlAsString.getBytes(StandardCharsets.UTF_8);
}
@TearDown(Level.Trial)
@@ -87,13 +102,59 @@ public class TypeConverterTest {
}
}
+ private String getResourceAsString(String resource) {
+ Scanner s = new Scanner(getClass().getClassLoader().getResourceAsStream(resource))
+ .useDelimiter("\\A");
+ return s.hasNext() ? s.next() : "";
+ }
}
+
@Benchmark
- @Measurement(batchSize = 1000000)
- public void typeConvertIntegerToString(BenchmarkState state, Blackhole bh) {
- String id = state.camel.getTypeConverter().convertTo(String.class, 12345);
- bh.consume(id);
+ public void typeConvertIntegerToString(BenchmarkCamelContextState state, Blackhole bh) {
+ String string = state.camel.getTypeConverter().convertTo(String.class, state.someInteger);
+ bh.consume(string);
}
+ @Benchmark
+ public void typeConvertStringToInteger(BenchmarkCamelContextState state, Blackhole bh) {
+ Integer integer = state.camel.getTypeConverter().convertTo(Integer.class, state.someIntegerString);
+ bh.consume(integer);
+ }
+
+ @Benchmark
+ public void typeConvertTheSameTypes(BenchmarkCamelContextState state, Blackhole bh) {
+ String string = state.camel.getTypeConverter().convertTo(String.class, state.someIntegerString);
+ bh.consume(string);
+ }
+
+ @Benchmark
+ public void typeConvertInputStreamToString(BenchmarkCamelContextState state, Blackhole bh) {
+ String string = state.camel.getTypeConverter().convertTo(String.class, new ByteArrayInputStream(state.xmlAsBytes));
+ bh.consume(string);
+ }
+
+ @Benchmark
+ public void typeConvertStringToInputStream(BenchmarkCamelContextState state, Blackhole bh) {
+ InputStream inputStream = state.camel.getTypeConverter().convertTo(InputStream.class, state.xmlAsString);
+ bh.consume(inputStream);
+ }
+
+ @Benchmark
+ public void typeConvertStringToDocument(BenchmarkCamelContextState state, Blackhole bh) {
+ Document document = state.camel.getTypeConverter().convertTo(Document.class, state.xmlAsString);
+ bh.consume(document);
+ }
+
+ @Benchmark
+ public void typeConvertStringToByteArray(BenchmarkCamelContextState state, Blackhole bh) {
+ byte[] bytes = state.camel.getTypeConverter().convertTo(byte[].class, state.xmlAsString);
+ bh.consume(bytes);
+ }
+
+ @Benchmark
+ public void typeConvertByteArrayToString(BenchmarkCamelContextState state, Blackhole bh) {
+ String string = state.camel.getTypeConverter().convertTo(String.class, state.xmlAsBytes);
+ bh.consume(string);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/d7c29069/tests/camel-jmh/src/test/resources/sample_soap.xml
----------------------------------------------------------------------
diff --git a/tests/camel-jmh/src/test/resources/sample_soap.xml b/tests/camel-jmh/src/test/resources/sample_soap.xml
new file mode 100644
index 0000000..6800482
--- /dev/null
+++ b/tests/camel-jmh/src/test/resources/sample_soap.xml
@@ -0,0 +1,33 @@
+<?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.
+
+-->
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
+ <soapenv:Header><routing xmlns="http://someuri">xadmin;server1;community#1.0##</routing></soapenv:Header>
+ <soapenv:Body>
+ <m:buyStocks xmlns:m="http://services.samples/xsd">
+ <order><symbol>IBM</symbol><buyerID>asankha</buyerID><price>140.34</price><volume>2000</volume></order>
+ <order><symbol>MSFT</symbol><buyerID>ruwan</buyerID><price>23.56</price><volume>8030</volume></order>
+ <order><symbol>SUN</symbol><buyerID>indika</buyerID><price>14.56</price><volume>500</volume></order>
+ <order><symbol>GOOG</symbol><buyerID>chathura</buyerID><price>60.24</price><volume>40000</volume></order>
+ <order><symbol>IBM</symbol><buyerID>asankha</buyerID><price>140.34</price><volume>2000</volume></order>
+ <order><symbol>MSFT</symbol><buyerID>ruwan</buyerID><price>23.56</price><volume>803000</volume></order>
+ <order><symbol>SUN</symbol><buyerID>indika</buyerID><price>14.56</price><volume>5000</volume></order>
+ </m:buyStocks>
+ </soapenv:Body>
+</soapenv:Envelope>
\ No newline at end of file
[2/3] camel git commit: CAMEL-XXX Add JMH benchmarks for
TypeConverter - replace Scanner with IOHelper for reading file,
fix checkstyle in SimpleMockTest.java
Posted by da...@apache.org.
CAMEL-XXX Add JMH benchmarks for TypeConverter - replace Scanner with IOHelper for reading file, fix checkstyle in SimpleMockTest.java
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/320eff0b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/320eff0b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/320eff0b
Branch: refs/heads/master
Commit: 320eff0ba334be6932ce381bb9b26a59093a0940
Parents: d7c2906
Author: Lachowicz, Marcin <la...@gmail.com>
Authored: Sat Jul 15 13:03:01 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 15 13:34:03 2017 +0200
----------------------------------------------------------------------
.../org/apache/camel/itest/jmh/TypeConverterTest.java | 10 ++--------
1 file changed, 2 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/320eff0b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
----------------------------------------------------------------------
diff --git a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
index 912225e..329ea5b 100644
--- a/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
+++ b/tests/camel-jmh/src/test/java/org/apache/camel/itest/jmh/TypeConverterTest.java
@@ -20,13 +20,13 @@ import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
-import java.util.Scanner;
import java.util.concurrent.TimeUnit;
import org.w3c.dom.Document;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.DefaultCamelContext;
+import org.apache.camel.util.IOHelper;
import org.junit.Test;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Level;
@@ -89,7 +89,7 @@ public class TypeConverterTest {
// ignore
}
- xmlAsString = getResourceAsString("sample_soap.xml");
+ xmlAsString = IOHelper.loadText(getClass().getClassLoader().getResourceAsStream("sample_soap.xml"));
xmlAsBytes = xmlAsString.getBytes(StandardCharsets.UTF_8);
}
@@ -101,12 +101,6 @@ public class TypeConverterTest {
// ignore
}
}
-
- private String getResourceAsString(String resource) {
- Scanner s = new Scanner(getClass().getClassLoader().getResourceAsStream(resource))
- .useDelimiter("\\A");
- return s.hasNext() ? s.next() : "";
- }
}
[3/3] camel git commit: Add longer timeout for jmh tests
Posted by da...@apache.org.
Add longer timeout for jmh tests
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/32edf80c
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/32edf80c
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/32edf80c
Branch: refs/heads/master
Commit: 32edf80c5a9dda2ad48e0317cbf32552f3a196a4
Parents: 320eff0
Author: Claus Ibsen <da...@apache.org>
Authored: Sat Jul 15 14:11:41 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Sat Jul 15 14:11:41 2017 +0200
----------------------------------------------------------------------
tests/camel-jmh/pom.xml | 1 +
1 file changed, 1 insertion(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/32edf80c/tests/camel-jmh/pom.xml
----------------------------------------------------------------------
diff --git a/tests/camel-jmh/pom.xml b/tests/camel-jmh/pom.xml
index c1514cc..abd4ff8 100644
--- a/tests/camel-jmh/pom.xml
+++ b/tests/camel-jmh/pom.xml
@@ -125,6 +125,7 @@
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin-version}</version>
<configuration>
+ <forkedProcessTimeoutInSeconds>1800</forkedProcessTimeoutInSeconds>
<includes>
<include>**/*Test.java</include>
</includes>