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.
()
| 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. |
| 792 | func (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 |
no test coverage detected