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

Client load report #1200

Merged
merged 26 commits into from Apr 27, 2017
Merged

Client load report #1200

merged 26 commits into from Apr 27, 2017

Conversation

menghanl
Copy link
Contributor

@menghanl menghanl commented Apr 25, 2017

This PR implements client load report for grpclb.

call.go Outdated
}
if put != nil {
put()
put = nil
Copy link
Member

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.)

Copy link
Contributor Author

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 {
Copy link
Member

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()
}

?

Copy link
Contributor Author

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 {
Copy link
Member

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)

Copy link
Contributor Author

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{
Copy link
Member

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)

Copy link
Contributor Author

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

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
}

Copy link
Contributor Author

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{
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

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++
Copy link
Member

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++.

Copy link
Contributor Author

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 {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@menghanl menghanl added 1.3 Type: Feature New features or improvements in behavior labels Apr 27, 2017
@menghanl menghanl merged commit 277e90a into grpc:master Apr 27, 2017
@menghanl menghanl deleted the client_load_report branch April 27, 2017 17:43
@lock lock bot locked as resolved and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Type: Feature New features or improvements in behavior
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants