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

[feat] supprt search total instances and global instance option #14

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v2
with:
version: v1.48.0
version: v1.55.2
args: --timeout=5m --skip-dirs='test,examples' --enable gofmt,golint,gocyclo,goimports --skip-files=.*_test.go$
52 changes: 29 additions & 23 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,24 @@ type OpOptions struct {
Action Action
Key []byte
// EndKey must be lexicographically greater than Key.
EndKey []byte
Value []byte
Prefix bool
PrevKV bool
Lease int64
KeyOnly bool
CountOnly bool
OrderBy SortTarget
SortOrder SortOrder
Revision int64
IgnoreLease bool
Mode CacheMode
WatchCallback WatchCallback
Offset int64
Limit int64
Global bool
EndKey []byte
Value []byte
Prefix bool
PrevKV bool
Lease int64
KeyOnly bool
CountOnly bool
OrderBy SortTarget
SortOrder SortOrder
Revision int64
IgnoreLease bool
Mode CacheMode
WatchCallback WatchCallback
Offset int64
Limit int64
Global bool
GlobalInstanceSearch bool
InstanceSearch bool
}

func (op OpOptions) String() string {
Expand Down Expand Up @@ -131,13 +133,17 @@ func WithLease(leaseID int64) OpOption { return func(op *OpOptions) { op.Lease =
func WithKeyOnly() OpOption { return func(op *OpOptions) { op.KeyOnly = true } }
func WithCountOnly() OpOption { return func(op *OpOptions) { op.CountOnly = true } }
func WithGlobal() OpOption { return func(op *OpOptions) { op.Global = true } }
func WithNoneOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortNone } }
func WithAscendOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortAscend } }
func WithDescendOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortDescend } }
func WithRev(revision int64) OpOption { return func(op *OpOptions) { op.Revision = revision } }
func WithIgnoreLease() OpOption { return func(op *OpOptions) { op.IgnoreLease = true } }
func WithCacheOnly() OpOption { return func(op *OpOptions) { op.Mode = ModeCache } }
func WithNoCache() OpOption { return func(op *OpOptions) { op.Mode = ModeNoCache } }
func WithGlobalInstanceSearch() OpOption {
Copy link
Collaborator

Choose a reason for hiding this comment

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

说明清楚设计意图

Copy link
Contributor Author

Choose a reason for hiding this comment

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

2w实例下需要优化servicecomb-center注册微服务实例接口性能,经分析,注册实例接口性能主要卡在用递归算法计算当前已使用实例数,优化思路是在cache里维护已注册的所有实例数(包含全局实例数【sc自己】),获取已注册实例数需要用所有实例数-全局实例数,但是全局实例数较难维护,且全局实例数一般数量很少,计算它的实例数用递归也没有什么性能损耗,所以在cache只维护一个count变量表示所有实例数,用这两个选项表示到cache查的是所有注册实例数还是全局实例数。

Copy link

@chengyouling chengyouling Mar 14, 2024

Choose a reason for hiding this comment

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

SC的实例数不是在初始化或者扩容等阶段就固定了吗?SC的实例考虑初始化的时候设定即可,主要是用原子计数考虑微服务实例数,感觉你说的有点复杂啊。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这里的实例数指的是注册到引擎的微服务实例数,需要实时维护

return func(op *OpOptions) { op.GlobalInstanceSearch = true }
}
func WithInstanceSearch() OpOption { return func(op *OpOptions) { op.InstanceSearch = true } }
func WithNoneOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortNone } }
func WithAscendOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortAscend } }
func WithDescendOrder() OpOption { return func(op *OpOptions) { op.SortOrder = SortDescend } }
func WithRev(revision int64) OpOption { return func(op *OpOptions) { op.Revision = revision } }
func WithIgnoreLease() OpOption { return func(op *OpOptions) { op.IgnoreLease = true } }
func WithCacheOnly() OpOption { return func(op *OpOptions) { op.Mode = ModeCache } }
func WithNoCache() OpOption { return func(op *OpOptions) { op.Mode = ModeNoCache } }
func WithWatchCallback(f WatchCallback) OpOption {
return func(op *OpOptions) { op.WatchCallback = f }
}
Expand Down
Loading