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

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

merged 3 commits into from
Sep 23, 2021

Conversation

yuruguo
Copy link
Contributor

@yuruguo yuruguo commented Sep 8, 2021

Fixes #11983

Motivation

When I execute pulsar-perf to simulate pub/sub test, I found that the task can be started normally after some options are set to unreasonable values, but there is no instance running, which leads to a waste of resources. In fact, when these unreasonable values appear, we should check to prevent the task from starting.
for example: ./bin/pulsar-perf consume --num-consumers -1 test

Modifications

  • Add ParameterValidator class
  • Correct parameter description
  • Use checkArgument method

Documentation

  • Need to update docs

@Anonymitaet Anonymitaet added the doc-not-needed Your PR changes do not impact docs label Sep 9, 2021
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall it looks good to me

I left one comment

if (Integer.parseInt(value) <= 0) {
throw new ParameterException("Parameter " + name + " should be > 0 (found " + value + ")");
}
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this is not needed

import com.beust.jcommander.ParameterException;

public class ParameterValidator implements IParameterValidator {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about naming this like PositiveNumberParameterValidator ?

Copy link
Contributor Author

@yuruguo yuruguo Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with it. Have renamed, PTAL.

@yuruguo yuruguo requested a review from eolivelli September 10, 2021 01:07
Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Just one minor edge case that needs to be addressed.

@@ -164,6 +167,7 @@ public ClientBuilder listenerThreads(int numListenerThreads) {

@Override
public ClientBuilder connectionsPerBroker(int connectionsPerBroker) {
checkArgument(connectionsPerBroker >= 0, "connectionsPerBroker needs to be >= 0");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per the java doc on the ClientBuilder interface, the value must be greater than 0.

Suggested change
checkArgument(connectionsPerBroker >= 0, "connectionsPerBroker needs to be >= 0");
checkArgument(connectionsPerBroker > 0, "connectionsPerBroker needs to be > 0");

Copy link
Contributor Author

@yuruguo yuruguo Sep 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. PTAL again, THX!

I have reverted,see review

@@ -69,7 +69,7 @@ protected void cleanup() throws Exception {
@Override
protected void customizeNewPulsarClientBuilder(ClientBuilder clientBuilder) {
// disable connection pooling
clientBuilder.connectionsPerBroker(0);
// clientBuilder.connectionsPerBroker(0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please revert

Copy link
Contributor Author

@yuruguo yuruguo Sep 14, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value of connectionsPerBroker must be greater than 0 (doc in ClientBuilder L266), and this test will fail after the check is added, so a comment is made.

Related review:#11973 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so what do you suggest ?
modifying a test means that we modify the behaviour and this is not good (most of the times)

This test tells me that 0 is an allowed number, so you have to update your preconditions (and docs?) and let this test pass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you that 0 is a feasible value for this test. So I update the document and revert the test.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at how this setting is used, and 0 is a valid setting.

if (maxConnectionsPerHosts == 0) {
// Disable pooling
return createConnection(logicalAddress, physicalAddress, -1);
}

@yuruguo yuruguo requested a review from eolivelli September 15, 2021 08:37
Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@michaeljmarshall PTAL

Copy link
Member

@michaeljmarshall michaeljmarshall left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should improve the javadoc to better explain what 0 connections per broker means. Otherwise, looks good to me.

@@ -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 not less than 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the name of this setting (connectionsPerBroker), it isn't immediately clear to me why 0 is a valid setting. I think we should add a note specifying that a value of 0 will disable connection pooling. I think it could also be valuable to update the client configuration file with the same note:

@ApiModelProperty(
name = "connectionsPerBroker",
value = "Number of connections established between the client and each Broker."
)
private int connectionsPerBroker = 1;

Nit: my preference for this line is to write this as needs to be greater than or equal to 0. Your change is certainly correct, so I'm not sure how much my preference matters, but based on a quick search through the project, we often use greater than or equal to in this situation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good suggestion, done. PTAL

Copy link
Contributor

@315157973 315157973 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Anonymitaet Please help review the docs

@@ -448,6 +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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
|`-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|

Please check all occurrences and keep consistent.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution. Does this affect only master or other versioned docs?
If latter, could you please help update all affected versions? Thanks

Copy link
Contributor Author

@yuruguo yuruguo Sep 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. The document has been checked and updated, PTAL again @Anonymitaet , thx!
  2. This affects only master docs.

@Anonymitaet Anonymitaet added doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. and removed doc-not-needed Your PR changes do not impact docs labels Sep 22, 2021
@yuruguo yuruguo requested a review from Anonymitaet September 22, 2021 08:12
@congbobo184 congbobo184 merged commit 9516e5d into apache:master Sep 23, 2021
@Anonymitaet Anonymitaet added this to the 2.9.0 milestone Oct 18, 2021
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc Your PR contains doc changes, no matter whether the changes are in markdown or code files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve parameter checking in pulsar-perf
6 participants