Skip to content

Commit

Permalink
etcdserver: improve request took too long warning
Browse files Browse the repository at this point in the history
  • Loading branch information
xiang90 authored and jpbetz committed Jun 12, 2018
1 parent fd61be4 commit df000fd
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
2 changes: 2 additions & 0 deletions etcdserver/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func (s *EtcdServer) newApplierV3() applierV3 {
}

func (a *applierV3backend) Apply(r *pb.InternalRaftRequest) *applyResult {
defer warnOfExpensiveRequest(time.Now(), r)

ar := &applyResult{}

// call into a.s.applyV3.F instead of a.F so upper appliers can check individual calls
Expand Down
2 changes: 2 additions & 0 deletions etcdserver/apply_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ func (a *applierV2store) Sync(r *pb.Request) Response {
// applyV2Request interprets r as a call to store.X and returns a Response interpreted
// from store.Event
func (s *EtcdServer) applyV2Request(r *pb.Request) Response {
defer warnOfExpensiveRequest(time.Now(), r)
toTTLOptions(r)

switch r.Method {
case "POST":
return s.applyV2.Post(r)
Expand Down
8 changes: 1 addition & 7 deletions etcdserver/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,14 +800,8 @@ func (s *EtcdServer) run() {

func (s *EtcdServer) applyAll(ep *etcdProgress, apply *apply) {
s.applySnapshot(ep, apply)
st := time.Now()
s.applyEntries(ep, apply)
d := time.Since(st)
entriesNum := len(apply.entries)
if entriesNum != 0 && d > time.Duration(entriesNum)*warnApplyDuration {
plog.Warningf("apply entries took too long [%v for %d entries]", d, len(apply.entries))
plog.Warningf("avoid queries with large range/delete range!")
}

proposalsApplied.Set(float64(ep.appliedi))
s.applyWait.Trigger(ep.appliedi)
// wait for the raft routine to finish the disk writes before triggering a
Expand Down
17 changes: 17 additions & 0 deletions etcdserver/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package etcdserver

import (
"fmt"
"time"

"github.com/coreos/etcd/etcdserver/membership"
Expand Down Expand Up @@ -95,3 +96,19 @@ func (nc *notifier) notify(err error) {
nc.err = err
close(nc.c)
}

func warnOfExpensiveRequest(now time.Time, stringer fmt.Stringer) {
warnOfExpensiveGenericRequest(now, stringer, "")
}

func warnOfExpensiveReadOnlyRangeRequest(now time.Time, stringer fmt.Stringer) {
warnOfExpensiveGenericRequest(now, stringer, "read-only range ")
}

func warnOfExpensiveGenericRequest(now time.Time, stringer fmt.Stringer, prefix string) {
// TODO: add metrics
d := time.Since(now)
if d > warnApplyDuration {
plog.Warningf("%srequest %q took too long (%v) to execute", prefix, stringer.String(), d)
}
}
5 changes: 5 additions & 0 deletions etcdserver/v2_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,8 @@ func (s *EtcdServer) Do(ctx context.Context, r pb.Request) (Response, error) {
}
return Response{}, ErrUnknownMethod
}

func (r *RequestV2) String() string {
rpb := pb.Request(*r)
return rpb.String()
}
5 changes: 5 additions & 0 deletions etcdserver/v3_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeRe
if s.ClusterVersion() == nil || s.ClusterVersion().LessThan(newRangeClusterVersion) {
return s.legacyRange(ctx, r)
}
defer warnOfExpensiveReadOnlyRangeRequest(time.Now(), r)

if !r.Serializable {
err := s.linearizableReadNotify(ctx)
Expand All @@ -108,6 +109,7 @@ func (s *EtcdServer) Range(ctx context.Context, r *pb.RangeRequest) (*pb.RangeRe
return s.authStore.IsRangePermitted(ai, r.Key, r.RangeEnd)
}
get := func() { resp, err = s.applyV3Base.Range(noTxn, r) }
get := func() { resp, err = s.applyV3Base.Range(nil, r) }
if serr := s.doSerialize(ctx, chk, get); serr != nil {
return nil, serr
}
Expand Down Expand Up @@ -178,6 +180,9 @@ func (s *EtcdServer) Txn(ctx context.Context, r *pb.TxnRequest) (*pb.TxnResponse
chk := func(ai *auth.AuthInfo) error {
return checkTxnAuth(s.authStore, ai, r)
}

defer warnOfExpensiveReadOnlyRangeRequest(time.Now(), r)

get := func() { resp, err = s.applyV3Base.Txn(r) }
if serr := s.doSerialize(ctx, chk, get); serr != nil {
return nil, serr
Expand Down

0 comments on commit df000fd

Please sign in to comment.