Mercurial > stress-tester
changeset 624:d599f5455379
benchmarks
author | Devel 1 |
---|---|
date | Fri, 13 Oct 2017 14:47:13 +0200 |
parents | 758409ac6dad |
children | 96cfb7cf66f3 |
files | stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/AbstractValueExtractorBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark.java stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark2.java |
diffstat | 3 files changed, 215 insertions(+), 0 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/st/client/http/filter/AbstractValueExtractorBenchmark.java Fri Oct 13 14:47:13 2017 +0200 @@ -0,0 +1,112 @@ +package com.passus.st.client.http.filter; + +import com.passus.filter.ValueExtractor; +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 static com.passus.st.client.http.HttpConsts.TAG_SESSION_ID; +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 AbstractValueExtractorBenchmark { + + private final ValueExtractor reqVer = extractor("$req.version"); + private final ValueExtractor reqUri = extractor("$req.uri"); + private final ValueExtractor reqUriM = extractor("$req.getUri()"); + private final ValueExtractor reqUrl = extractor("$req.url"); + private final ValueExtractor reqUrlHost = extractor("$req.url.host"); + private final ValueExtractor reqCookie = extractor("$req.getCookie('abc')"); + private final ValueExtractor reqSid = extractor("$req.sessionId"); + private final ValueExtractor respStatusCode = extractor("$resp.status.code"); + private final ValueExtractor respHeader = extractor("$resp.getHeader('Content-Type')"); + private final ValueExtractor httpSessionVar = extractor("$httpSession.get('Var1')"); + + private final HttpRequest req = HttpRequestBuilder.get("http://test.com/logout") + .cookie("abc", "def").tag(TAG_SESSION_ID, "sid").build(); + private final HttpResponse resp = HttpResponseBuilder.ok().header("Content-Type", "binary").build(); + private final HttpMessageWrapper wrapper = new HttpMessageWrapper(req, resp, null); + + public abstract ValueExtractor extractor(String expr); + + @Setup + public static void beforeClass() { + AppUtils.registerAll(); + } + + @TearDown + public static void afterClass() { + AppUtils.unregisterAll(); + } + + @Benchmark + public Object reqVer() { + return reqVer.extract(wrapper); + } + + @Benchmark + public Object reqUri() { + return reqUri.extract(wrapper); + } + + @Benchmark + public Object reqUriM() { + return reqUriM.extract(wrapper); + } + + @Benchmark + public Object reqUrl() { + return reqUrl.extract(wrapper); + } + + @Benchmark + public Object reqUrlHost() { + return reqUrlHost.extract(wrapper); + } + + @Benchmark + public Object reqCookie() { + return reqCookie.extract(wrapper); + } + + @Benchmark + public Object reqSid() { + return reqSid.extract(wrapper); + } + + @Benchmark + public Object respStatusCode() { + return respStatusCode.extract(wrapper); + } + + @Benchmark + public Object respHeader() { + return respHeader.extract(wrapper); + } + + @Benchmark + public Object httpSessionVar() { + return httpSessionVar.extract(wrapper); + } + + static void checkResult(AbstractValueExtractorBenchmark bench) { + System.out.println(bench.reqVer()); + System.out.println(bench.reqUri()); + System.out.println(bench.reqUrl()); + System.out.println(bench.reqUrlHost()); + System.out.println(bench.reqCookie()); + System.out.println(bench.reqSid()); + System.out.println(bench.respStatusCode()); + System.out.println(bench.respHeader()); + System.out.println(bench.httpSessionVar()); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/client/http/filter/ValueExtractorBenchmark.java Fri Oct 13 14:47:13 2017 +0200 @@ -0,0 +1,50 @@ +package com.passus.st.client.http.filter; + +import com.passus.filter.ValueExtractor; +import com.passus.filter.ValueExtractorParser; +import java.text.ParseException; +import java.util.concurrent.TimeUnit; +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 ValueExtractorBenchmark extends AbstractValueExtractorBenchmark { + + @Override + public ValueExtractor extractor(String expr) { + try { + return ValueExtractorParser.DEFAULT.parse(expr); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + } + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder().include("[.]" + ValueExtractorBenchmark.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + + ValueExtractorBenchmark bench = new ValueExtractorBenchmark(); + beforeClass(); +// 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/ValueExtractorBenchmark2.java Fri Oct 13 14:47:13 2017 +0200 @@ -0,0 +1,53 @@ +package com.passus.st.client.http.filter; + +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; +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 ValueExtractorBenchmark2 extends AbstractValueExtractorBenchmark { + + public static final ValueExtractorParser BOOSTED = new ValueExtractorParser(new HttpMessageFieldExtractorFactory()); + + @Override + public ValueExtractor extractor(String expr) { + try { + return BOOSTED.parse(expr); + } catch (ParseException ex) { + throw new RuntimeException(ex); + } + } + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder().include("[.]" + ValueExtractorBenchmark2.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + + ValueExtractorBenchmark2 bench = new ValueExtractorBenchmark2(); + beforeClass(); +// checkAllocation(bench, 10_000_000); + checkResult(bench); + } + +}