-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][client]Reduce CPU usage when client idle and batch message enable #23188
base: master
Are you sure you want to change the base?
Conversation
Reduce CPU usage when client idle and batch message enable
@stillerrr Please add the following content to your PR description and select a checkbox:
|
@@ -266,6 +271,8 @@ public ProducerImpl(PulsarClientImpl client, String topic, ProducerConfiguration | |||
} | |||
this.batchMessageContainer = (BatchMessageContainerBase) containerBuilder.build(); | |||
this.batchMessageContainer.setProducer(this); | |||
ThreadFactory threadFactory = new ExecutorProvider.ExtendedThreadFactory("pulsar-batch", Thread.currentThread().isDaemon()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we reuse an existing thread pool? Otherwise each ProducerImpl(partition) will create a thread pool
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resue the scheduleExecutorProvider of PulsarClientImpl
ClientCnx cnx = cnx(); | ||
if (cnx != null && isBatchMessagingEnabled()) { | ||
this.batchFlushTask = cnx.ctx().executor().schedule(catchingAndLoggingThrowables(this::batchFlushTask), | ||
if (isBatchMessagingEnabled()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why remove cnx != null
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
already add back, make sure the judgment is not changed
Reuse PulsarClient scheduleExecutorProvider
Add back the judgment condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reduce CPU usage when client idle and batch message enable
I don't see how the executor type for the batchFlushTask
could be the source of high CPU when the client is idling. The batchFlushTask
is a one-time task and it will only be scheduled when there's an ongoing batch.
@hanmz In this case, there shouldn't be any active tasks if the client is idle. please check my comment #23188 (review) . That's why this PR doesn't make sense to me. |
@stillerrr Have you tried profiling with Async Profiler to find out what's going on? |
@stillerrr There shouldn't be any sending tasks at all when the client is idle. please see my previous comment. That's why it's necessary to profile this with Async Profiler. |
@hanmz @lhotari The point thing is In version 2.10.4, pulsar producer do scheduled task once 1ms, the result of cpu usage is what I sent |
The description is currently misleading. Re: #23187 (comment) |
Reduce CPU usage when client idle and batch message enable
Fixes #23187
Motivation
ProducerImple use EventLoopGroup to send batch message per 1ms by default, it would cause about 14% CPU usage when client is idle and no messaage producing
Modifications
Use JDK ScheduleExecutorService to do this schedule task
Verifying this change
(Please pick either of the following options)
This change is a trivial rework / code cleanup without any test coverage.
(or)
This change is already covered by existing tests, such as (please describe tests).
(or)
This change added tests and can be verified as follows:
(example:)
Does this pull request potentially affect one of the following parts:
If the box was checked, please highlight the changes
Documentation
doc
doc-required
doc-not-needed
doc-complete
Matching PR in forked repository
PR in forked repository: