Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[testclient] Improve parameter checking in pulsar-perf #11973

Merged
merged 3 commits into from
Sep 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
[testclient] Improve parameter checking in pulsar-perf
  • Loading branch information
yuruguo committed Sep 22, 2021
commit 6d4aced9cb8668d51709d61d6049ff8e83ebeb66
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ ClientBuilder authentication(String authPluginClassName, Map<String, String> aut
* Increasing this parameter may improve throughput when using many producers over a high latency connection.
*
* @param connectionsPerBroker
* max number of connections per broker (needs to be greater than 0)
* max number of connections per broker (needs to be greater than or equal to 0)
* @return the client builder instance
*/
ClientBuilder connectionsPerBroker(int connectionsPerBroker);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public ClientBuilder authentication(String authPluginClassName, Map<String, Stri

@Override
public ClientBuilder operationTimeout(int operationTimeout, TimeUnit unit) {
checkArgument(operationTimeout >= 0, "operationTimeout needs to be >= 0");
conf.setOperationTimeoutMs(unit.toMillis(operationTimeout));
return this;
}
Expand All @@ -161,6 +162,7 @@ public ClientBuilder ioThreads(int numIoThreads) {

@Override
public ClientBuilder listenerThreads(int numListenerThreads) {
checkArgument(numListenerThreads > 0, "listenerThreads needs to be > 0");
conf.setNumListenerThreads(numListenerThreads);
return this;
}
Expand Down Expand Up @@ -246,7 +248,6 @@ public ClientBuilder tlsProtocols(Set<String> tlsProtocols) {

@Override
public ClientBuilder statsInterval(long statsInterval, TimeUnit unit) {
checkArgument(statsInterval >= 0, "statsInterval needs to be >= 0");
conf.setStatsIntervalSeconds(unit.toSeconds(statsInterval));
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,21 +135,18 @@ public ProducerBuilder<T> producerName(String producerName) {

@Override
public ProducerBuilder<T> sendTimeout(int sendTimeout, @NonNull TimeUnit unit) {
checkArgument(sendTimeout >= 0, "sendTimeout needs to be >= 0");
conf.setSendTimeoutMs(sendTimeout, unit);
return this;
}

@Override
public ProducerBuilder<T> maxPendingMessages(int maxPendingMessages) {
checkArgument(maxPendingMessages >= 0, "maxPendingMessages needs to be >= 0");
conf.setMaxPendingMessages(maxPendingMessages);
return this;
}

@Override
public ProducerBuilder<T> maxPendingMessagesAcrossPartitions(int maxPendingMessagesAcrossPartitions) {
checkArgument(maxPendingMessagesAcrossPartitions >= 0, "maxPendingMessagesAcrossPartitions needs to be >= 0");
conf.setMaxPendingMessagesAcrossPartitions(maxPendingMessagesAcrossPartitions);
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public class ClientConfigurationData implements Serializable, Cloneable {
@ApiModelProperty(
name = "connectionsPerBroker",
value = "Number of connections established between the client and each Broker."
+ "A value of 0 means to disable connection pooling."
)
private int connectionsPerBroker = 1;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
import org.apache.pulsar.client.api.AuthenticationDataProvider;
import org.apache.pulsar.client.api.AuthenticationFactory;
import org.apache.pulsar.common.naming.TopicName;
import org.apache.pulsar.testclient.ParameterValidator;
import org.apache.pulsar.testclient.PositiveNumberParameterValidator;
import org.apache.pulsar.testclient.PerfClientUtils;
import org.apache.pulsar.testclient.utils.PaddingDecimalFormat;
import org.slf4j.Logger;
Expand Down Expand Up @@ -91,7 +91,7 @@ static class Arguments {
@Parameter(names = { "-s", "--size" }, description = "Message size in byte")
public int msgSize = 1024;

@Parameter(names = { "-t", "--num-topic" }, description = "Number of topics", validateWith = ParameterValidator.class)
@Parameter(names = { "-t", "--num-topic" }, description = "Number of topics", validateWith = PositiveNumberParameterValidator.class)
public int numTopics = 1;

@Parameter(names = { "--auth_plugin" }, description = "Authentication plugin class name")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ static class Arguments {
@Parameter(names = { "-s", "--size" }, description = "Message size")
public int msgSize = 1024;

@Parameter(names = { "-t", "--num-topic" }, description = "Number of managed ledgers", validateWith = ParameterValidator.class)
@Parameter(names = { "-t", "--num-topic" }, description = "Number of managed ledgers", validateWith = PositiveNumberParameterValidator.class)
public int numManagedLedgers = 1;

@Parameter(names = { "--threads" }, description = "Number of threads writing", validateWith = ParameterValidator.class)
@Parameter(names = { "--threads" }, description = "Number of threads writing", validateWith = PositiveNumberParameterValidator.class)
public int numThreads = 1;

@Parameter(names = { "-zk", "--zookeeperServers" }, description = "ZooKeeper connection string", required = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
Expand Down Expand Up @@ -83,13 +82,13 @@ static class Arguments {
@Parameter(description = "persistent://prop/ns/my-topic", required = true)
public List<String> topic;

@Parameter(names = { "-t", "--num-topics" }, description = "Number of topics", validateWith = ParameterValidator.class)
@Parameter(names = { "-t", "--num-topics" }, description = "Number of topics", validateWith = PositiveNumberParameterValidator.class)
public int numTopics = 1;

@Parameter(names = { "-n", "--num-consumers" }, description = "Number of consumers (per subscription), only one consumer is allowed when subscriptionType is Exclusive", validateWith = ParameterValidator.class)
@Parameter(names = { "-n", "--num-consumers" }, description = "Number of consumers (per subscription), only one consumer is allowed when subscriptionType is Exclusive", validateWith = PositiveNumberParameterValidator.class)
public int numConsumers = 1;

@Parameter(names = { "-ns", "--num-subscriptions" }, description = "Number of subscriptions (per topic)", validateWith = ParameterValidator.class)
@Parameter(names = { "-ns", "--num-subscriptions" }, description = "Number of subscriptions (per topic)", validateWith = PositiveNumberParameterValidator.class)
public int numSubscriptions = 1;

@Parameter(names = { "-s", "--subscriber-name" }, description = "Subscriber name prefix", hidden = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
Expand Down Expand Up @@ -109,7 +108,7 @@ static class Arguments {
@Parameter(description = "persistent://prop/ns/my-topic", required = true)
public List<String> topics;

@Parameter(names = { "-threads", "--num-test-threads" }, description = "Number of test threads", validateWith = ParameterValidator.class)
@Parameter(names = { "-threads", "--num-test-threads" }, description = "Number of test threads", validateWith = PositiveNumberParameterValidator.class)
public int numTestThreads = 1;

@Parameter(names = { "-r", "--rate" }, description = "Publish rate msg/s across topics")
Expand All @@ -118,10 +117,10 @@ static class Arguments {
@Parameter(names = { "-s", "--size" }, description = "Message size (bytes)")
public int msgSize = 1024;

@Parameter(names = { "-t", "--num-topic" }, description = "Number of topics", validateWith = ParameterValidator.class)
@Parameter(names = { "-t", "--num-topic" }, description = "Number of topics", validateWith = PositiveNumberParameterValidator.class)
public int numTopics = 1;

@Parameter(names = { "-n", "--num-producers" }, description = "Number of producers (per topic)", validateWith = ParameterValidator.class)
@Parameter(names = { "-n", "--num-producers" }, description = "Number of producers (per topic)", validateWith = PositiveNumberParameterValidator.class)
public int numProducers = 1;

@Parameter(names = {"--separator"}, description = "Separator between the topic and topic number")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static class Arguments {
@Parameter(description = "persistent://prop/ns/my-topic", required = true)
public List<String> topic;

@Parameter(names = { "-t", "--num-topics" }, description = "Number of topics", validateWith = ParameterValidator.class)
@Parameter(names = { "-t", "--num-topics" }, description = "Number of topics", validateWith = PositiveNumberParameterValidator.class)
public int numTopics = 1;

@Parameter(names = { "-r", "--rate" }, description = "Simulate a slow message reader (rate in msg/s)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
import com.beust.jcommander.IParameterValidator;
import com.beust.jcommander.ParameterException;

public class ParameterValidator implements IParameterValidator {
public class PositiveNumberParameterValidator implements IParameterValidator {

@Override
public void validate(String name, String value) throws ParameterException {
if (Integer.parseInt(value) <= 0) {
throw new ParameterException("Parameter " + name + " should be > 0 (found " + value + ")");
}
return;
}
}
16 changes: 8 additions & 8 deletions site2/docs/reference-cli-tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ Options
|`-ss`, `--subscriptions`|A list of subscriptions to consume on (e.g. sub1,sub2)|sub|
|`-st`, `--subscription-type`|Subscriber type. Possible values are Exclusive, Shared, Failover, Key_Shared.|Exclusive|
|`-sp`, `--subscription-position`|Subscriber position. Possible values are Latest, Earliest.|Latest|
|`-time`, `--test-duration`|Test duration in secs. If <= 0, it will keep consuming|0|
|`-time`, `--test-duration`|Test duration (in seconds). If this value is less than or equal to 0, it keeps consuming messages.|0|
|`--trust-cert-file`|Path for the trusted TLS certificate file||
|`--tls-allow-insecure`|Allow insecure TLS connection||

Expand Down Expand Up @@ -478,7 +478,7 @@ Options
|`-c`, `--max-connections`|Max number of TCP connections to a single broker|100|
|`-o`, `--max-outstanding`|Max number of outstanding messages|1000|
|`-p`, `--max-outstanding-across-partitions`|Max number of outstanding messages across partitions|50000|
|`-m`, `--num-messages`|Number of messages to publish in total. If <= 0, it will keep publishing.|0|
|`-m`, `--num-messages`|Number of messages to publish in total. If this value is less than or equal to 0, it keeps publishing messages.|0|
|`-n`, `--num-producers`|The number of producers (per topic)|1|
|`-t`, `--num-topic`|The number of topics|1|
|`-f`, `--payload-file`|Use payload from an UTF-8 encoded text file and a payload will be randomly selected when publishing messages||
Expand All @@ -487,7 +487,7 @@ Options
|`-u`, `--service-url`|Pulsar service URL||
|`-s`, `--size`|Message size (in bytes)|1024|
|`-i`, `--stats-interval-seconds`|Statistics interval seconds. If 0, statistics will be disabled.|0|
|`-time`, `--test-duration`|Test duration in secs. If <= 0, it will keep publishing.|0|
|`-time`, `--test-duration`|Test duration (in seconds). If this value is less than or equal to 0, it keeps publishing messages.|0|
|`--trust-cert-file`|Path for the trusted TLS certificate file||
|`--warmup-time`|Warm-up time in seconds|1|
|`--tls-allow-insecure`|Allow insecure TLS connection||
Expand Down Expand Up @@ -516,7 +516,7 @@ Options
|`-u`, `--service-url`|Pulsar service URL||
|`-m`, `--start-message-id`|Start message id. This can be either 'earliest', 'latest' or a specific message id by using 'lid:eid'|earliest|
|`-i`, `--stats-interval-seconds`|Statistics interval seconds. If 0, statistics will be disabled.|0|
|`-time`, `--test-duration`|Test duration in secs. If <= 0, it will keep consuming|0|
|`-time`, `--test-duration`|Test duration (in seconds). If this value is less than or equal to 0, it keeps consuming messages.|0|
|`--trust-cert-file`|Path for the trusted TLS certificate file||
|`--use-tls`|Use TLS encryption on the connection|false|
|`--tls-allow-insecure`|Allow insecure TLS connection||
Expand All @@ -536,13 +536,13 @@ Options
|`--auth_plugin`|Authentication plugin class name||
|`--conf-file`|Configuration file||
|`-h`, `--help`|Help message|false|
|`-m`, `--num-messages`|Number of messages to publish in total. If <= 0, it will keep publishing|0|
|`-m`, `--num-messages`|Number of messages to publish in total. If this value is less than or equal to 0, it keeps publishing messages.|0|
|`-t`, `--num-topic`|The number of topics|1|
|`-f`, `--payload-file`|Use payload from a file instead of empty buffer||
|`-u`, `--proxy-url`|Pulsar Proxy URL, e.g., "ws://localhost:8080/"||
|`-r`, `--rate`|Publish rate msg/s across topics|100|
|`-s`, `--size`|Message size in byte|1024|
|`-time`, `--test-duration`|Test duration in secs. If <= 0, it will keep publishing|0|
|`-time`, `--test-duration`|Test duration (in seconds). If this value is less than or equal to 0, it keeps publishing messages.|0|


### `managed-ledger`
Expand All @@ -562,11 +562,11 @@ Options
|`-h`, `--help`|Help message|false|
|`-c`, `--max-connections`|Max number of TCP connections to a single bookie|1|
|`-o`, `--max-outstanding`|Max number of outstanding requests|1000|
|`-m`, `--num-messages`|Number of messages to publish in total. If <= 0, it will keep publishing|0|
|`-m`, `--num-messages`|Number of messages to publish in total. If this value is less than or equal to 0, it keeps publishing messages.|0|
|`-t`, `--num-topic`|Number of managed ledgers|1|
|`-r`, `--rate`|Write rate msg/s across managed ledgers|100|
|`-s`, `--size`|Message size in byte|1024|
|`-time`, `--test-duration`|Test duration in secs. If <= 0, it will keep publishing|0|
|`-time`, `--test-duration`|Test duration (in seconds). If this value is less than or equal to 0, it keeps publishing messages.|0|
|`--threads`|Number of threads writing|1|
|`-w`, `--write-quorum`|Ledger write quorum|1|
|`-zk`, `--zookeeperServers`|ZooKeeper connection string||
Expand Down