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

Optimize memory usage: support to shrink for pendingAcks map #14515

Merged
merged 13 commits into from
Mar 5, 2022

Conversation

lordcheng10
Copy link
Contributor

Modifications

issue: #14268

In order to optimize memory consumption, in the consumer class, the map used by the pendingAcks variable needs to support automatic shrink.

The original pendingAcks variable is defined by the ConcurrentLongLongPairHashMap class of bookkeeper. In order to be independent of the bookkeeper release version, this class is extracted into pulsar as a common class, similar to the ConcurrentLongHashMap class.

See the PR corresponding to bookkeeper: apache/bookkeeper#3061.

Documentation

Check the box below or label this PR directly (if you have committer privilege).

Need to update docs?

  • doc-required

    (If you need help on updating docs, create a doc issue)

  • no-need-doc

    (Please explain why)

  • doc

    (If this PR contains doc changes)

@github-actions github-actions bot added the doc-not-needed Your PR changes do not impact docs label Mar 1, 2022
@lordcheng10 lordcheng10 changed the title support to shrink for pendingAcks map Optimize memory usage: support to shrink for pendingAcks map Mar 1, 2022
category = CATEGORY_SERVER,
doc = "Whether ConcurrentLongLongPairHashMap supports automatic shrinking," +
"the default is false, which means automatic shrinking is not supported.")
private boolean autoShrink = false;
Copy link
Contributor

Choose a reason for hiding this comment

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

we shouldn't add this knob.
and if we really want the name should be more narrow and point exactly to the thing that we are changing

Copy link
Contributor Author

@lordcheng10 lordcheng10 Mar 1, 2022

Choose a reason for hiding this comment

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

remove this configuration? Or modify the configuration name? like: autoShrinkForConcurrentLongLongPairHashMap?

Copy link
Contributor

Choose a reason for hiding this comment

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

it is only for pendingAcks at the moment, so the name should reflect it.
it is not for every ConcurrentLongLongPairHashMap

Copy link
Contributor Author

Choose a reason for hiding this comment

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

like this?
autoShrinkForPendingAcks

Copy link
Contributor Author

@lordcheng10 lordcheng10 Mar 1, 2022

Choose a reason for hiding this comment

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

Fixed. PTAL,thanks! @eolivelli

rename autoShrink to autoShrinkForConsumerPendingAcksMap;

* @param autoShrink whether ConcurrentLongLongPairHashMap supports automatic shrinking.
* @return
*/
CompletableFuture<Consumer> subscribe(SubscriptionOption option, boolean autoShrink);
Copy link
Contributor

Choose a reason for hiding this comment

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

I believe that adding a new method for "autoShrink" is not necessary.
also the variable name should be more meaningful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you mean adding the autoShrink parameter directly on the original method?

Copy link
Contributor

Choose a reason for hiding this comment

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

this is global parameter, maybe you have another way to pass this way.
every Consumer will use the same value.

if you add a "parameter" in the function it means that it would be possible to see different values and this is not true

I believe that overall we don't need a configuration flag at all.

your change is good and you demonstrated that it is needed

cc @merlimat

Copy link
Contributor Author

@lordcheng10 lordcheng10 Mar 1, 2022

Choose a reason for hiding this comment

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

this is global parameter, maybe you have another way to pass this way.
every Consumer will use the same value.
if you add a "parameter" in the function it means that it would be possible to see different values and this is not true

OK , I will fix

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 believe that overall we don't need a configuration flag at all.

Do you think the autoShrink configuration item should not be added? When defining pendingAcks, set it directly to true? For example:
this.pendingAcks = ConcurrentLongLongPairHashMap.newBuilder()
.autoShrink(true)
.expectedItems(256)
.concurrencyLevel(1)
.build();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed. PTAL,thanks! @eolivelli
In the ServerCnx class, define a static variable autoShrinkForConsumerPendingAcksMap instead of passing parameters;

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@@ -704,6 +704,12 @@
)
private boolean isAllowAutoUpdateSchemaEnabled = true;

@FieldContext(
category = CATEGORY_SERVER,
doc = "Whether ConcurrentLongLongPairHashMap supports automatic shrinking,"
Copy link
Contributor

Choose a reason for hiding this comment

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

supports -> enable ?

Copy link
Contributor

Choose a reason for hiding this comment

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

And let's add some description about when it's better to enable this auto shinking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

*
* <p>Keys <strong>MUST</strong> be &gt;= 0.
*/
public class ConcurrentLongLongPairHashMap {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's better to copy unit test too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed
@Jason918 PTAL,thanks!

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

2 similar comments
@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

@lordcheng10
Copy link
Contributor Author

/pulsarbot run-failure-checks

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.

we are closer.
but we cannot use a 'static' variable

@@ -205,6 +205,7 @@
private boolean autoReadDisabledPublishBufferLimiting = false;
private final long maxPendingBytesPerThread;
private final long resumeThresholdPendingBytesPerThread;
public static boolean autoShrinkForConsumerPendingAcksMap;
Copy link
Contributor

Choose a reason for hiding this comment

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

this shouldn't be static

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 addition to defining static variables, or passing parameters through methods, I have not thought of other ways. @eolivelli Do you have any other good ideas?

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public static boolean autoShrinkForConsumerPendingAcksMap;
@Getter
private boolean autoShrinkForConsumerPendingAcksMap;

I think this works.

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 think this works.

The question here is: how do we pass autoShrinkForConsumerPendingAcksMap to the Consumer class, if we don't define autoShrinkForConsumerPendingAcksMap as static and pass the method parameters.

Copy link
Contributor Author

@lordcheng10 lordcheng10 Mar 3, 2022

Choose a reason for hiding this comment

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

Aha, I found a solution, the configuration can be accessed in this way in the consumer class:

subscription.getTopic().getBrokerService()
.getPulsar().getConfiguration().isAutoShrinkForConsumerPendingAcksMap()

Copy link
Contributor Author

@lordcheng10 lordcheng10 Mar 3, 2022

Choose a reason for hiding this comment

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

Fixed.
@eolivelli PTAL,thanks

Copy link
Contributor

Choose a reason for hiding this comment

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

The question here is: how do we pass autoShrinkForConsumerPendingAcksMap to the Consumer class, if we don't define autoShrinkForConsumerPendingAcksMap as static and pass the method parameters.

What I mean is like the handling of preciseDispatcherFlowControl.

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.

+1

great work !

@lordcheng10
Copy link
Contributor Author

lordcheng10 commented Mar 4, 2022

@Jason918 PTAL,thanks!

@lordcheng10
Copy link
Contributor Author

lordcheng10 commented Mar 4, 2022

@merlimat PTAL,thanks!

@codelipenghui codelipenghui added this to the 2.11.0 milestone Mar 4, 2022
@lordcheng10
Copy link
Contributor Author

ping

@eolivelli eolivelli merged commit e747b8f into apache:master Mar 5, 2022
Nicklee007 pushed a commit to Nicklee007/pulsar that referenced this pull request Apr 20, 2022
codelipenghui pushed a commit that referenced this pull request Apr 28, 2022
codelipenghui pushed a commit that referenced this pull request Apr 28, 2022
@codelipenghui codelipenghui added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Apr 28, 2022
codelipenghui pushed a commit that referenced this pull request Apr 29, 2022
@codelipenghui codelipenghui added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Apr 29, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request May 4, 2022
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request May 9, 2022
Shawyeok pushed a commit to Shawyeok/pulsar that referenced this pull request Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants