changeset 784:263f92f87cbc

DataProcessorChainBenchmark
author Devel 2
date Wed, 20 Dec 2017 10:30:04 +0100
parents a4b90beadbe2
children 4619da758ec7
files stress-tester-benchmark/src/main/java/com/passus/data/DataProcessorChainBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark2.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark2.java
diffstat 3 files changed, 127 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester-benchmark/src/main/java/com/passus/data/DataProcessorChainBenchmark.java	Wed Dec 20 10:30:04 2017 +0100
@@ -0,0 +1,125 @@
+package com.passus.data;
+
+import com.passus.data.compression.GZIPDecompressionProcessor;
+import com.passus.data.compression.InflaterProcessor;
+import com.passus.data.utils.CompressionUtils;
+import java.io.IOException;
+import java.util.Random;
+import java.util.concurrent.TimeUnit;
+import org.openjdk.jmh.annotations.Benchmark;
+import org.openjdk.jmh.annotations.BenchmarkMode;
+import org.openjdk.jmh.annotations.Fork;
+import org.openjdk.jmh.annotations.Level;
+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.Warmup;
+import org.openjdk.jmh.runner.Runner;
+import org.openjdk.jmh.runner.RunnerException;
+import org.openjdk.jmh.runner.options.Options;
+import org.openjdk.jmh.runner.options.OptionsBuilder;
+
+/**
+ *
+ * @author Mirosław Hawrot
+ */
+@State(Scope.Thread)
+@BenchmarkMode(Mode.AverageTime)
+@OutputTimeUnit(TimeUnit.NANOSECONDS)
+@Fork(value = 1)
+@Measurement(iterations = 10)
+@Warmup(iterations = 0)
+public class DataProcessorChainBenchmark {
+
+    private final int dataSize = 64 * 1024;
+
+    private final byte[] data = new byte[dataSize];
+
+    private final byte[] deflated;
+    private final byte[] gziped;
+    private final byte[] gziped2;
+
+    private final ByteBuff in;
+
+    private final PooledAllocator pooledAllocator = new PooledAllocator(dataSize * 2, 4, 0);
+
+    private ByteBuff out = new HeapByteBuff(data.length * 2);
+
+    public DataProcessorChainBenchmark() {
+        try {
+            Random rand = new Random();
+            rand.nextBytes(data);
+
+            deflated = CompressionUtils.deflate(data);
+            gziped = CompressionUtils.gzip(deflated);
+            gziped2 = CompressionUtils.gzip(gziped);
+
+            in = new HeapByteBuff(gziped2);
+        } catch (Exception e) {
+            throw new RuntimeException(e);
+        }
+    }
+
+    private DataProcessorChain prepareChain(Allocator allocator) {
+        GZIPDecompressionProcessor gzipProc = new GZIPDecompressionProcessor();
+        GZIPDecompressionProcessor gzipProc2 = new GZIPDecompressionProcessor();
+        InflaterProcessor inflaterProcessor = new InflaterProcessor();
+        DataProcessorChain chain = new DataProcessorChain(gzipProc, gzipProc2, inflaterProcessor);
+        if (allocator != null) {
+            chain.setAllocator(allocator);
+        }
+
+        chain.open();
+        return chain;
+    }
+
+    @Setup(Level.Iteration)
+    public void setUp() {
+        out.clear();
+    }
+
+    @Benchmark
+    public int measureProcess_DefaultAllocator() {
+        int res;
+        try (DataProcessorChain chain = prepareChain(null)) {
+            res = chain.process(in, out);
+        }
+        return res;
+    }
+
+    @Benchmark
+    public int measureProcess_PooledAllocator() {
+        int res;
+        try (DataProcessorChain chain = prepareChain(pooledAllocator)) {
+            res = chain.process(in, out);
+        }
+        return res;
+    }
+
+    public static void main(String[] args) throws RunnerException, IOException, Exception {
+        Options opt = new OptionsBuilder().include(DataProcessorChainBenchmark.class.getSimpleName() + ".*").build();
+        new Runner(opt).run();
+
+        /*DataProcessorChainBenchmark bench = new DataProcessorChainBenchmark();
+        System.out.println("usedSize: " + bench.pooledAllocator.usedSize());
+        System.out.println("unusedSize: " + bench.pooledAllocator.unusedSize());
+        
+        long start = System.currentTimeMillis();
+        for (int i = 0; i < 1_000_000; i++) {
+            //bench.measureProcess_DefaultAllocator();
+            bench.measureProcess_PooledAllocator();
+            bench.out.clear();
+        }
+
+        //
+        System.out.println("duration: " + (System.currentTimeMillis() - start));
+        System.out.println("usedSize: " + bench.pooledAllocator.usedSize());
+        System.out.println("unusedSize: " + bench.pooledAllocator.unusedSize());
+        System.out.println("created: " + bench.pooledAllocator.created());*/
+
+    }
+
+}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark2.java	Wed Dec 20 10:29:41 2017 +0100
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/HttpMessagePredicateBenchmark2.java	Wed Dec 20 10:30:04 2017 +0100
@@ -1,7 +1,6 @@
 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;
@@ -27,7 +26,7 @@
 @Warmup(iterations = 4)
 public class HttpMessagePredicateBenchmark2 extends AbstractHttpMessagePredicateBenchmark {
 
-    private static final PredicateNodeTransformer TRANSFORMER2 = new PredicateNodeTransformer(new HttpMessageFieldExtractorFactory());
+    private static final PredicateNodeTransformer TRANSFORMER2 = new PredicateNodeTransformer();
 
     @Override
     public Predicate predicate(String config) {
--- a/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark2.java	Wed Dec 20 10:29:41 2017 +0100
+++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark2.java	Wed Dec 20 10:30:04 2017 +0100
@@ -2,7 +2,6 @@
 
 import com.passus.filter.ValueExtractor;
 import com.passus.filter.ValueExtractorParser;
-import com.passus.st.filter.HttpMessageFieldExtractorFactory;
 import java.text.ParseException;
 import java.util.concurrent.TimeUnit;
 import org.openjdk.jmh.annotations.BenchmarkMode;
@@ -29,7 +28,7 @@
 @Warmup(iterations = 4)
 public class ValueExtractorBenchmark2 extends AbstractValueExtractorBenchmark {
 
-    public static final ValueExtractorParser BOOSTED = new ValueExtractorParser(new HttpMessageFieldExtractorFactory());
+    public static final ValueExtractorParser BOOSTED = new ValueExtractorParser();
 
     @Override
     public ValueExtractor extractor(String expr) {