You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hc.apache.org by ol...@apache.org on 2018/09/17 20:05:06 UTC

httpcomponents-core git commit: Updated HttpBenchmark tool verbose output to print HTTP/2 specific details

Repository: httpcomponents-core
Updated Branches:
  refs/heads/master 30ed9787f -> cc5b62ac5


Updated HttpBenchmark tool verbose output to print HTTP/2 specific details


Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/cc5b62ac
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/cc5b62ac
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/cc5b62ac

Branch: refs/heads/master
Commit: cc5b62ac564906bdf0868a147436e9800aaf7260
Parents: 30ed978
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Sep 17 22:04:18 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Sep 17 22:04:18 2018 +0200

----------------------------------------------------------------------
 .../hc/core5/benchmark/BenchmarkWorker.java     |  6 +-
 .../hc/core5/benchmark/CommandLineUtils.java    | 11 ++-
 .../hc/core5/benchmark/HttpBenchmark.java       | 87 ++++++++++++++++++++
 3 files changed, 97 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cc5b62ac/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
index 7e68691..f4a5b38 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkWorker.java
@@ -202,7 +202,7 @@ class BenchmarkWorker implements ResourceHolder {
                     System.out.println(response.getCode());
                 }
                 if (entityDetails != null) {
-                    if (config.getVerbosity() >= 4) {
+                    if (config.getVerbosity() >= 6) {
                         if (entityDetails.getContentType() != null) {
                             final ContentType contentType = ContentType.parseLenient(entityDetails.getContentType());
                             charset = contentType.getCharset();
@@ -229,7 +229,7 @@ class BenchmarkWorker implements ResourceHolder {
                 final int n = src.remaining();
                 contentLength.addAndGet(n);
                 stats.incTotalContentLength(n);
-                if (config.getVerbosity() >= 4) {
+                if (config.getVerbosity() >= 6) {
                     final CharsetDecoder decoder = (charset != null ? charset : StandardCharsets.US_ASCII).newDecoder();
                     System.out.print(decoder.decode(src));
                 }
@@ -248,7 +248,7 @@ class BenchmarkWorker implements ResourceHolder {
                 if (resultCallback != null) {
                     resultCallback.completed(null);
                 }
-                if (config.getVerbosity() >= 4) {
+                if (config.getVerbosity() >= 6) {
                     System.out.println();
                     System.out.println();
                 }

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cc5b62ac/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java
index 731cf38..529dfd5 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/CommandLineUtils.java
@@ -72,10 +72,13 @@ public class CommandLineUtils {
         Topt.setRequired(false);
         Topt.setArgName("content-type");
 
-        final Option vopt = new Option("v", true, "Set verbosity level - 4 and above " +
-                "prints response content, 3 and above prints " +
-                "information on headers, 2 and above prints response codes (404, 200, " +
-                "etc.), 1 and above prints warnings and errors");
+        final Option vopt = new Option("v", true, "Set verbosity level: " +
+                "1 prints warnings and errors, " +
+                "2 prints response codes, " +
+                "3 prints message headers, " +
+                "4 prints HTTP/2 frame info, " +
+                "5 prints HTTP/2 flow control events, " +
+                "6 prints response content");
         vopt.setRequired(false);
         vopt.setArgName("verbosity");
 

http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/cc5b62ac/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
index 68e8705..b267c78 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/HttpBenchmark.java
@@ -34,6 +34,7 @@ import java.nio.ByteBuffer;
 import java.nio.channels.ByteChannel;
 import java.security.cert.CertificateException;
 import java.security.cert.X509Certificate;
+import java.util.List;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
@@ -60,6 +61,9 @@ import org.apache.hc.core5.http.protocol.HttpProcessorBuilder;
 import org.apache.hc.core5.http.protocol.RequestExpectContinue;
 import org.apache.hc.core5.http.protocol.RequestUserAgent;
 import org.apache.hc.core5.http2.HttpVersionPolicy;
+import org.apache.hc.core5.http2.frame.FramePrinter;
+import org.apache.hc.core5.http2.frame.RawFrame;
+import org.apache.hc.core5.http2.impl.nio.Http2StreamListener;
 import org.apache.hc.core5.http2.impl.nio.bootstrap.H2RequesterBootstrap;
 import org.apache.hc.core5.http2.protocol.H2RequestConnControl;
 import org.apache.hc.core5.http2.protocol.H2RequestContent;
@@ -328,6 +332,89 @@ public class HttpBenchmark {
                     }
 
                 })
+                .setStreamListener(new Http2StreamListener() {
+
+                    private final FramePrinter framePrinter = new FramePrinter();
+
+                    @Override
+                    public void onHeaderInput(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final List<? extends Header> headers) {
+                        if (config.getVerbosity() >= 3) {
+                            for (final Header header : headers) {
+                                System.out.println(">> " + header.toString());
+                            }
+                            System.out.println();
+                        }
+                    }
+
+                    @Override
+                    public void onHeaderOutput(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final List<? extends Header> headers) {
+                        if (config.getVerbosity() >= 3) {
+                            for (final Header header : headers) {
+                                System.out.println("<< " + header.toString());
+                            }
+                            System.out.println();
+                        }
+                    }
+
+                    @Override
+                    public void onFrameInput(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final RawFrame frame) {
+                        if (config.getVerbosity() >= 4) {
+                            System.out.print(">> ");
+                            try {
+                                framePrinter.printFrameInfo(frame, System.out);
+                            } catch (final IOException ignore) {
+                            }
+                            System.out.println();
+                        }
+                    }
+
+                    @Override
+                    public void onFrameOutput(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final RawFrame frame) {
+                        if (config.getVerbosity() >= 4) {
+                            System.out.print("<< ");
+                            try {
+                                framePrinter.printFrameInfo(frame, System.out);
+                            } catch (final IOException ignore) {
+                            }
+                            System.out.println();
+                        }
+                    }
+
+                    @Override
+                    public void onInputFlowControl(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final int delta,
+                            final int actualSize) {
+                        if (config.getVerbosity() >= 5) {
+                            System.out.println(">> stream " + streamId + ": " + actualSize + " " + delta);
+                        }
+                    }
+
+                    @Override
+                    public void onOutputFlowControl(
+                            final HttpConnection connection,
+                            final int streamId,
+                            final int delta,
+                            final int actualSize) {
+                        if (config.getVerbosity() >= 5) {
+                            System.out.println("<< stream " + streamId + ": " + actualSize + " " + delta);
+                        }
+                    }
+
+                })
                 .setIOReactorConfig(IOReactorConfig.custom()
                     .setSoTimeout(config.getSocketTimeout())
                     .build())