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

[cli] Enable CLI to publish non-batched messages #12641

Merged
merged 1 commit into from
Nov 8, 2021

Conversation

massakam
Copy link
Contributor

@massakam massakam commented Nov 5, 2021

Motivation

Currently, messages produced by the pulsar-client command are always batched. However, zero queue consumers cannot receive these batched messages. I think it would be useful to be able to easily produce non-batched messages.

Modifications

Added an option to disable batching to the pulsar-client command:

$ ./bin/pulsar-client produce -m hello -n 10 --disable-batching persistent://public/default/t1

Verifying this change

  • Make sure that the change passes the CI checks.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)
  • The rest endpoints: (no)
  • The admin cli options: (no)
  • Anything that affects deployment: (no)

Documentation

  • doc

@massakam massakam added type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. area/cli labels Nov 5, 2021
@massakam massakam added this to the 2.10.0 milestone Nov 5, 2021
@massakam massakam self-assigned this Nov 5, 2021
@@ -107,6 +107,9 @@
description = "Rate (in msg/sec) at which to produce," +
" value 0 means to produce messages as fast as possible.")
private double publishRate = 0;

@Parameter(names = { "-db", "--disable-batching" }, description = "Disable batch sending of messages")
Copy link
Contributor

Choose a reason for hiding this comment

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

It better to named --batch-enabled? and the default is true.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Normally, boolean type options do not require a value, so the default value should be false.

# By default batching is enabled
$ ./bin/pulsar-client produce -m hello persistent://public/default/t1

# Batching is enabled in this case as well
$ ./bin/pulsar-client produce -m hello --batch-enabled persistent://public/default/t1

We can set the default value to true by specifying arity = 1, but it may be a bit verbose.
https://jcommander.org/#_boolean

# Batching is enabled
$ ./bin/pulsar-client produce -m hello --batch-enabled true persistent://public/default/t1

# Batching is disabled
$ ./bin/pulsar-client produce -m hello --batch-enabled false persistent://public/default/t1

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that makes sense.

How about keeping the same configurations with the perf producer?

        @Parameter(names = { "-b",
                "--batch-time-window" }, description = "Batch messages in 'x' ms window (Default: 1ms)")
        public double batchTimeMillis = 1.0;

        @Parameter(names = {
            "-bm", "--batch-max-messages"
        }, description = "Maximum number of messages per batch")
        public int batchMaxMessages = DEFAULT_BATCHING_MAX_MESSAGES;

        @Parameter(names = {
            "-bb", "--batch-max-bytes"
        }, description = "Maximum number of bytes per batch")
        public int batchMaxBytes = 4 * 1024 * 1024
if (arguments.batchTimeMillis <= 0.0 && arguments.batchMaxMessages <= 0) {
                producerBuilder.enableBatching(false);
            }

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the pulsar-client command, one batch message always contains only one message, even if batching is enabled. This is because we are using the synchronous method send() instead of the asynchronous method sendAsync().

So, unlike the perf producer, I don't think such fine-grained settings are useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is no particular benefit to enabling batching for the pulsar-client command, so we have the option of always disabling it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, that make sense.

Assert.assertTrue(msg.getMessageId() instanceof BatchMessageIdImpl);
} else {
Assert.assertEquals(new String(msg.getData()), "non-batched");
Assert.assertFalse(msg.getMessageId() instanceof BatchMessageIdImpl);
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that you have not checked if the message is from a batch message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this check not enough? Is there any other good way?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, my mistake. It's good.

Assert.assertTrue(msg.getMessageId() instanceof BatchMessageIdImpl);
} else {
Assert.assertEquals(new String(msg.getData()), "non-batched");
Assert.assertFalse(msg.getMessageId() instanceof BatchMessageIdImpl);
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, sorry, my mistake. It's good.

@codelipenghui codelipenghui merged commit a1bad71 into apache:master Nov 8, 2021
zeo1995 pushed a commit to zeo1995/pulsar that referenced this pull request Nov 9, 2021
* up/master:
  [Doc] Add explanations for setting geo-replication at topic level (apache#12633)
  commit chapter Tiered Storage (apache#12592)
  [pulsar-admin] Add remove-subscription-types-enabled command for namespace (apache#12392)
  Enable CLI to publish non-batched messages (apache#12641)
  [Doc] Add doc for tokenSettingPrefix (apache#12662)
  [pulsar-admin] Add corresponding get command for namespace (apache#12322)
  [pulsar-admin] Perfect judgment conditions of pulsar-admin (apache#12315)
  [broker] Avoid unnecessary recalculation of maxSubscriptionsPerTopic in AbstractTopic (apache#12658)
  [Transaction]Stop TB recovering with exception (apache#12636)
  [website][upgrade]feat: docs migration - 2.7.1 / client (apache#12612)
  [website][upgrade]feat: docs migration - 2.7.1 / performance (apache#12611)
  [website][upgrade]feat: docs migration - 2.7.1 / security (apache#12610)
  [Modernizer] Apply Modernizer plugin for pulsar broker common module and fix violation. (apache#12657)
  [Authorization] Support GET_METADATA topic op after enable auth (apache#12656)
  Fix StringIndexOutOfBoundsException in org.apache.pulsar.broker.resources.NamespaceResources#pathIsFromNamespace (apache#12659)
zeo1995 pushed a commit to zeo1995/pulsar that referenced this pull request Nov 9, 2021
* up/master:
  [Doc] Add explanations for setting geo-replication at topic level (apache#12633)
  commit chapter Tiered Storage (apache#12592)
  [pulsar-admin] Add remove-subscription-types-enabled command for namespace (apache#12392)
  Enable CLI to publish non-batched messages (apache#12641)
  [Doc] Add doc for tokenSettingPrefix (apache#12662)
  [pulsar-admin] Add corresponding get command for namespace (apache#12322)
  [pulsar-admin] Perfect judgment conditions of pulsar-admin (apache#12315)
  [broker] Avoid unnecessary recalculation of maxSubscriptionsPerTopic in AbstractTopic (apache#12658)
  [Transaction]Stop TB recovering with exception (apache#12636)
  [website][upgrade]feat: docs migration - 2.7.1 / client (apache#12612)
  [website][upgrade]feat: docs migration - 2.7.1 / performance (apache#12611)
  [website][upgrade]feat: docs migration - 2.7.1 / security (apache#12610)
  [Modernizer] Apply Modernizer plugin for pulsar broker common module and fix violation. (apache#12657)
  [Authorization] Support GET_METADATA topic op after enable auth (apache#12656)
  Fix StringIndexOutOfBoundsException in org.apache.pulsar.broker.resources.NamespaceResources#pathIsFromNamespace (apache#12659)

# Conflicts:
#	site2/website-next/versioned_sidebars/version-2.7.2-sidebars.json
@massakam massakam deleted the cli-non-batched-msg branch November 9, 2021 03:15
codelipenghui pushed a commit that referenced this pull request Nov 18, 2021
### Motivation

Currently, messages produced by the `pulsar-client` command are always batched. However, zero queue consumers cannot receive these batched messages. I think it would be useful to be able to easily produce non-batched messages.

### Modifications

Added an option to disable batching to the `pulsar-client` command:
```sh
$ ./bin/pulsar-client produce -m hello -n 10 --disable-batching persistent://public/default/t1
```

(cherry picked from commit a1bad71)
@codelipenghui codelipenghui added cherry-picked/branch-2.8 Archived: 2.8 is end of life release/2.8.2 and removed release/2.8.3 labels Nov 18, 2021
eolivelli pushed a commit to eolivelli/pulsar that referenced this pull request Nov 29, 2021
### Motivation

Currently, messages produced by the `pulsar-client` command are always batched. However, zero queue consumers cannot receive these batched messages. I think it would be useful to be able to easily produce non-batched messages.

### Modifications

Added an option to disable batching to the `pulsar-client` command:
```sh
$ ./bin/pulsar-client produce -m hello -n 10 --disable-batching persistent://public/default/t1
```
codelipenghui pushed a commit that referenced this pull request Dec 20, 2021
### Motivation

Currently, messages produced by the `pulsar-client` command are always batched. However, zero queue consumers cannot receive these batched messages. I think it would be useful to be able to easily produce non-batched messages.

### Modifications

Added an option to disable batching to the `pulsar-client` command:
```sh
$ ./bin/pulsar-client produce -m hello -n 10 --disable-batching persistent://public/default/t1
```

(cherry picked from commit a1bad71)
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Dec 20, 2021
momo-jun added a commit to momo-jun/pulsar that referenced this pull request Aug 4, 2022
momo-jun added a commit to momo-jun/pulsar that referenced this pull request Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli cherry-picked/branch-2.8 Archived: 2.8 is end of life cherry-picked/branch-2.9 Archived: 2.9 is end of life doc Your PR contains doc changes, no matter whether the changes are in markdown or code files. release/2.8.2 release/2.9.2 type/enhancement The enhancements for the existing features or docs. e.g. reduce memory usage of the delayed messages
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants