-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement least active load balance #602
Conversation
"github.com/seata/seata-go/pkg/remoting/mock" | ||
) | ||
|
||
func TestConsistentHashLoadBalance(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该是LeastActive?
if session.IsClosed() { | ||
sessions.Delete(session) | ||
} else { | ||
interval := session.GetActive().UnixNano() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按照你目前的实现,最终变成了轮询,而不是最少活跃。原因:getty中的active指的是连接上次活跃的毫秒时间戳,无法代表连接的活跃度。
在seata java中,active指的是连接活跃度,在发送之前active cas 加1,在发送之后active cas 减1。在高并发使用场景下,对于最不被频繁使用的连接,其active值会首先变得更小,从而被优先选中。
建议:在least_active_loadbalance.go中实现类似于seata java的活跃度计算能力,注意使用cas处理并发增减活跃度,而不是锁。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
感谢,我再看看👀
@oldmee 按照pr模板的要求,在 |
@oldmee According to the requirements of the pr template, fill in the issue id after |
pkg/remoting/getty/getty_remoting.go
Outdated
@@ -19,6 +19,7 @@ package getty | |||
|
|||
import ( | |||
"fmt" | |||
"github.com/seata/seata-go/pkg/remoting/rpc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
乱了,change 下
package loadbalance | ||
|
||
import ( | ||
"github.com/seata/seata-go/pkg/remoting/rpc" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把所有的 import 风格规整下哈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
好的
pkg/remoting/rpc/rpc_status.go
Outdated
"sync/atomic" | ||
) | ||
|
||
var ServiceStatusMap sync.Map |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ServiceStatusMap 不需要被其它包访问,用小写非导出的形式会不会更好些。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嗯,我改一下
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #602 +/- ##
==========================================
+ Coverage 37.28% 37.44% +0.15%
==========================================
Files 175 177 +2
Lines 11666 11727 +61
==========================================
+ Hits 4350 4391 +41
- Misses 6952 6969 +17
- Partials 364 367 +3 ☔ View full report in Codecov by Sentry. |
@@ -61,14 +62,19 @@ func (g *GettyRemoting) SendSync(msg message.RpcMessage, s getty.Session, callba | |||
if s == nil { | |||
s = sessionManager.selectSession(msg) | |||
} | |||
return g.sendAsync(s, msg, callback) | |||
rpc.BeginCount(s.RemoteAddr()) | |||
result, err := g.sendAsync(s, msg, callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断处理 err
} | ||
|
||
func (g *GettyRemoting) SendASync(msg message.RpcMessage, s getty.Session, callback callbackMethod) error { | ||
if s == nil { | ||
s = sessionManager.selectSession(msg) | ||
} | ||
rpc.BeginCount(s.RemoteAddr()) | ||
_, err := g.sendAsync(s, msg, callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
判断处理 err
What this PR does:
implement least active load balance
Which issue(s) this PR fixes:
Fixes #585
Special notes for your reviewer:
Does this PR introduce a user-facing change?: