[Broker] Use shared executors for broker and geo-replication clients#13839
Conversation
| doc = "Number of shared threads to use for broker clients." | ||
| + " Default is set to `2 * Runtime.getRuntime().availableProcessors()`" | ||
| ) | ||
| private int brokerClientNumIOThreads = 2 * Runtime.getRuntime().availableProcessors(); |
There was a problem hiding this comment.
I'd say that we should prob reuse the broker IO threads here
There was a problem hiding this comment.
The problem is that broker IO threads is a EventLoopGroup instance which is already used in the Pulsar Client.
The Pulsar Client has this internal/IO and external/listener executors in addition to the eventLoopGroup.
It might be a risky change in Pulsar Client to replace the internal executor to delegate directly to eventLoopGroup.
This is the reason why I think it's necessary to have a separate setting to control the amount of threads used to run the Pulsar Client internal executors. Before this PR each client has had a single threaded internal executor for each client instance.
There was a problem hiding this comment.
Yes, I think the confusion comes from the name brokerClientNumIOThreads, since it's client internal executor and not the client event loop which is already shared.
Additionally, the client internal executor shouldn't really be used a lot in broker, since it's used mainly for dispatching the partitioned/multi topic consumers, so we could just default to 1 thread instead.
There was a problem hiding this comment.
Yes, I think the confusion comes from the name brokerClientNumIOThreads, since it's client internal executor and not the client event loop which is already shared.
That's true. The Pulsar Client uses the numIOThreads parameter for configuring the number of threads for the eventLoopGroup and also for the internal/IO executor.
This is confusing. The internal executor was introduced in #8208 and that change uses numIOThreads parameter also for configuring the number of threads for the internal executor. @merlimat I wonder what would be a way to improve this situation?
There was a problem hiding this comment.
Additionally, the client internal executor shouldn't really be used a lot in broker, since it's used mainly for dispatching the partitioned/multi topic consumers, so we could just default to 1 thread instead.
yes, that is true. I wonder if the value needs to be configurable at all? I'll remove brokerClientNumIOThreads key and just use the value 1 as I did for the external executor.
- don't ever make it a daemon thread
| // the external executor is not used in the broker client or replication clients since this executor is | ||
| // used for consumer listeners. | ||
| // since an instance is required, a single threaded shared instance is used for all broker client instances |
There was a problem hiding this comment.
Doesn't this hint at a problem in the java client? It looks like a listener is declared on consumer initialization. We could change the behavior so that it only gets a thread when there is a listener.
We'll still have the issue of creating an ExecutorProvider per client, so this change still makes sense, but it'd be cheaper for end users to avoid the thread creation for consumers that lack listeners.
I am going to open a PR to update the Java Consumer.
There was a problem hiding this comment.
Doesn't this hint at a problem in the java client? It looks like a listener is declared on consumer initialization. We could change the behavior so that it only gets a thread when there is a listener.
Yes the client isn't optimal, but I doubt that it causes an actual measurable overhead. I think that the thread is just pinned out of the single shared thread and nothing will get run on it (in the current usage patterns when client is used in the broker).
There was a problem hiding this comment.
Yes the client isn't optimal, but I doubt that it causes an actual measurable overhead. I think that the thread is just pinned out of the single shared thread and nothing will get run on it (in the current usage patterns when client is used in the broker).
I was thinking about user applications that have many consumers. I just looked a bit closer, and the upper limit here is NumListenerThreads in the client configuration. That is the max number of threads a client will spawn for consumer listeners. Was this a problem in the broker because we have many clients?
Motivation
Modifications