changeset 619:26f51466052b

benchmarks
author Devel 1
date Thu, 12 Oct 2017 16:25:26 +0200
parents 28da18935579
children aa6f7460c240
files stress-tester-benchmark/nb-configuration.xml stress-tester-benchmark/nbactions-pred.xml stress-tester-benchmark/nbactions-pred2.xml stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/AbstractHttpMessagePredicateBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark2.java
diffstat 6 files changed, 249 insertions(+), 65 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester-benchmark/nb-configuration.xml	Thu Oct 12 16:25:02 2017 +0200
+++ b/stress-tester-benchmark/nb-configuration.xml	Thu Oct 12 16:25:26 2017 +0200
@@ -9,6 +9,8 @@
     <config-data xmlns="http://www.netbeans.org/ns/maven-config-data/1">
         <configurations>
             <configuration id="PacketCounter" profiles=""/>
+            <configuration id="pred2" profiles=""/>
+            <configuration id="pred" profiles=""/>
         </configurations>
     </config-data>
 </project-shared-configuration>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/nbactions-pred.xml	Thu Oct 12 16:25:26 2017 +0200
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+        <action>
+            <actionName>run</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark</exec.args>
+                <exec.executable>java</exec.executable>
+            </properties>
+        </action>
+        <action>
+            <actionName>debug</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark</exec.args>
+                <exec.executable>java</exec.executable>
+                <jpda.listen>true</jpda.listen>
+            </properties>
+        </action>
+        <action>
+            <actionName>profile</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark</exec.args>
+                <exec.executable>java</exec.executable>
+            </properties>
+        </action>
+    </actions>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/nbactions-pred2.xml	Thu Oct 12 16:25:26 2017 +0200
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<actions>
+        <action>
+            <actionName>run</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark2</exec.args>
+                <exec.executable>java</exec.executable>
+            </properties>
+        </action>
+        <action>
+            <actionName>debug</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-Xdebug -Xrunjdwp:transport=dt_socket,server=n,address=${jpda.address} -classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark2</exec.args>
+                <exec.executable>java</exec.executable>
+                <jpda.listen>true</jpda.listen>
+            </properties>
+        </action>
+        <action>
+            <actionName>profile</actionName>
+            <packagings>
+                <packaging>jar</packaging>
+            </packagings>
+            <goals>
+                <goal>process-classes</goal>
+                <goal>org.codehaus.mojo:exec-maven-plugin:1.2.1:exec</goal>
+            </goals>
+            <properties>
+                <exec.args>-classpath %classpath com.passus.st.client.http.filter.HttpMessagePredicateBenchmark2</exec.args>
+                <exec.executable>java</exec.executable>
+            </properties>
+        </action>
+    </actions>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/AbstractHttpMessagePredicateBenchmark.java	Thu Oct 12 16:25:26 2017 +0200
@@ -0,0 +1,96 @@
+package com.passus.st.client.http.filter;
+
+import com.passus.net.http.HttpRequest;
+import com.passus.net.http.HttpRequestBuilder;
+import com.passus.net.http.HttpResponse;
+import com.passus.net.http.HttpResponseBuilder;
+import com.passus.st.AppUtils;
+import com.passus.utils.AllocationUtils;
+import java.util.function.Predicate;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.Setup;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.TearDown;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+@State(Scope.Thread)
+public abstract class AbstractHttpMessagePredicateBenchmark {
+
+    private final Predicate reqGetCookie = predicate("{req.getCookie('abc'): def}");
+    private final Predicate respGetHeader = predicate("{resp.getHeader('abc'): '/logout'}");
+    private final Predicate reqUri = predicate("{req.uri: '/logout'}");
+    private final Predicate reqUrl = predicate("{req.url: '/logout'}");
+    private final Predicate respStatusCode = predicate("{resp.status.code: 200}");
+    private final Predicate compound = predicate("{req.uri: '/logout', req.url: '/logout', resp.status.code: 200}");
+
+    private final HttpRequest req = HttpRequestBuilder.get("http://test.com/logout")
+            .cookie("abc", "def").build();
+    private final HttpResponse resp = HttpResponseBuilder.ok().header("abc", "def").build();
+    private final HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, null);
+
+    public abstract Predicate predicate(String config);
+
+    @Setup
+    public static void beforeClass() {
+        AppUtils.registerAll();
+    }
+
+    @TearDown
+    public static void afterClass() {
+        AppUtils.unregisterAll();
+    }
+
+    @Benchmark
+    public Object reqUri() {
+        return reqUri.test(wrapper);
+    }
+
+    @Benchmark
+    public Object reqUrl() {
+        return reqUrl.test(wrapper);
+    }
+
+    @Benchmark
+    public Object compound() {
+        return compound.test(wrapper);
+    }
+
+    @Benchmark
+    public Object respStatusCode() {
+        return respStatusCode.test(wrapper);
+    }
+
+    @Benchmark
+    public Object xReqGetCookie() {
+        return reqGetCookie.test(wrapper);
+    }
+
+    @Benchmark
+    public Object xRespGetHeader() {
+        return respGetHeader.test(wrapper);
+    }
+
+    public static void checkAllocation(AbstractHttpMessagePredicateBenchmark bench, int count) throws Exception {
+        AllocationUtils au = new AllocationUtils();
+        au.setCount(count);
+        au.checkAllocation("reqCookie", bench::xReqGetCookie);
+        au.checkAllocation("respHdr", bench::xRespGetHeader);
+//        au.checkAllocation("compound", bench::compound);
+//        au.checkAllocation("reqUri", bench::reqUri);
+//        au.checkAllocation("reqUrl", bench::reqUrl);
+//        au.checkAllocation("respStatusCode", bench::respStatusCode);
+    }
+
+    public static void checkResult(AbstractHttpMessagePredicateBenchmark bench) {
+        System.out.println(bench.xReqGetCookie());
+        System.out.println(bench.xRespGetHeader());
+        System.out.println(bench.compound());
+        System.out.println(bench.reqUrl());
+        System.out.println(bench.reqUri());
+        System.out.println(bench.respStatusCode());
+    }
+}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Thu Oct 12 16:25:02 2017 +0200
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark.java	Thu Oct 12 16:25:26 2017 +0200
@@ -1,24 +1,15 @@
 package com.passus.st.client.http.filter;
 
 import com.passus.filter.config.PredicateNodeTransformer;
-import com.passus.net.http.HttpRequest;
-import com.passus.net.http.HttpRequestBuilder;
-import com.passus.net.http.HttpResponse;
-import com.passus.net.http.HttpResponseBuilder;
-import com.passus.st.AppUtils;
-import com.passus.utils.AllocationUtils;
 import java.util.concurrent.TimeUnit;
 import java.util.function.Predicate;
-import org.openjdk.jmh.annotations.Benchmark;
 import org.openjdk.jmh.annotations.BenchmarkMode;
 import org.openjdk.jmh.annotations.Fork;
 import org.openjdk.jmh.annotations.Measurement;
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.annotations.OutputTimeUnit;
 import org.openjdk.jmh.annotations.Scope;
-import org.openjdk.jmh.annotations.Setup;
 import org.openjdk.jmh.annotations.State;
-import org.openjdk.jmh.annotations.TearDown;
 import org.openjdk.jmh.annotations.Warmup;
 import org.openjdk.jmh.runner.Runner;
 import org.openjdk.jmh.runner.options.Options;
@@ -30,15 +21,16 @@
  */
 @State(Scope.Thread)
 @BenchmarkMode(Mode.AverageTime)
-@OutputTimeUnit(TimeUnit.MICROSECONDS)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
 @Fork(value = 1)
 @Measurement(iterations = 6)
-@Warmup(iterations = 6)
-public class HttpMessagePredicateBenchmark {
+@Warmup(iterations = 4)
+public class HttpMessagePredicateBenchmark extends AbstractHttpMessagePredicateBenchmark {
 
     private static final PredicateNodeTransformer TRANSFORMER = new PredicateNodeTransformer();
 
-    private static Predicate predicate(String config) {
+    @Override
+    public Predicate predicate(String config) {
         try {
             return TRANSFORMER.transform(config);
         } catch (Exception e) {
@@ -46,62 +38,13 @@
         }
     }
 
-    private final Predicate reqUriPred = predicate("{req.uri: '/logout'}");
-    private final Predicate reqUrlPred = predicate("{req.url: '/logout'}");
-    private final Predicate respStatusCodePred = predicate("{resp.status.code: 200}");
-    private final Predicate compound = predicate("{req.uri: '/logout', req.url: '/logout', resp.status.code: 200}");
-
-    private final HttpRequest req = HttpRequestBuilder.get("http://test.com/logout").build();
-    private final HttpResponse resp = HttpResponseBuilder.ok().build();
-    private final HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, null);
-
-    @Setup
-    public static void beforeClass() {
-        AppUtils.registerAll();
-    }
-
-    @TearDown
-    public static void afterClass() {
-        AppUtils.unregisterAll();
-    }
-
-    @Benchmark
-    public Object reqUriPred() {
-        return reqUriPred.test(wrapper);
-    }
-
-    @Benchmark
-    public Object reqUrlPred() {
-        return reqUrlPred.test(wrapper);
-    }
-
-    @Benchmark
-    public Object compound() {
-        return compound.test(wrapper);
-    }
-
-    @Benchmark
-    public Object respStatusCodePred() {
-        return respStatusCodePred.test(wrapper);
-    }
-
     public static void main(String[] args) throws Exception {
         Options opt = new OptionsBuilder().include(HttpMessagePredicateBenchmark.class.getSimpleName() + ".*").build();
         new Runner(opt).run();
 
-        HttpMessagePredicateBenchmark bench = new HttpMessagePredicateBenchmark();
         beforeClass();
-
-        AllocationUtils au = new AllocationUtils();
-        au.setCount(30_000);
-        au.checkAllocation("compound", bench::compound);
-        au.checkAllocation("reqUri", bench::reqUriPred);
-        au.checkAllocation("reqUrl", bench::reqUrlPred);
-        au.checkAllocation("respStatusCode", bench::respStatusCodePred);
-
-        System.out.println(bench.compound());
-        System.out.println(bench.reqUrlPred());
-        System.out.println(bench.reqUriPred());
-        System.out.println(bench.respStatusCodePred());
+        HttpMessagePredicateBenchmark bench = new HttpMessagePredicateBenchmark();
+        checkAllocation(bench, 10_000_000);
+        checkResult(bench);
     }
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark2.java	Thu Oct 12 16:25:26 2017 +0200
@@ -0,0 +1,51 @@
+package com.passus.st.client.http.filter;
+
+import com.passus.filter.config.PredicateNodeTransformer;
+import com.passus.st.filter.HttpMessageFieldExtractorFactory;
+import java.util.concurrent.TimeUnit;
+import java.util.function.Predicate;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Measurement;
+import org.openjdk.jmh.annotations.Mode;
+import org.openjdk.jmh.annotations.OutputTimeUnit;
+import org.openjdk.jmh.annotations.Scope;
+import org.openjdk.jmh.annotations.State;
+import org.openjdk.jmh.annotations.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ *
+ * @author mikolaj.podbielski
+ */
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Fork(value = 1)
+@Measurement(iterations = 6)
+@Warmup(iterations = 4)
+public class HttpMessagePredicateBenchmark2 extends AbstractHttpMessagePredicateBenchmark {
+
+    private static final PredicateNodeTransformer TRANSFORMER2 = new PredicateNodeTransformer(new HttpMessageFieldExtractorFactory());
+
+    @Override
+    public Predicate predicate(String config) {
+        try {
+            return TRANSFORMER2.transform(config);
+        } catch (Exception e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+    }
+
+    public static void main(String[] args) throws Exception {
+        Options opt = new OptionsBuilder().include(HttpMessagePredicateBenchmark2.class.getSimpleName() + ".*").build();
+//        new Runner(opt).run();
+
+        HttpMessagePredicateBenchmark2 bench = new HttpMessagePredicateBenchmark2();
+        beforeClass();
+        checkAllocation(bench, 10_000_000);
+        checkResult(bench);
+    }
+}