Skip to content

Client load report#1200

Merged
menghanl merged 26 commits intogrpc:masterfrom
menghanl:client_load_report
Apr 27, 2017
Merged

Client load report#1200
menghanl merged 26 commits intogrpc:masterfrom
menghanl:client_load_report

Conversation

@menghanl
Copy link
Copy Markdown
Contributor

@menghanl menghanl commented Apr 25, 2017

This PR implements client load report for grpclb.

@menghanl menghanl requested review from MakMukhi and dfawley April 25, 2017 00:41
@menghanl menghanl force-pushed the client_load_report branch from 0f09abc to 18c603c Compare April 25, 2017 06:14
@menghanl menghanl force-pushed the client_load_report branch from 436fbcb to f41c688 Compare April 25, 2017 06:40
Comment thread call.go Outdated
}
if put != nil {
put()
put = nil
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment thread 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
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread call.go Outdated
put()
put = nil
}
if _, ok := err.(transport.ConnectionError); ok || err == transport.ErrStreamDrain {
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread call.go Outdated
}
return toRPCErr(err)
}
updateRPCStatsInContext(ctx, rpcStats{
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed.

Comment thread rpc_util.go Outdated
}

func updateRPCStatsInContext(ctx context.Context, s rpcStats) {
ss, ok := rpcStatsFromContext(ctx)
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread grpclb.go
b.clientStats = lbpb.ClientStats{} // Clear the stats.
b.mu.Unlock()
t := time.Now()
stats.Timestamp = &lbpb.Timestamp{
Copy link
Copy Markdown
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
Copy Markdown
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...

Comment thread grpclb.go
return
}
b.mu.Lock()
stats := b.clientStats
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread grpclb.go Outdated
seq := b.seq

defer func() {
if err == nil {
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread grpclb.go
if !opts.BlockingWait {
b.next = next
if a.dropForLoadBalancing {
b.clientStats.NumCallsFinished++
Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread rpc_util.go Outdated
return nil
}

type rpcStats struct {
Copy link
Copy Markdown
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
Copy Markdown
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.

2 participants