[improve][client]pulsar-client-io thread has high CPU usage when client idle and batch message enable
Search before asking
- [X] I searched in the issues and found nothing similar.
Motivation
Create a pulsar client and to initialize, send a little message to topic, then the pulsar-client-io thread(just 1 thread by default) cpu usage is 14%, but client is idle, no action for it.
the root cause is that batch message sending is enable, ProducerImpl would use pulsar-client-io thread to send message per 1ms by default
pulsar-client use EventLoopGroup as thread pool, the thread name is "pulsar-client-io",EpollEventLoopGroup is preferred.
When switch to NioEventLoopGroup, the CPU usage just reduce little to 9.6%
Solution
Use ScheduledExecutorService to send batch message to replace the EventLoopGroup. It would reduce CPU usage less than 1%
Alternatives
No response
Anything else?
No response
Are you willing to submit a PR?
- [X] I'm willing to submit a PR!
@stillerrr When the client is idle, batchFlushTasks aren't scheduled in the Pulsar client code. The current problem description where it says "when client idle" doesn't make sense to my.
It could be useful to use a real profiler sync as https://github.com/async-profiler/async-profiler to pinpoint the problem.
It could be useful to use a real profiler sync as https://github.com/async-profiler/async-profiler to pinpoint the problem.
EventLoopGroup is always running, and NIOEventLoopGroup use less CPU (about 9%) than EpollEventLoopGroup
@stillerrr When the client is idle, batchFlushTasks aren't scheduled in the Pulsar client code. The current problem description where it says "when client idle" doesn't make sense to my.
EventLoopGroup do scheduled task would use more CPU than ScheduledExecutorService
"when client idle" means few requests, maybe 1000 request per second, and it would cause batchFlushTasks scheduled
"when client idle" means few requests, maybe 1000 request per second, and it would cause batchFlushTasks scheduled
well, it's not really idling if there's 1000 requests per second. I think that the title of this issue is very misleading.