Skip to content

[Bug] pulsar-io EventLoopGroup is used in dispatchers to execute synchronized code and CPU intensive work #23865

Open

Description

@lhotari

Search before asking

  • I searched in the issues and found nothing similar.

Read release policy

  • I understand that unsupported versions don't get bug fixes. I will attempt to reproduce the issue on a supported version of Pulsar client and Pulsar broker.

Version

All released versions

Minimal reproduce step

In dispatchers, topic.getBrokerService().executor(), the "pulsar-io" EventLoopGroup is used to execute synchronized code and CPU intensive work. The "pulsar-io" EventLoopGroup is intended to be the worker for Pulsar's ServerCnx Netty handler so that network connections remain responsive. Since dispatcher implementations contain multiple synchronized methods, blocking operations could impact all connections that are bound to the same IO thread.

Another potential problem that the solution causes unnecessary context switching since the current solution doesn't use a single thread for the scheduled jobs and the work that it performs.

What did you expect to see?

A pinned executor to be used for executing all operations for a dispatcher or replicator.

What did you see instead?

EventLoopGroup is used as executor and the thread could change for each execution.

Anything else?

No response

Are you willing to submit a PR?

  • I'm willing to submit a PR!

Activity

  1. added
    type/bugThe PR fixed a bug or issue reported a bug
    on Jan 18, 2025
  2. added this to the 4.1.0 milestone on Jan 18, 2025
  3. self-assigned this
    on Jan 18, 2025
  4. lhotari commented on Aug 20, 2025

    @lhotari
    MemberAuthor

    this is a real performance issue with Pulsar. In #24623, I have added a solution for profiling test cases with Async Profiler with JFR integrated to it. It's possible to analyze the results with Eclipse Mission Control.

    The lock analysis shows that dispatchers contribute to most blocking on pulsar-io threads:
    Image

    This is a problem since Netty IO threads shouldn't ever be blocked since one thread is used across multiple connections to handle the asynchronous IO events. Blocking will cause a "noisy neighbor" problem across connections.

  5. modified the milestones: 4.1.0, 4.2.0 on Sep 8, 2025
  6. merlimat commented on Oct 24, 2026

    @merlimat
    Contributor

    Still present on master. BrokerService.executor() returns the Netty worker group (pulsar-broker/src/main/java/org/apache/pulsar/broker/service/BrokerService.java:3622), and the dispatchers still schedule their synchronized read and flow work on it, for example the read reschedule in PersistentDispatcherMultipleConsumers.java:602-604 and the flow handling at :330/:378, plus PersistentDispatcherSingleActiveConsumer.java:139/:439/:554 and PersistentReplicator.java:340/:365. Only the dispatch step itself now uses a pinned topic-ordered thread (PersistentDispatcherMultipleConsumers.java:182). So blocking in these methods can still stall every connection bound to the same pulsar-io thread. The likely fix is to run each dispatcher's and replicator's scheduled work on one thread chosen from the topic-ordered executor, as the dispatch step already does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/dispatcherbug-verifiedBug confirmed still present on current mastertype/bugThe PR fixed a bug or issue reported a bug

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions