Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
2
22a7f0099
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Summer2022
22a7f0099
Commits
a97fa47c
Commit
a97fa47c
authored
5 years ago
by
zonghaishang
Browse files
Options
Downloads
Patches
Plain Diff
format code
parent
83409cab
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cluster/loadbalance/least_active.go
+11
-10
11 additions, 10 deletions
cluster/loadbalance/least_active.go
filter/impl/active_filter.go
+2
-2
2 additions, 2 deletions
filter/impl/active_filter.go
protocol/RpcStatus.go
+6
-3
6 additions, 3 deletions
protocol/RpcStatus.go
with
19 additions
and
15 deletions
cluster/loadbalance/least_active.go
+
11
−
10
View file @
a97fa47c
...
...
@@ -13,20 +13,22 @@
// @author yiji@apache.org
package
loadbalance
import
(
"math/rand"
)
import
(
"github.com/dubbo/go-for-apache-dubbo/cluster"
"github.com/dubbo/go-for-apache-dubbo/common/extension"
"github.com/dubbo/go-for-apache-dubbo/filter"
"github.com/dubbo/go-for-apache-dubbo/protocol"
"math/rand"
)
const
(
l
eastActive
=
"leastactive"
L
eastActive
=
"leastactive"
)
func
init
()
{
extension
.
SetLoadbalance
(
l
eastActive
,
NewLeastActiveLoadBalance
)
extension
.
SetLoadbalance
(
L
eastActive
,
NewLeastActiveLoadBalance
)
}
type
leastActiveLoadBalance
struct
{
...
...
@@ -37,9 +39,8 @@ func NewLeastActiveLoadBalance() cluster.LoadBalance {
}
func
(
lb
*
leastActiveLoadBalance
)
Select
(
invokers
[]
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Invoker
{
count
:=
len
(
invokers
)
if
invokers
==
nil
||
count
==
0
{
if
count
==
0
{
return
nil
}
if
count
==
1
{
...
...
@@ -48,17 +49,17 @@ func (lb *leastActiveLoadBalance) Select(invokers []protocol.Invoker, invocation
var
(
leastActive
int32
=
-
1
// The least active value of all invokers
totalWeight
int64
=
0
// The number of invokers having the same least active value (
leastActive
)
totalWeight
int64
=
0
// The number of invokers having the same least active value (
LEAST_ACTIVE
)
firstWeight
int64
=
0
// Initial value, used for comparision
leastIndexes
=
make
([]
int
,
count
)
// The index of invokers having the same least active value (
leastActive
)
leastCount
=
0
// The number of invokers having the same least active value (
leastActive
)
leastIndexes
=
make
([]
int
,
count
)
// The index of invokers having the same least active value (
LEAST_ACTIVE
)
leastCount
=
0
// The number of invokers having the same least active value (
LEAST_ACTIVE
)
sameWeight
=
true
// Every invoker has the same weight value?
)
for
i
:=
0
;
i
<
count
;
i
++
{
invoker
:=
invokers
[
i
]
// Active number
active
:=
filter
.
GetStatus
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
.
GetActive
()
active
:=
protocol
.
GetStatus
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
.
GetActive
()
// current weight (maybe in warmUp)
weight
:=
GetWeight
(
invoker
,
invocation
)
// There are smaller active services
...
...
This diff is collapsed.
Click to expand it.
filter/impl/active_filter.go
+
2
−
2
View file @
a97fa47c
...
...
@@ -35,13 +35,13 @@ type ActiveFilter struct {
func
(
ef
*
ActiveFilter
)
Invoke
(
invoker
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Result
{
logger
.
Infof
(
"invoking active filter. %v,%v"
,
invocation
.
MethodName
(),
len
(
invocation
.
Arguments
()))
filter
.
BeginCount
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
protocol
.
BeginCount
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
return
invoker
.
Invoke
(
invocation
)
}
func
(
ef
*
ActiveFilter
)
OnResponse
(
result
protocol
.
Result
,
invoker
protocol
.
Invoker
,
invocation
protocol
.
Invocation
)
protocol
.
Result
{
filter
.
EndCount
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
protocol
.
EndCount
(
invoker
.
GetUrl
(),
invocation
.
MethodName
())
return
result
}
...
...
This diff is collapsed.
Click to expand it.
filter
/RpcStatus.go
→
protocol
/RpcStatus.go
+
6
−
3
View file @
a97fa47c
...
...
@@ -11,16 +11,19 @@
// limitations under the License.
// @author yiji@apache.org
package
filter
package
protocol
import
(
"github.com/dubbo/go-for-apache-dubbo/common"
"sync"
"sync/atomic"
)
import
(
"github.com/dubbo/go-for-apache-dubbo/common"
)
var
(
methodStatistics
=
sync
.
Map
{}
// url -> { methodName : RpcStatus}
methodStatistics
sync
.
Map
// url -> { methodName : RpcStatus}
)
type
RpcStatus
struct
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment