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
Client load report #1200
Client load report #1200
Conversation
Before moving grpclb into grpc package. This reverts commit 3c582a8.
0f09abc
to
18c603c
Compare
436fbcb
to
f41c688
Compare
call.go
Outdated
} | ||
if put != nil { | ||
put() | ||
put = nil |
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.
Why nil out put? Unless I'm reading it wrong, it's local to this loop, and we either return or continue after this.
(Same below.)
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.
Removed.
call.go
Outdated
stream, err = sendRequest(ctx, cc.dopts, cc.dopts.cp, callHdr, t, args, topts) | ||
stream, err = t.NewStream(ctx, callHdr) | ||
if err != nil { | ||
if _, ok := err.(transport.ConnectionError); ok && put != nil { |
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.
Maybe combine the ifs here:
if put != nil {
if _, ok := err.(transport.ConnectionError); ok {
updateRPCStats()
}
put()
}
?
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.
Done
call.go
Outdated
put() | ||
put = nil | ||
} | ||
if _, ok := err.(transport.ConnectionError); ok || err == transport.ErrStreamDrain { |
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.
How about:
if _, ok := err.(transport.ConnectionError); (ok || err == transport.ErrStreamDrain) && !c.failFast {
continue
}
return toRPCErr(err)
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.
Done
call.go
Outdated
@@ -277,11 +302,19 @@ func invoke(ctx context.Context, method string, args, reply interface{}, cc *Cli | |||
} | |||
return toRPCErr(err) | |||
} | |||
updateRPCStatsInContext(ctx, rpcStats{ |
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.
Why is this update here? Presumably nobody will care about the stats until put is called. (It's also not guarded by a put != nil
)
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.
Removed.
rpc_util.go
Outdated
} | ||
|
||
func updateRPCStatsInContext(ctx context.Context, s rpcStats) { | ||
ss, ok := rpcStatsFromContext(ctx) |
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.
if ss, ok := rpcStatsFromContext(ctx); ok {
*ss = s
}
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.
Done
b.clientStats = lbpb.ClientStats{} // Clear the stats. | ||
b.mu.Unlock() | ||
t := time.Now() | ||
stats.Timestamp = &lbpb.Timestamp{ |
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.
FYI: there's a helper in ptypes for setting Timestamp messages. It would probably be best to use that.
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.
The timestamp here is a copy of the ptypes Timestamp...
return | ||
} | ||
b.mu.Lock() | ||
stats := b.clientStats |
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.
This makes an unnecessary copy. You could instead use b.clientStats directly and clear it after calling Send.
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.
b.clientStats is protected by the mutex. I don't want to put the rpc call between the lock/unlock.
grpclb.go
Outdated
seq := b.seq | ||
|
||
defer func() { | ||
if err == nil { |
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.
Preferred go-ism:
if err != nil {
return
}
And outdent the following code.
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.
Done
@@ -556,6 +618,13 @@ func (b *balancer) Get(ctx context.Context, opts BalancerGetOptions) (addr Addre | |||
} | |||
if !opts.BlockingWait { | |||
b.next = next | |||
if a.dropForLoadBalancing { | |||
b.clientStats.NumCallsFinished++ |
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.
Optional: in the defer, if err != nil, do this b.clientStats.NumCallsFinished++
.
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.
In that case, these two values will not be protected by the same pair of lock/unlock.
rpc_util.go
Outdated
@@ -345,6 +345,30 @@ func recv(p *parser, c Codec, s *transport.Stream, dc Decompressor, m interface{ | |||
return nil | |||
} | |||
|
|||
type rpcStats struct { |
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.
How about rpcInfo instead? Stats makes me think there are metrics inside. Combine "stats" with bytesSent/Received, and I expect those to be ints instead of bools.
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.
Done
This PR implements client load report for grpclb.