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

rafthttp: add Raft send latency metric for writes #10023

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions etcdserver/api/rafthttp/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,19 @@ var (
[]string{"From"},
)

raftSendSeconds = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "etcd",
Subsystem: "network",
Name: "raft_send_total_duration_seconds",
Help: "Total latency distributions of Raft message sends",

// lowest bucket start of upper bound 0.0001 sec (0.1 ms) with factor 2
// highest bucket start of 0.0001 sec * 2^15 == 3.2768 sec
Buckets: prometheus.ExponentialBuckets(0.0001, 2, 16),
},
[]string{"Type", "To"},
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean []string{"To"}?

)

rttSec = prometheus.NewHistogramVec(prometheus.HistogramOpts{
Namespace: "etcd",
Subsystem: "network",
Expand Down Expand Up @@ -162,5 +175,6 @@ func init() {
prometheus.MustRegister(snapshotReceiveFailures)
prometheus.MustRegister(snapshotReceiveSeconds)

prometheus.MustRegister(raftSendSeconds)
prometheus.MustRegister(rttSec)
}
5 changes: 2 additions & 3 deletions etcdserver/api/rafthttp/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ func (p *pipeline) handle() {
case m := <-p.msgc:
start := time.Now()
err := p.post(pbutil.MustMarshal(&m))
end := time.Now()

if err != nil {
p.status.deactivate(failureType{source: pipelineMsg, action: "write"}, err.Error())

Expand All @@ -117,9 +115,10 @@ func (p *pipeline) handle() {
continue
}

took := time.Since(start)
p.status.activate()
if m.Type == raftpb.MsgApp && p.followerStats != nil {
p.followerStats.Succ(end.Sub(start))
p.followerStats.Succ(took)
}
if isMsgSnap(m) {
p.raft.ReportSnapshot(m.To, raft.SnapshotFinish)
Expand Down
10 changes: 10 additions & 0 deletions etcdserver/api/rafthttp/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ func (cw *streamWriter) run() {
heartbeatc, msgc = nil, nil

case m := <-msgc:
start := time.Now()
err := enc.encode(&m)
if err == nil {
took := time.Since(start)
unflushed += m.Size()

if len(msgc) == 0 || batched > streamBufSize/2 {
Expand All @@ -214,6 +216,14 @@ func (cw *streamWriter) run() {
batched++
}

// snapshot sends are tracked via separate metrics https://github.com/etcd-io/etcd/pull/9997
// heartbeats are tracked via prober https://github.com/etcd-io/etcd/pull/10022
// TODO: track other messages?
if m.Type == raftpb.MsgProp ||
Copy link
Contributor

Choose a reason for hiding this comment

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

this is not the sending time (flushing the buffer to the network card). we actually send the messages at line 211 when flush is called explicitly.

Copy link
Contributor

Choose a reason for hiding this comment

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

i would rather just remove this metrics. it is not easy to measure after all with buffers all over the places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xiang90 Good point. For now, tracking snapshots and heartbeats is good enough. Will come back to this later.

m.Type == raftpb.MsgApp ||
m.Type == raftpb.MsgAppResp {
raftSendSeconds.WithLabelValues(m.Type.String(), types.ID(m.To).String()).Observe(took.Seconds())
}
continue
}

Expand Down