MCPcopy
hub / github.com/IBM/sarama / LeastLoadedBroker

Method LeastLoadedBroker

client.go:792–815  ·  view source on GitHub ↗

LeastLoadedBroker returns the broker with the least pending requests. Firstly, choose the broker from cached broker list. If the broker list is empty, choose from seed brokers.

()

Source from the content-addressed store, hash-verified

790// LeastLoadedBroker returns the broker with the least pending requests.
791// Firstly, choose the broker from cached broker list. If the broker list is empty, choose from seed brokers.
792func (client *client) LeastLoadedBroker() *Broker {
793 client.lock.RLock()
794 defer client.lock.RUnlock()
795
796 var leastLoadedBroker *Broker
797 pendingRequests := math.MaxInt
798 for _, broker := range client.brokers {
799 if pendingRequests > broker.ResponseSize() {
800 pendingRequests = broker.ResponseSize()
801 leastLoadedBroker = broker
802 }
803 }
804 if leastLoadedBroker != nil {
805 _ = leastLoadedBroker.Open(client.conf)
806 return leastLoadedBroker
807 }
808
809 if len(client.seedBrokers) > 0 {
810 _ = client.seedBrokers[0].Open(client.conf)
811 return client.seedBrokers[0]
812 }
813
814 return leastLoadedBroker
815}
816
817// private caching/lazy metadata helpers
818

Callers 3

InitProducerIDMethod · 0.95
tryRefreshMetadataMethod · 0.95
findCoordinatorMethod · 0.95

Calls 2

OpenMethod · 0.95
ResponseSizeMethod · 0.80

Tested by

no test coverage detected