feat(client): Re-use already connected broker without pending request to fetch metadata - #3605
feat(client): Re-use already connected broker without pending request to fetch metadata#3605lbcjbb wants to merge 1 commit into
Conversation
b95c115 to
d00d33b
Compare
d00d33b to
d5f32a6
Compare
|
Thanks, seems like a good refinement - can you add a simple TestLeastLoadedBroker unittest just to lock in the deterministic behaviour - with connected idle broker and a couple of disconnected brokers assert that no connection is opened on the others? |
d5f32a6 to
ccd210e
Compare
|
@puellanivis @dnwe Thank you for your review 🙏. |
2e80512 to
239728c
Compare
|
Hmm, I'm not sure about these most recent updates Refactoring to add The Regarding the change in general, the new priority order seems to be:
That means a healthy connected broker with 1 pending request now loses to a completely disconnected broker, forcing a new connection? That doesn't seem to meet the goal that your original issue description was aiming for? |
I've added this new func
I can't see how we could do it any other way, or perhaps by introducing brokers with fake connection when necessary.
I’ve been wondering about that. Is it better to prioritise a healthy connected broker, even if this broker is still processing a request? Or assume the costs involve in establishing a new connection to another broker? |
|
I was proposing an equally simple and direct third function that returned two pieces of information that would otherwise be acquired through two mutex locks. I did not suggest that there should be a One Function To Rule Them All™ that each of the simple functions should call into and then return specific values from. We’re allowed to have a little bit of copying… as a treat. Especially, when that little bit of copying keeps everything simple. Three simple and direct functions heavily outweighs one complicated function called by three functions that then prune out the results they care about. |
Current existing behavior did not account for if the broker was connected or not. So the previous behavior was to prefer the first broker that was either idle, or disconnected. (Both would have a RequestSize of zero.) We probably do want to switch to preferring the least loaded connected broker, especially if it’s under some magic number of requests. Like you say, a broker with a RequestSize of 1 is probably better than connecting out to another broker. But if all the connected Brokers are all swamped, then we probably really do want to connect out to a disconnected broker. |
…s to fetch metadata When several brokers are not connected or connected and idle, `Client.LeastLoadedBroker()` could establish a new connection to a broker rather than favouring an already connected broker. This happends depending on the iteration order of the brokers's map which is not predictable. This change makes a slight adjustment of this method to return the first connected and idle broker encountered, which may drastically reduce the total number of connection per broker when a same Kafka cluster is used by several thousand applications. Signed-off-by: Jean-Baptiste Bronisz <jean-baptiste.bronisz@adevinta.com>
239728c to
f8df9f1
Compare
It's fixed |
|
Do you know how it was implemented in the confluent-kafka-go, or a Kafka library in Python or Java? |
|
In the librdkafka library, rd_kafka_metadata() calls rd_kafka_broker_weight_usable. |
When several brokers are not connected or connected and idle,
Client.LeastLoadedBroker()could establish a new connection to a broker rather than favouring an already connected broker. This happends depending on the iteration order of the brokers's map which is not predictable.This change makes a slight adjustment of this method to return the first connected and idle broker encountered, which may drastically reduce the total number of connection per broker when a same Kafka cluster is used by several thousand applications.