Mercurial > stress-tester
changeset 603:c70bc3304737
stress-tester-benchmark - fixed compilation, cleanup
line wrap: on
line diff
--- a/stress-tester-benchmark/src/main/java/com/passus/http/CookieDate.java Fri Oct 06 09:12:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,79 +0,0 @@ -package com.passus.http; - -import com.passus.st.protocol.http.HttpDateFormatter; -import com.passus.st.protocol.http.HttpSetCookieDecoder; -import java.time.LocalDateTime; -import java.time.ZoneId; -import java.time.format.DateTimeFormatter; -import java.util.Date; -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.Measurement; -import org.openjdk.jmh.annotations.Mode; -import org.openjdk.jmh.annotations.OutputTimeUnit; -import org.openjdk.jmh.annotations.Param; -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.RunnerException; -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 = 5) -public class CookieDate { - - private static final long DATE_MILLIS = 1252487340_000L; // Wed Sep 09 11:09:00 CEST 2009 - - private static final String[] STRINGS = { - "Wed, 09-Sep-2009 09:09:00 GMT", - "Wed, 09 Sep 2009 09:09:00 GMT", - "Wed Sep 09 2009 09:09:00 GMT+0000", - "Wed, 09-Sep-09 09:09:00 GMT", - "Wed, 09 Sep 09 09:09:00 GMT", - "Wednesday, 09-Sep-09 09:09:00 GMT", - "blah" - }; - - @Param({"0", "1", "2", "3", "4", "5", "6"}) - private int idx; - -// @Benchmark - public long parse0HttpCookieDecoder() { - return HttpSetCookieDecoder.parseMaxAge(STRINGS[idx]); - } - -// @Benchmark - public Date parse1Netty() { - return io.netty.handler.codec.DateFormatter.parseHttpDate(STRINGS[idx]); - } - -// @Benchmark - public Date parse2JDK() { - LocalDateTime ldt = LocalDateTime.parse(STRINGS[idx], DateTimeFormatter.RFC_1123_DATE_TIME); - return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); - } - - @Benchmark - public Date parse2NettyCopy() { - return HttpDateFormatter.parseHttpDate(STRINGS[idx]); - } - - - public static void main(String[] args) throws RunnerException { - HttpDateFormatter.parseHttpDate(STRINGS[0]); - Options opt = new OptionsBuilder().include(CookieDate.class.getSimpleName() + ".*").build(); - new Runner(opt).run(); - } -}
--- a/stress-tester-benchmark/src/main/java/com/passus/http/HttpCookieDecoderBenchmark.java Fri Oct 06 09:12:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,59 +0,0 @@ -package com.passus.http; - -import com.passus.ambience.protocol.http.HttpCookieHeaderParser; -import com.passus.st.data.ByteString; -import com.passus.st.data.ByteStringImpl; -import com.passus.st.protocol.http.HttpCookie; -import com.passus.st.protocol.http.HttpSetCookieDecoder; -import java.util.List; -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.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.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 = 6) -@Warmup(iterations = 4) -public class HttpCookieDecoderBenchmark { - - private HttpSetCookieDecoder setCookieDecoder = new HttpSetCookieDecoder(); - - private String setCookieHeader = "someCookie=someValue;path=/somepath;domain = somedomain ; HttpOnly; Secure;"; - - private ByteString setCookieHeaderBs = new ByteStringImpl(setCookieHeader); - - @Benchmark - public int decode_HttpSetCookieDecoder() { - HttpCookie cookie = setCookieDecoder.decode(setCookieHeaderBs, 0, false); - return cookie.getVersion(); - } - - @Benchmark - public int decode_HttpCookieHeaderParser() { - List<java.net.HttpCookie> cookies = HttpCookieHeaderParser.parseSetCookieHeader(setCookieHeader); - return cookies.size(); - } - - public static void main(String[] args) throws RunnerException { - Options opt = new OptionsBuilder().include(HttpCookieDecoderBenchmark.class.getSimpleName() + ".*").build(); - new Runner(opt).run(); - } - -}
--- a/stress-tester-benchmark/src/main/java/com/passus/http/HttpDigestMD5Benchmark.java Fri Oct 06 09:12:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,147 +0,0 @@ -package com.passus.http; - -import com.passus.data.ByteBuff; -import com.passus.data.ByteString; -import com.passus.data.ByteStringImpl; -import com.passus.data.HeapByteBuff; -import com.passus.utils.AllocationUtils; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.concurrent.TimeUnit; -import org.bouncycastle.jce.provider.JDKMessageDigest; -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.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 HttpDigestMD5Benchmark { - - private final byte COLON = ':'; - private final byte[] user = "user".getBytes(); - private final byte[] password = "password".getBytes(); - private final byte[] realm = "11111111112222222222333333333344".getBytes(); - private final ByteString ubs = new ByteStringImpl(user); - private final ByteString rbs = new ByteStringImpl(realm); - private final ByteString pbs = new ByteStringImpl(password); - - @Benchmark - public MessageDigest getMD5() throws NoSuchAlgorithmException { - return MessageDigest.getInstance("MD5"); - } - - @Benchmark - public JDKMessageDigest.MD5 getMD5BC() { - return new JDKMessageDigest.MD5(); - } - - @Benchmark - public byte[] digestMultiCall() throws NoSuchAlgorithmException { - MessageDigest md = getMD5(); - md.update(user); - md.update(COLON); - md.update(realm); - md.update(COLON); - md.update(password); - return md.digest(); - } - - @Benchmark - public byte[] digestWithBuffer() throws NoSuchAlgorithmException { - MessageDigest md = getMD5(); - byte[] buff = new byte[user.length + realm.length + password.length + 2]; - System.arraycopy(user, 0, buff, 0, user.length); - buff[user.length] = COLON; - System.arraycopy(realm, 0, buff, user.length + 1, realm.length); - buff[user.length + realm.length + 1] = COLON; - System.arraycopy(password, 0, buff, user.length + realm.length + 2, password.length); - return md.digest(buff); - } - - @Benchmark - public byte[] digestMultiCallBC() { - JDKMessageDigest.MD5 md = getMD5BC(); - md.update(user); - md.update(COLON); - md.update(realm); - md.update(COLON); - md.update(password); - return md.digest(); - } - - @Benchmark - public byte[] digestWithBufferBC() { - JDKMessageDigest.MD5 md = getMD5BC(); - byte[] buff = new byte[user.length + realm.length + password.length + 2]; - System.arraycopy(user, 0, buff, 0, user.length); - buff[user.length] = COLON; - System.arraycopy(realm, 0, buff, user.length + 1, realm.length); - buff[user.length + realm.length + 1] = COLON; - System.arraycopy(password, 0, buff, user.length + realm.length + 2, password.length); - return md.digest(buff); - } - -// @Benchmark -// public byte[] copy() { -// JDKMessageDigest.MD5 md = getMD5BC(); -// md.update(ubs.getBytes()); -// md.update(COLON); -// md.update(rbs.getBytes()); -// md.update(COLON); -// md.update(pbs.getBytes()); -// return md.digest(); -// } - - public static void main(String[] args) throws Exception { - Options opt = new OptionsBuilder().include(HttpDigestMD5Benchmark.class.getSimpleName() + ".*").build(); - new Runner(opt).run(); - - HttpDigestMD5Benchmark bench = new HttpDigestMD5Benchmark(); - - AllocationUtils au = new AllocationUtils(); - au.checkAllocation("jdk-mc", bench::digestMultiCall); - au.checkAllocation(" bc-mc", bench::digestMultiCallBC); - au.checkAllocation("jdk-buff", bench::digestWithBuffer); - au.checkAllocation(" bc-buff", bench::digestWithBufferBC); - - printHex(bench.digestMultiCall()); - printHex(bench.digestMultiCallBC()); - printHex(bench.digestWithBuffer()); - printHex(bench.digestWithBufferBC()); - } - - private final static char[] HEX = { - '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' - }; - - public static String bytesToHex(byte[] bytes) { - char[] hexChars = new char[bytes.length * 2]; - for (int j = 0; j < bytes.length; j++) { - int v = bytes[j] & 0xFF; - hexChars[j * 2] = HEX[v >>> 4]; - hexChars[j * 2 + 1] = HEX[v & 0x0F]; - } - return new String(hexChars); - } - - public static void printHex(byte[] bytes) { - System.out.println(bytesToHex(bytes)); - } -}
--- a/stress-tester-benchmark/src/main/java/com/passus/http/HttpRequestDecodingBenchmark.java Fri Oct 06 09:12:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,109 +0,0 @@ -package com.passus.http; - -import com.passus.st.protocol.http.HttpHeadersDecoder; -import com.passus.st.protocol.http.HttpRequestDecoder; -import com.passus.utils.AllocationUtils; -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; -import org.openjdk.jmh.annotations.Benchmark; - -/** - * - * @author Mirosław Hawrot - */ -@State(Scope.Thread) -@BenchmarkMode(Mode.AverageTime) -@OutputTimeUnit(TimeUnit.NANOSECONDS) -@Fork(value = 1) -@Measurement(iterations = 6) -@Warmup(iterations = 4) -public class HttpRequestDecodingBenchmark { - - private String headersStr = "Host: testHost\r\n" - + "Host2:testHost2\r\n" - + "\r\n"; - - private byte[] headersBytes; - - private String reqStr = "GET /resource HTTP/1.1\r\n" - + headersStr; - - private byte[] reqBytes; - - { - try { - reqBytes = reqStr.getBytes("US-ASCII"); - headersBytes = headersStr.getBytes("US-ASCII"); - } catch (Exception e) { - } - } - - private com.passus.ambience.protocol.http.HttpRequest ambRequest = new com.passus.ambience.protocol.http.HttpRequest(); - - private HttpRequestDecoder decoderStrict = new HttpRequestDecoder(true); - - private HttpRequestDecoder decoderNotStrict = new HttpRequestDecoder(false); - - private HttpHeadersDecoder headersDecoderNotStrict = new HttpHeadersDecoder(false); - - @Benchmark - public int testAmbDecoder() throws Exception { - com.passus.ambience.protocol.http.HttpRequest ambRequest = new com.passus.ambience.protocol.http.HttpRequest(); - return ambRequest.decode(reqBytes, 0); - } - - //@Benchmark - public int testDecoder_Strict() throws Exception { - return decoderStrict.decode(reqBytes); - } - - //@Benchmark - public int testDecoder_NotStrict() throws Exception { - return decoderNotStrict.decode(reqBytes); - } - - @Benchmark - public int testHeadersDecoder_NotStrict() throws Exception { - int res = headersDecoderNotStrict.decode(headersBytes); - headersDecoderNotStrict.clear(); - return res; - } - - public static void main(String[] args) throws Exception { - //Options opt = new OptionsBuilder().include(HttpRequestDecodingBenchmark.class.getSimpleName() + ".*").build(); - //new Runner(opt).run(); - - HttpRequestDecodingBenchmark bench = new HttpRequestDecodingBenchmark(); - //System.out.println(bench.testAmbDecoder()); - //System.out.println(bench.testDecoder_Strict()); - //System.out.println(bench.testDecoder_NotStrict()); - long start = System.currentTimeMillis(); - for (int i = 0; i < 100000; i++) { - bench.testAmbDecoder(); - } - System.out.println(System.currentTimeMillis() - start); - - start = System.currentTimeMillis(); - for (int i = 0; i < 100000; i++) { - bench.testHeadersDecoder_NotStrict(); - } - System.out.println(System.currentTimeMillis() - start); - - AllocationUtils au = new AllocationUtils(); - au.setOverheadBase(bench.headersStr.length()); - au.checkAllocation("AmbienceDecoder", bench::testAmbDecoder); - au.checkAllocation("HeadersNotStrict", bench::testHeadersDecoder_NotStrict); - au.checkAllocation("NotStrict", bench::testDecoder_NotStrict); - au.checkAllocation("Strict", bench::testDecoder_Strict); - } -}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/avro/AvroCustomBenchmark.java Fri Oct 06 09:12:38 2017 +0200 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/avro/AvroCustomBenchmark.java Fri Oct 06 10:03:29 2017 +0200 @@ -1,6 +1,6 @@ package com.passus.st.avro; -import com.passus.st.reporter.trx.Server; +import com.passus.st.reporter.trx.NettyReporterServer; import com.passus.st.reporter.trx.SocketReporterClient; import com.passus.utils.AllocationUtils; import java.io.IOException; @@ -34,7 +34,7 @@ @Warmup(iterations = 7) public class AvroCustomBenchmark extends AbstractAvroBenchmark { - private final Server server = new Server(serverAddress, new DummyReporter()); + private final NettyReporterServer server = new NettyReporterServer(serverAddress, new DummyReporter()); private final SocketReporterClient client = new SocketReporterClient(serverAddress, 4, new SynchronousQueue<>(), false); private final TestMetric metric = new TestMetric();
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/protocol/http/CookieDate.java Fri Oct 06 10:03:29 2017 +0200 @@ -0,0 +1,79 @@ +package com.passus.st.protocol.http; + +import com.passus.st.protocol.http.HttpDateFormatter; +import com.passus.st.protocol.http.HttpSetCookieDecoder; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.Date; +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.Measurement; +import org.openjdk.jmh.annotations.Mode; +import org.openjdk.jmh.annotations.OutputTimeUnit; +import org.openjdk.jmh.annotations.Param; +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.RunnerException; +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 = 5) +public class CookieDate { + + private static final long DATE_MILLIS = 1252487340_000L; // Wed Sep 09 11:09:00 CEST 2009 + + private static final String[] STRINGS = { + "Wed, 09-Sep-2009 09:09:00 GMT", + "Wed, 09 Sep 2009 09:09:00 GMT", + "Wed Sep 09 2009 09:09:00 GMT+0000", + "Wed, 09-Sep-09 09:09:00 GMT", + "Wed, 09 Sep 09 09:09:00 GMT", + "Wednesday, 09-Sep-09 09:09:00 GMT", + "blah" + }; + + @Param({"0", "1", "2", "3", "4", "5", "6"}) + private int idx; + +// @Benchmark + public long parse0HttpCookieDecoder() { + return HttpSetCookieDecoder.parseMaxAge(STRINGS[idx]); + } + +// @Benchmark + public Date parse1Netty() { + return io.netty.handler.codec.DateFormatter.parseHttpDate(STRINGS[idx]); + } + +// @Benchmark + public Date parse2JDK() { + LocalDateTime ldt = LocalDateTime.parse(STRINGS[idx], DateTimeFormatter.RFC_1123_DATE_TIME); + return Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()); + } + + @Benchmark + public Date parse2NettyCopy() { + return HttpDateFormatter.parseHttpDate(STRINGS[idx]); + } + + + public static void main(String[] args) throws RunnerException { + HttpDateFormatter.parseHttpDate(STRINGS[0]); + Options opt = new OptionsBuilder().include(CookieDate.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/protocol/http/HttpCookieDecoderBenchmark.java Fri Oct 06 10:03:29 2017 +0200 @@ -0,0 +1,57 @@ +package com.passus.st.protocol.http; + +import com.passus.ambience.protocol.http.HttpCookieHeaderParser; +import com.passus.st.data.ByteString; +import com.passus.st.data.ByteStringImpl; +import java.util.List; +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.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.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 = 6) +@Warmup(iterations = 4) +public class HttpCookieDecoderBenchmark { + + private HttpSetCookieDecoder setCookieDecoder = new HttpSetCookieDecoder(); + + private String setCookieHeader = "someCookie=someValue;path=/somepath;domain = somedomain ; HttpOnly; Secure;"; + + private ByteString setCookieHeaderBs = new ByteStringImpl(setCookieHeader); + + @Benchmark + public int decode_HttpSetCookieDecoder() { + HttpCookie cookie = setCookieDecoder.decode(setCookieHeaderBs, 0, false); + return cookie.getVersion(); + } + + @Benchmark + public int decode_HttpCookieHeaderParser() { + List<java.net.HttpCookie> cookies = HttpCookieHeaderParser.parseSetCookieHeader(setCookieHeader); + return cookies.size(); + } + + public static void main(String[] args) throws RunnerException { + Options opt = new OptionsBuilder().include(HttpCookieDecoderBenchmark.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/protocol/http/HttpCookieDecoderBennchmark.java Fri Oct 06 10:03:29 2017 +0200 @@ -0,0 +1,54 @@ +package com.passus.st.protocol.http; + +import java.io.IOException; +import java.net.HttpCookie; +import java.util.List; +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.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.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 = 6) +public class HttpCookieDecoderBennchmark { + + private String cookieStr = "someCookie=someValue;path='/somepath';domain = \"somedomain\" ; HttpOnly; Secure;"; + + private final HttpSetCookieDecoder decoder = new HttpSetCookieDecoder(); + + @Benchmark + public int testJDKDecoder() throws IOException { + List<HttpCookie> cookies = HttpCookie.parse("Set-Cookie:" + cookieStr); + return cookies == null ? 1 : -1; + } + + @Benchmark + public int testDecoder() throws IOException { + com.passus.st.protocol.http.HttpCookie cookie = decoder.decode(cookieStr); + return cookie == null ? 1 : -1; + } + + public static void main(String[] args) throws RunnerException, IOException { + Options opt = new OptionsBuilder().include(HttpCookieDecoderBennchmark.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + } + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/protocol/http/HttpDigestMD5Benchmark.java Fri Oct 06 10:03:29 2017 +0200 @@ -0,0 +1,145 @@ +package com.passus.st.protocol.http; + +import com.passus.data.ByteString; +import com.passus.data.ByteStringImpl; +import com.passus.utils.AllocationUtils; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.concurrent.TimeUnit; +import org.bouncycastle.jce.provider.JDKMessageDigest; +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.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 HttpDigestMD5Benchmark { + + private final byte COLON = ':'; + private final byte[] user = "user".getBytes(); + private final byte[] password = "password".getBytes(); + private final byte[] realm = "11111111112222222222333333333344".getBytes(); + private final ByteString ubs = new ByteStringImpl(user); + private final ByteString rbs = new ByteStringImpl(realm); + private final ByteString pbs = new ByteStringImpl(password); + + @Benchmark + public MessageDigest getMD5() throws NoSuchAlgorithmException { + return MessageDigest.getInstance("MD5"); + } + + @Benchmark + public JDKMessageDigest.MD5 getMD5BC() { + return new JDKMessageDigest.MD5(); + } + + @Benchmark + public byte[] digestMultiCall() throws NoSuchAlgorithmException { + MessageDigest md = getMD5(); + md.update(user); + md.update(COLON); + md.update(realm); + md.update(COLON); + md.update(password); + return md.digest(); + } + + @Benchmark + public byte[] digestWithBuffer() throws NoSuchAlgorithmException { + MessageDigest md = getMD5(); + byte[] buff = new byte[user.length + realm.length + password.length + 2]; + System.arraycopy(user, 0, buff, 0, user.length); + buff[user.length] = COLON; + System.arraycopy(realm, 0, buff, user.length + 1, realm.length); + buff[user.length + realm.length + 1] = COLON; + System.arraycopy(password, 0, buff, user.length + realm.length + 2, password.length); + return md.digest(buff); + } + + @Benchmark + public byte[] digestMultiCallBC() { + JDKMessageDigest.MD5 md = getMD5BC(); + md.update(user); + md.update(COLON); + md.update(realm); + md.update(COLON); + md.update(password); + return md.digest(); + } + + @Benchmark + public byte[] digestWithBufferBC() { + JDKMessageDigest.MD5 md = getMD5BC(); + byte[] buff = new byte[user.length + realm.length + password.length + 2]; + System.arraycopy(user, 0, buff, 0, user.length); + buff[user.length] = COLON; + System.arraycopy(realm, 0, buff, user.length + 1, realm.length); + buff[user.length + realm.length + 1] = COLON; + System.arraycopy(password, 0, buff, user.length + realm.length + 2, password.length); + return md.digest(buff); + } + +// @Benchmark +// public byte[] copy() { +// JDKMessageDigest.MD5 md = getMD5BC(); +// md.update(ubs.getBytes()); +// md.update(COLON); +// md.update(rbs.getBytes()); +// md.update(COLON); +// md.update(pbs.getBytes()); +// return md.digest(); +// } + + public static void main(String[] args) throws Exception { + Options opt = new OptionsBuilder().include(HttpDigestMD5Benchmark.class.getSimpleName() + ".*").build(); + new Runner(opt).run(); + + HttpDigestMD5Benchmark bench = new HttpDigestMD5Benchmark(); + + AllocationUtils au = new AllocationUtils(); + au.checkAllocation("jdk-mc", bench::digestMultiCall); + au.checkAllocation(" bc-mc", bench::digestMultiCallBC); + au.checkAllocation("jdk-buff", bench::digestWithBuffer); + au.checkAllocation(" bc-buff", bench::digestWithBufferBC); + + printHex(bench.digestMultiCall()); + printHex(bench.digestMultiCallBC()); + printHex(bench.digestWithBuffer()); + printHex(bench.digestWithBufferBC()); + } + + private final static char[] HEX = { + '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' + }; + + public static String bytesToHex(byte[] bytes) { + char[] hexChars = new char[bytes.length * 2]; + for (int j = 0; j < bytes.length; j++) { + int v = bytes[j] & 0xFF; + hexChars[j * 2] = HEX[v >>> 4]; + hexChars[j * 2 + 1] = HEX[v & 0x0F]; + } + return new String(hexChars); + } + + public static void printHex(byte[] bytes) { + System.out.println(bytesToHex(bytes)); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/stress-tester-benchmark/src/main/java/com/passus/st/protocol/http/HttpRequestDecodingBenchmark.java Fri Oct 06 10:03:29 2017 +0200 @@ -0,0 +1,104 @@ +package com.passus.st.protocol.http; + +import com.passus.utils.AllocationUtils; +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.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; + +/** + * + * @author Mirosław Hawrot + */ +@State(Scope.Thread) +@BenchmarkMode(Mode.AverageTime) +@OutputTimeUnit(TimeUnit.NANOSECONDS) +@Fork(value = 1) +@Measurement(iterations = 6) +@Warmup(iterations = 4) +public class HttpRequestDecodingBenchmark { + + private String headersStr = "Host: testHost\r\n" + + "Host2:testHost2\r\n" + + "\r\n"; + + private byte[] headersBytes; + + private String reqStr = "GET /resource HTTP/1.1\r\n" + + headersStr; + + private byte[] reqBytes; + + { + try { + reqBytes = reqStr.getBytes("US-ASCII"); + headersBytes = headersStr.getBytes("US-ASCII"); + } catch (Exception e) { + } + } + + private com.passus.ambience.protocol.http.HttpRequest ambRequest = new com.passus.ambience.protocol.http.HttpRequest(); + + private HttpRequestDecoder decoderStrict = new HttpRequestDecoder(true); + + private HttpRequestDecoder decoderNotStrict = new HttpRequestDecoder(false); + + private HttpHeadersDecoder headersDecoderNotStrict = new HttpHeadersDecoder(false); + + @Benchmark + public int testAmbDecoder() throws Exception { + com.passus.ambience.protocol.http.HttpRequest ambRequest = new com.passus.ambience.protocol.http.HttpRequest(); + return ambRequest.decode(reqBytes, 0); + } + + //@Benchmark + public int testDecoder_Strict() throws Exception { + return decoderStrict.decode(reqBytes); + } + + //@Benchmark + public int testDecoder_NotStrict() throws Exception { + return decoderNotStrict.decode(reqBytes); + } + + @Benchmark + public int testHeadersDecoder_NotStrict() throws Exception { + int res = headersDecoderNotStrict.decode(headersBytes); + headersDecoderNotStrict.clear(); + return res; + } + + public static void main(String[] args) throws Exception { + //Options opt = new OptionsBuilder().include(HttpRequestDecodingBenchmark.class.getSimpleName() + ".*").build(); + //new Runner(opt).run(); + + HttpRequestDecodingBenchmark bench = new HttpRequestDecodingBenchmark(); + //System.out.println(bench.testAmbDecoder()); + //System.out.println(bench.testDecoder_Strict()); + //System.out.println(bench.testDecoder_NotStrict()); + long start = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + bench.testAmbDecoder(); + } + System.out.println(System.currentTimeMillis() - start); + + start = System.currentTimeMillis(); + for (int i = 0; i < 100000; i++) { + bench.testHeadersDecoder_NotStrict(); + } + System.out.println(System.currentTimeMillis() - start); + + AllocationUtils au = new AllocationUtils(); + au.setOverheadBase(bench.headersStr.length()); + au.checkAllocation("AmbienceDecoder", bench::testAmbDecoder); + au.checkAllocation("HeadersNotStrict", bench::testHeadersDecoder_NotStrict); + au.checkAllocation("NotStrict", bench::testDecoder_NotStrict); + au.checkAllocation("Strict", bench::testDecoder_Strict); + } +}
--- a/stress-tester-benchmark/src/main/java/com/passus/st/utils/protcol/http/HttpCookieDecoderBennchmark.java Fri Oct 06 09:12:38 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,55 +0,0 @@ -package com.passus.st.utils.protcol.http; - -import com.passus.st.protocol.http.HttpSetCookieDecoder; -import java.io.IOException; -import java.net.HttpCookie; -import java.util.List; -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.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.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 = 6) -public class HttpCookieDecoderBennchmark { - - private String cookieStr = "someCookie=someValue;path='/somepath';domain = \"somedomain\" ; HttpOnly; Secure;"; - - private final HttpSetCookieDecoder decoder = new HttpSetCookieDecoder(); - - @Benchmark - public int testJDKDecoder() throws IOException { - List<HttpCookie> cookies = HttpCookie.parse("Set-Cookie:" + cookieStr); - return cookies == null ? 1 : -1; - } - - @Benchmark - public int testDecoder() throws IOException { - com.passus.st.protocol.http.HttpCookie cookie = decoder.decode(cookieStr); - return cookie == null ? 1 : -1; - } - - public static void main(String[] args) throws RunnerException, IOException { - Options opt = new OptionsBuilder().include(HttpCookieDecoderBennchmark.class.getSimpleName() + ".*").build(); - new Runner(opt).run(); - } - -}
--- a/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFormLoginFilter.java Fri Oct 06 09:12:38 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/filter/HttpFormLoginFilter.java Fri Oct 06 10:03:29 2017 +0200 @@ -64,12 +64,13 @@ ParametersBag conversation = context.scopes().getConversation(request); if (credentials != null) { - LOGGER.debug("Credentials provided for user '{}'.", credentials.getUser()); + LOGGER.debug("Credentials provided for user '{}' [{}].", credentials.getUser(), request.getId()); parameters.set(userField, credentials.getUser()); parameters.set(passwordField, credentials.getPassword()); helper.setFormUrlencoded(request, parameters); conversation.set(PARAM_USERNAME, credentials.getUser()); } else { + LOGGER.debug("Credentials not provided. [{}]", request.getId()); conversation.set(PARAM_USERNAME, parameters.get(userField).toString()); } } @@ -88,18 +89,18 @@ if (loginOk) { ParametersBag conversation = context.scopes().getConversation(request, false); if (conversation != null) { - LOGGER.debug("Login succeeded for user '{}'.", conversation.get(PARAM_USERNAME)); + LOGGER.debug("Login succeeded for user '{}' [{}].", conversation.get(PARAM_USERNAME), request.getId()); ParametersBag session = context.scopes().getSession(request); if (session == null) { - LOGGER.debug("Session not found."); + LOGGER.debug("Session not found. [{}]", request.getId()); } else { session.set(PARAM_USERNAME, conversation.get(PARAM_USERNAME)); } } else { - LOGGER.debug("Login succeeded for unknown user."); + LOGGER.debug("Login succeeded for unknown user. [{}]", request.getId()); } } else { - LOGGER.debug("Login failed."); + LOGGER.debug("Login failed. [{}]", request.getId()); } }