Skip to content
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

Merged
merged 11 commits into from
Feb 3, 2024
Merged

implement least active load balance #602

merged 11 commits into from
Feb 3, 2024

Conversation

oldmee
Copy link
Contributor

@oldmee oldmee commented Aug 10, 2023

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?:


"github.com/seata/seata-go/pkg/remoting/mock"
)

func TestConsistentHashLoadBalance(t *testing.T) {
Copy link
Contributor

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()
Copy link
Contributor

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处理并发增减活跃度,而不是锁。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢,我再看看👀

@iSuperCoder
Copy link
Contributor

@oldmee 按照pr模板的要求,在Fixes #后填写issue id。

@Issues-translate-bot
Copy link

RoBot detected the issue body's language is not English, translate it automatically. 👯👭🏻🧑‍🤝‍🧑👫🧑🏿‍🤝‍🧑🏻👩🏾‍🤝‍👨🏿👬🏿


@oldmee According to the requirements of the pr template, fill in the issue id after Fixes #.

@slievrly slievrly added this to the 1.3.0 milestone Aug 15, 2023
@@ -19,6 +19,7 @@ package getty

import (
"fmt"
"github.com/seata/seata-go/pkg/remoting/rpc"
Copy link
Contributor

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"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

把所有的 import 风格规整下哈

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的

"sync/atomic"
)

var ServiceStatusMap sync.Map
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ServiceStatusMap 不需要被其它包访问,用小写非导出的形式会不会更好些。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,我改一下

@codecov-commenter
Copy link

codecov-commenter commented Aug 22, 2023

Codecov Report

Attention: 21 lines in your changes are missing coverage. Please review.

Comparison is base (6f030cb) 37.28% compared to head (54e281f) 37.44%.

Files Patch % Lines
pkg/remoting/getty/getty_remoting.go 0.00% 13 Missing ⚠️
...g/remoting/loadbalance/least_active_loadbalance.go 80.64% 3 Missing and 3 partials ⚠️
pkg/remoting/loadbalance/loadbalance.go 0.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

@@ -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)
Copy link
Contributor

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

判断处理 err

@luky116 luky116 merged commit a875204 into apache:master Feb 3, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

在remoting模块中实现LeastActive负载均衡
7 participants