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 09:56:42 UTC
[2/2] httpcomponents-core git commit: Improved consistency with AB
command interface; removed support for HTTP/1.0
Improved consistency with AB command interface; removed support for HTTP/1.0
Project: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/repo
Commit: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/commit/66cb8622
Tree: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/tree/66cb8622
Diff: http://git-wip-us.apache.org/repos/asf/httpcomponents-core/diff/66cb8622
Branch: refs/heads/master
Commit: 66cb8622c33548b9ce2ac8a9a9040462bba72b36
Parents: 2821638
Author: Oleg Kalnichevski <ol...@apache.org>
Authored: Mon Sep 17 11:54:17 2018 +0200
Committer: Oleg Kalnichevski <ol...@apache.org>
Committed: Mon Sep 17 11:54:17 2018 +0200
----------------------------------------------------------------------
.../hc/core5/benchmark/BenchmarkConfig.java | 125 +++++++-------
.../hc/core5/benchmark/CommandLineUtils.java | 173 +++++++++----------
.../hc/core5/benchmark/HttpBenchmark.java | 6 +-
.../hc/core5/benchmark/BenchmarkToolTest.java | 2 +-
4 files changed, 153 insertions(+), 153 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/66cb8622/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkConfig.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkConfig.java b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkConfig.java
index 5631a67..25f303d 100644
--- a/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkConfig.java
+++ b/httpcore5-testing/src/main/java/org/apache/hc/core5/benchmark/BenchmarkConfig.java
@@ -32,6 +32,7 @@ import java.util.Arrays;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.util.Args;
+import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
public class BenchmarkConfig {
@@ -39,22 +40,21 @@ public class BenchmarkConfig {
private final URI uri;
private final int requests;
private final int concurrencyLevel;
- private final boolean keepAlive;
+ private final TimeValue timeLimit;
+ private final Timeout socketTimeout;
+ private final File payloadFile;
+ private final ContentType contentType;
private final int verbosity;
private final boolean headInsteadOfGet;
- private final boolean useHttp1_0;
- private final ContentType contentType;
private final String[] headers;
- private final Timeout socketTimeout;
+ private final boolean keepAlive;
private final String method;
+
private final boolean useChunking;
private final boolean useExpectContinue;
private final boolean useAcceptGZip;
- private final File payloadFile;
private final String payloadText;
private final String soapAction;
- private final int timeLimit;
-
private final boolean disableSSLVerification;
private final String trustStorePath;
private final String identityStorePath;
@@ -64,20 +64,20 @@ public class BenchmarkConfig {
private BenchmarkConfig(final URI uri,
final int requests,
final int concurrencyLevel,
- final boolean keepAlive, final int verbosity,
- final boolean headInsteadOfGet,
- final boolean useHttp1_0,
+ final TimeValue timeLimit,
+ final Timeout socketTimeout,
+ final File payloadFile,
final ContentType contentType,
+ final int verbosity,
+ final boolean headInsteadOfGet,
final String[] headers,
- final Timeout socketTimeout,
+ final boolean keepAlive,
final String method,
final boolean useChunking,
final boolean useExpectContinue,
final boolean useAcceptGZip,
- final File payloadFile,
final String payloadText,
final String soapAction,
- final int timeLimit,
final boolean disableSSLVerification,
final String trustStorePath,
final String identityStorePath,
@@ -86,21 +86,20 @@ public class BenchmarkConfig {
this.uri = uri;
this.requests = requests;
this.concurrencyLevel = concurrencyLevel;
- this.keepAlive = keepAlive;
+ this.timeLimit = timeLimit;
+ this.socketTimeout = socketTimeout;
+ this.payloadFile = payloadFile;
+ this.contentType = contentType;
this.verbosity = verbosity;
this.headInsteadOfGet = headInsteadOfGet;
- this.useHttp1_0 = useHttp1_0;
- this.contentType = contentType;
this.headers = headers;
- this.socketTimeout = socketTimeout;
+ this.keepAlive = keepAlive;
this.method = method;
this.useChunking = useChunking;
this.useExpectContinue = useExpectContinue;
this.useAcceptGZip = useAcceptGZip;
- this.payloadFile = payloadFile;
this.payloadText = payloadText;
this.soapAction = soapAction;
- this.timeLimit = timeLimit;
this.disableSSLVerification = disableSSLVerification;
this.trustStorePath = trustStorePath;
this.identityStorePath = identityStorePath;
@@ -132,10 +131,6 @@ public class BenchmarkConfig {
return headInsteadOfGet;
}
- public boolean isUseHttp1_0() {
- return useHttp1_0;
- }
-
public File getPayloadFile() {
return payloadFile;
}
@@ -196,7 +191,7 @@ public class BenchmarkConfig {
return identityStorePassword;
}
- public int getTimeLimit() {
+ public TimeValue getTimeLimit() {
return timeLimit;
}
@@ -206,21 +201,20 @@ public class BenchmarkConfig {
"uri=" + uri +
", requests=" + requests +
", concurrencyLevel=" + concurrencyLevel +
- ", keepAlive=" + keepAlive +
+ ", timeLimit=" + timeLimit +
+ ", socketTimeout=" + socketTimeout +
+ ", payloadFile=" + payloadFile +
+ ", contentType=" + contentType +
", verbosity=" + verbosity +
", headInsteadOfGet=" + headInsteadOfGet +
- ", useHttp1_0=" + useHttp1_0 +
- ", contentType=" + contentType +
", headers=" + Arrays.toString(headers) +
- ", socketTimeout=" + socketTimeout +
+ ", keepAlive=" + keepAlive +
", method='" + method + '\'' +
", useChunking=" + useChunking +
", useExpectContinue=" + useExpectContinue +
", useAcceptGZip=" + useAcceptGZip +
- ", payloadFile=" + payloadFile +
", payloadText='" + payloadText + '\'' +
", soapAction='" + soapAction + '\'' +
- ", timeLimit=" + timeLimit +
", disableSSLVerification=" + disableSSLVerification +
", trustStorePath='" + trustStorePath + '\'' +
", identityStorePath='" + identityStorePath + '\'' +
@@ -238,22 +232,21 @@ public class BenchmarkConfig {
return new Builder()
.setUri(config.getUri())
.setRequests(config.getRequests())
- .setThreads(config.getConcurrencyLevel())
- .setKeepAlive(config.isKeepAlive())
+ .setConcurrencyLevel(config.getConcurrencyLevel())
+ .setTimeLimit(config.getTimeLimit())
+ .setSocketTimeout(config.getSocketTimeout())
+ .setPayloadFile(config.getPayloadFile())
+ .setContentType(config.getContentType())
.setVerbosity(config.getVerbosity())
.setHeadInsteadOfGet(config.isHeadInsteadOfGet())
- .setUseHttp1_0(config.isUseHttp1_0())
- .setContentType(config.getContentType())
.setHeaders(config.getHeaders())
- .setSocketTimeout(config.getSocketTimeout())
+ .setKeepAlive(config.isKeepAlive())
.setMethod(config.getMethod())
.setUseChunking(config.isUseChunking())
.setUseExpectContinue(config.isUseExpectContinue())
.setUseAcceptGZip(config.isUseAcceptGZip())
- .setPayloadFile(config.getPayloadFile())
.setPayloadText(config.getPayloadText())
.setSoapAction(config.getSoapAction())
- .setTimeLimit(config.getTimeLimit())
.setDisableSSLVerification(config.isDisableSSLVerification())
.setTrustStorePath(config.getTrustStorePath())
.setIdentityStorePath(config.getIdentityStorePath())
@@ -266,24 +259,23 @@ public class BenchmarkConfig {
private URI uri;
private int requests;
- private int threads;
- private boolean keepAlive;
+ private int concurrencyLevel;
+ private TimeValue timeLimit;
+ private Timeout socketTimeout;
+ private File payloadFile;
+ private ContentType contentType;
private int verbosity;
private boolean headInsteadOfGet;
- private boolean useHttp1_0;
- private ContentType contentType;
private String[] headers;
- private Timeout socketTimeout;
+ private boolean keepAlive;
private String method;
+
private boolean useChunking;
private boolean useExpectContinue;
private boolean useAcceptGZip;
- private File payloadFile;
private String payloadText;
private String soapAction;
- private int timeLimit = -1;
-
- private boolean disableSSLVerification = true;
+ private boolean disableSSLVerification;
private String trustStorePath;
private String identityStorePath;
private String trustStorePassword;
@@ -292,11 +284,10 @@ public class BenchmarkConfig {
public Builder() {
super();
this.requests = 1;
- this.threads = 1;
+ this.concurrencyLevel = 1;
this.keepAlive = false;
this.verbosity = 0;
this.headInsteadOfGet = false;
- this.useHttp1_0 = false;
this.socketTimeout = Timeout.ofSeconds(60);
}
@@ -310,8 +301,8 @@ public class BenchmarkConfig {
return this;
}
- public Builder setThreads(final int threads) {
- this.threads = threads;
+ public Builder setConcurrencyLevel(final int concurrencyLevel) {
+ this.concurrencyLevel = concurrencyLevel;
return this;
}
@@ -330,11 +321,6 @@ public class BenchmarkConfig {
return this;
}
- public Builder setUseHttp1_0(final boolean useHttp1_0) {
- this.useHttp1_0 = useHttp1_0;
- return this;
- }
-
public Builder setContentType(final ContentType contentType) {
this.contentType = contentType;
return this;
@@ -385,7 +371,7 @@ public class BenchmarkConfig {
return this;
}
- public Builder setTimeLimit(final int timeLimit) {
+ public Builder setTimeLimit(final TimeValue timeLimit) {
this.timeLimit = timeLimit;
return this;
}
@@ -416,10 +402,29 @@ public class BenchmarkConfig {
}
public BenchmarkConfig build() {
- return new BenchmarkConfig(uri, requests, threads, keepAlive, verbosity, headInsteadOfGet, useHttp1_0,
- contentType, headers, socketTimeout, method, useChunking, useExpectContinue, useAcceptGZip,
- payloadFile, payloadText, soapAction, timeLimit, disableSSLVerification, trustStorePath,
- identityStorePath, trustStorePassword, identityStorePassword);
+ return new BenchmarkConfig(
+ uri,
+ requests,
+ concurrencyLevel,
+ timeLimit,
+ socketTimeout,
+ payloadFile,
+ contentType,
+ verbosity,
+ headInsteadOfGet,
+ headers,
+ keepAlive,
+ method,
+ useChunking,
+ useExpectContinue,
+ useAcceptGZip,
+ payloadText,
+ soapAction,
+ disableSSLVerification,
+ trustStorePath,
+ identityStorePath,
+ trustStorePassword,
+ identityStorePassword);
}
}
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/66cb8622/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 c191e8c..6037219 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
@@ -35,6 +35,7 @@ import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
import org.apache.commons.cli.Options;
import org.apache.hc.core5.http.ContentType;
+import org.apache.hc.core5.util.TimeValue;
import org.apache.hc.core5.util.Timeout;
public class CommandLineUtils {
@@ -44,125 +45,128 @@ public class CommandLineUtils {
}
public static Options getOptions() {
- final Option iopt = new Option("i", false, "Do HEAD requests instead of GET (deprecated)");
- iopt.setRequired(false);
-
- final Option oopt = new Option("o", false, "Use HTTP/S 1.0 instead of 1.1 (default)");
- oopt.setRequired(false);
-
- final Option kopt = new Option("k", false, "Enable the HTTP KeepAlive feature, " +
- "i.e., perform multiple requests within one HTTP session. " +
- "Default is no KeepAlive");
- kopt.setRequired(false);
-
- final Option uopt = new Option("u", false, "Chunk entity. Default is false");
- uopt.setRequired(false);
-
- final Option xopt = new Option("x", false, "Use Expect-Continue. Default is false");
- xopt.setRequired(false);
-
- final Option gopt = new Option("g", false, "Accept GZip. Default is false");
- gopt.setRequired(false);
-
- final Option nopt = new Option("n", true, "Number of requests to perform for the " +
- "benchmarking session. The default is to just perform a single " +
- "request which usually leads to non-representative benchmarking " +
- "results");
+ final Option nopt = new Option("n", true, "Number of requests to perform. " +
+ "The default is to just perform a single request which may lead " +
+ "to non-representative benchmarking results");
nopt.setRequired(false);
nopt.setArgName("requests");
- final Option copt = new Option("c", true, "Concurrency while performing the " +
- "benchmarking session. The default is to just use a single thread/client");
+ final Option copt = new Option("c", true, "Number of multiple requests to make at a time. " +
+ "The default is to just execute a single request");
copt.setRequired(false);
copt.setArgName("concurrency");
- final Option popt = new Option("p", true, "File containing data to POST or PUT");
+ final Option topt = new Option("t", true, "Seconds to max. to spend on benchmarking");
+ topt.setRequired(false);
+ topt.setArgName("time-limit");
+
+ final Option sopt = new Option("s", true, "Seconds to max. wait for each response. Default is 60 seconds");
+ sopt.setRequired(false);
+ sopt.setArgName("socket-Timeout");
+
+ final Option popt = new Option("p", true, "File containing data to enclose in the request");
popt.setRequired(false);
popt.setArgName("Payload file");
- final Option mopt = new Option("m", true, "HTTP Method. Default is POST. " +
- "Possible options are GET, POST, PUT, DELETE, HEAD, OPTIONS, TRACE");
- mopt.setRequired(false);
- mopt.setArgName("HTTP method");
-
- final Option Topt = new Option("T", true, "Content-type header to use for POST/PUT data");
+ final Option Topt = new Option("T", true, "Content-type header to use for enclosed request data");
Topt.setRequired(false);
Topt.setArgName("content-type");
- final Option topt = new Option("t", true, "Client side socket timeout (in ms) - default 60 Secs");
- topt.setRequired(false);
- topt.setArgName("socket-Timeout");
+ 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");
+ vopt.setRequired(false);
+ vopt.setArgName("verbosity");
- final Option tlopt = new Option("l", true, "Time limit for the test to run (default is infinity)");
- tlopt.setRequired(false);
- tlopt.setArgName("time-limit");
+ final Option iopt = new Option("i", false, "Use HEAD instead of GET");
+ iopt.setRequired(false);
final Option Hopt = new Option("H", true, "Add arbitrary header line, " +
- "eg. 'Accept-Encoding: gzip' inserted after all normal " +
- "header lines. (repeatable as -H \"h1: v1\",\"h2: v2\" etc)");
+ "eg. 'Accept-Encoding: gzip' inserted after all normal " +
+ "header lines. (repeatable as -H \"h1: v1\",\"h2: v2\" etc)");
Hopt.setRequired(false);
Hopt.setArgName("header");
- 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 info");
- vopt.setRequired(false);
- vopt.setArgName("verbosity");
+ final Option kopt = new Option("k", false, "Use HTTP KeepAlive feature. Default is no KeepAlive");
+ kopt.setRequired(false);
+
+ final Option mopt = new Option("m", true, "HTTP Method. Default is GET or POST if the request to enclose data");
+ mopt.setRequired(false);
+ mopt.setArgName("HTTP method");
+
+ // HttpCore specific options
+
+ final Option uopt = new Option("u", false, "Chunk entity. Default is false");
+ uopt.setRequired(false);
+
+ final Option xopt = new Option("x", false, "Use Expect-Continue. Default is false");
+ xopt.setRequired(false);
+
+ final Option gopt = new Option("g", false, "Accept GZip. Default is false");
+ gopt.setRequired(false);
final Option hopt = new Option("h", false, "Display usage information");
nopt.setRequired(false);
final Options options = new Options();
- options.addOption(iopt);
- options.addOption(mopt);
- options.addOption(uopt);
- options.addOption(xopt);
- options.addOption(gopt);
- options.addOption(kopt);
options.addOption(nopt);
options.addOption(copt);
+ options.addOption(topt);
+ options.addOption(sopt);
options.addOption(popt);
options.addOption(Topt);
options.addOption(vopt);
+ options.addOption(iopt);
options.addOption(Hopt);
+ options.addOption(kopt);
+ options.addOption(mopt);
+
+ // HttpCore specific options
+
+ options.addOption(uopt);
+ options.addOption(xopt);
+ options.addOption(gopt);
+
options.addOption(hopt);
- options.addOption(topt);
- options.addOption(oopt);
- options.addOption(tlopt);
return options;
}
public static BenchmarkConfig parseCommandLine(final CommandLine cmd) {
final BenchmarkConfig.Builder builder = new BenchmarkConfig.Builder();
- if (cmd.hasOption('v')) {
- final String s = cmd.getOptionValue('v');
+ if (cmd.hasOption('n')) {
+ final String s = cmd.getOptionValue('n');
try {
- builder.setVerbosity(Integer.parseInt(s));
+ builder.setRequests(Integer.parseInt(s));
} catch (final NumberFormatException ex) {
- printError("Invalid verbosity level: " + s);
+ printError("Invalid number of requests: " + s);
}
}
- if (cmd.hasOption('k')) {
- builder.setKeepAlive(true);
- }
-
if (cmd.hasOption('c')) {
final String s = cmd.getOptionValue('c');
try {
- builder.setThreads(Integer.parseInt(s));
+ builder.setConcurrencyLevel(Integer.parseInt(s));
} catch (final NumberFormatException ex) {
printError("Invalid number for concurrency: " + s);
}
}
- if (cmd.hasOption('n')) {
- final String s = cmd.getOptionValue('n');
+ if (cmd.hasOption('t')) {
+ final String t = cmd.getOptionValue('t');
try {
- builder.setRequests(Integer.parseInt(s));
+ builder.setTimeLimit(TimeValue.ofSeconds(Integer.parseInt(t)));
} catch (final NumberFormatException ex) {
- printError("Invalid number of requests: " + s);
+ printError("Invalid time limit: " + t);
+ }
+ }
+
+ if (cmd.hasOption('s')) {
+ final String s = cmd.getOptionValue('s');
+ try {
+ builder.setSocketTimeout(Timeout.ofMillis(Integer.parseInt(s)));
+ } catch (final NumberFormatException ex) {
+ printError("Invalid socket timeout: " + s);
}
}
@@ -178,6 +182,15 @@ public class CommandLineUtils {
builder.setContentType(ContentType.parse(cmd.getOptionValue('T')));
}
+ if (cmd.hasOption('v')) {
+ final String s = cmd.getOptionValue('v');
+ try {
+ builder.setVerbosity(Integer.parseInt(s));
+ } catch (final NumberFormatException ex) {
+ printError("Invalid verbosity level: " + s);
+ }
+ }
+
if (cmd.hasOption('i')) {
builder.setHeadInsteadOfGet(true);
}
@@ -187,26 +200,8 @@ public class CommandLineUtils {
builder.setHeaders(headerStr.split(","));
}
- if (cmd.hasOption('t')) {
- final String t = cmd.getOptionValue('t');
- try {
- builder.setSocketTimeout(Timeout.ofMillis(Integer.parseInt(t)));
- } catch (final NumberFormatException ex) {
- printError("Invalid socket timeout: " + t);
- }
- }
-
- if (cmd.hasOption('l')) {
- final String l = cmd.getOptionValue('l');
- try {
- builder.setTimeLimit(Integer.parseInt(l));
- } catch (final NumberFormatException ex) {
- printError("Invalid time limit: " + l);
- }
- }
-
- if (cmd.hasOption('o')) {
- builder.setUseHttp1_0(true);
+ if (cmd.hasOption('k')) {
+ builder.setKeepAlive(true);
}
if (cmd.hasOption('m')) {
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/66cb8622/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 8b4d1d2..2599205 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
@@ -332,7 +332,7 @@ public class HttpBenchmark {
final AtomicLong requestCount = new AtomicLong(config.getRequests());
- final HttpVersion version = config.isUseHttp1_0() ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1;
+ final HttpVersion version = HttpVersion.HTTP_1_1;
final CountDownLatch completionLatch = new CountDownLatch(config.getConcurrencyLevel());
final BenchmarkWorker[] workers = new BenchmarkWorker[config.getConcurrencyLevel()];
@@ -350,7 +350,7 @@ public class HttpBenchmark {
workers[i] = worker;
}
- final long deadline = config.getTimeLimit() > 0 ? config.getTimeLimit() : Long.MAX_VALUE;
+ final long deadline = config.getTimeLimit() != null ? config.getTimeLimit().toMillis() : Long.MAX_VALUE;
final long startTime = System.currentTimeMillis();
@@ -358,7 +358,7 @@ public class HttpBenchmark {
workers[i].execute();
}
- completionLatch.await(deadline, TimeUnit.SECONDS);
+ completionLatch.await(deadline, TimeUnit.MILLISECONDS);
if (config.getVerbosity() >= 3) {
System.out.println("...done");
http://git-wip-us.apache.org/repos/asf/httpcomponents-core/blob/66cb8622/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
----------------------------------------------------------------------
diff --git a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
index 659b2b0..235fc79 100644
--- a/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
+++ b/httpcore5-testing/src/test/java/org/apache/hc/core5/benchmark/BenchmarkToolTest.java
@@ -82,7 +82,7 @@ public class BenchmarkToolTest {
.setHost("localhost")
.setPort(server.getLocalPort())
.build())
- .setThreads(3)
+ .setConcurrencyLevel(3)
.setRequests(100)
.build();
final HttpBenchmark httpBenchmark = new HttpBenchmark(config);