0x-infinity opened a new issue, #994:
URL: https://github.com/apache/incubator-seata-go/issues/994
### 讨论详情
### Description
In `pkg/remoting/loadbalance/round_robin_loadbalance.go`, each call to
`RoundRobinLoadBalance()` creates new map and slice, and performs sorting
operations.
**Problem Code**: `pkg/remoting/loadbalance/round_robin_loadbalance.go:31-54`
```go
func RoundRobinLoadBalance(sessions *sync.Map, s string) getty.Session {
adderToSession := make(map[string]getty.Session, 0) // create new map
each time
adders := make([]string, 0) // create new slice
each time
sessions.Range(func(key, value interface{}) bool {
session := key.(getty.Session)
if session.IsClosed() {
sessions.Delete(key)
} else {
adderToSession[session.RemoteAddr()] = session
adders = append(adders, session.RemoteAddr())
}
return true
})
sort.Strings(adders) // sort each time
// ...
}
```
### Why Need Improve
1. Load balancing is a high-frequency operation, triggered on every RPC call
2. Large number of temporary objects increases GC pressure
3. Time complexity of sorting each time is O(n log n)
4. Session list is relatively stable, no need to rebuild each timeRetry
### 📚 相关背景
_No response_
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]