From cbd8a4fb9c97950c7b4d7bbc6e60bd5e64746144 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Thu, 26 Sep 2013 10:40:33 -0700 Subject: [PATCH 1/2] feat(scripts/test-cluster): add a cluster test command this uses tmux to setup a test cluster that you can easily kill and start for debugging. --- .gitignore | 1 + scripts/test-cluster | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 scripts/test-cluster diff --git a/.gitignore b/.gitignore index 8459ca713..d00d899e2 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ src/ pkg/ /etcd release_version.go +/machine* diff --git a/scripts/test-cluster b/scripts/test-cluster new file mode 100755 index 000000000..ccdedd1b7 --- /dev/null +++ b/scripts/test-cluster @@ -0,0 +1,19 @@ +#!/bin/bash +SESSION=etcd-cluster + +tmux new-session -d -s $SESSION + +# Setup a window for tailing log files +tmux new-window -t $SESSION:1 -n 'machines' +tmux split-window -h +tmux select-pane -t 0 +tmux send-keys "./etcd -s 127.0.0.1:7001 -c 127.0.0.1:4001 -d machine1 -n machine1" C-m + +for i in 2 3; do + tmux select-pane -t 0 + tmux split-window -v + tmux send-keys "./etcd -cors='*' -s 127.0.0.1:700${i} -c 127.0.0.1:400${i} -C 127.0.0.1:7001 -d machine${i} -n machine${i}" C-m +done + +# Attach to session +tmux attach-session -t $SESSION From da01fe602774341353b8eebeff0f1c845dc80eb3 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Thu, 26 Sep 2013 12:17:54 -0700 Subject: [PATCH 2/2] fix(command): make Latency and Counts objects instead of suffixing everything make a latency object --- command.go | 3 ++- raft_stats.go | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 27 insertions(+), 21 deletions(-) diff --git a/command.go b/command.go index dc0684707..a469a53fd 100644 --- a/command.go +++ b/command.go @@ -172,7 +172,8 @@ func (c *JoinCommand) Apply(raftServer *raft.Server) (interface{}, error) { // add peer stats if c.Name != r.Name() { - r.peersStats.Peers[c.Name] = &raftPeerStats{MinLatency: 1 << 63} + r.peersStats.Peers[c.Name] = &raftPeerStats{} + r.peersStats.Peers[c.Name].Latency.Minimum = 1 << 63 } return b, err diff --git a/raft_stats.go b/raft_stats.go index 439c14ce9..f17945ea6 100644 --- a/raft_stats.go +++ b/raft_stats.go @@ -85,43 +85,48 @@ type raftPeersStats struct { } type raftPeerStats struct { - Latency float64 `json:"latency"` - AvgLatency float64 `json:"averageLatency"` - avgLatencySquare float64 - SdvLatency float64 `json:"sdvLatency"` - MinLatency float64 `json:"minLatency"` - MaxLatency float64 `json:"maxLatency"` - FailCnt uint64 `json:"failsCount"` - SuccCnt uint64 `json:"successCount"` + Latency struct { + Current float64 `json:"current"` + Average float64 `json:"average"` + averageSquare float64 + StandardDeviation float64 `json:"standardDeviation"` + Minimum float64 `json:"minimum"` + Maximum float64 `json:"maximum"` + } `json:"latency"` + + Counts struct { + Fail uint64 `json:"fail"` + Success uint64 `json:"success"` + } `json:"counts"` } // Succ function update the raftPeerStats with a successful send func (ps *raftPeerStats) Succ(d time.Duration) { - total := float64(ps.SuccCnt) * ps.AvgLatency - totalSquare := float64(ps.SuccCnt) * ps.avgLatencySquare + total := float64(ps.Counts.Success) * ps.Latency.Average + totalSquare := float64(ps.Counts.Success) * ps.Latency.averageSquare - ps.SuccCnt++ + ps.Counts.Success++ - ps.Latency = float64(d) / (1000000.0) + ps.Latency.Current = float64(d) / (1000000.0) - if ps.Latency > ps.MaxLatency { - ps.MaxLatency = ps.Latency + if ps.Latency.Current > ps.Latency.Maximum { + ps.Latency.Maximum = ps.Latency.Current } - if ps.Latency < ps.MinLatency { - ps.MinLatency = ps.Latency + if ps.Latency.Current < ps.Latency.Minimum { + ps.Latency.Minimum = ps.Latency.Current } - ps.AvgLatency = (total + ps.Latency) / float64(ps.SuccCnt) - ps.avgLatencySquare = (totalSquare + ps.Latency*ps.Latency) / float64(ps.SuccCnt) + ps.Latency.Average = (total + ps.Latency.Current) / float64(ps.Counts.Success) + ps.Latency.averageSquare = (totalSquare + ps.Latency.Current * ps.Latency.Current) / float64(ps.Counts.Success) // sdv = sqrt(avg(x^2) - avg(x)^2) - ps.SdvLatency = math.Sqrt(ps.avgLatencySquare - ps.AvgLatency*ps.AvgLatency) + ps.Latency.StandardDeviation = math.Sqrt(ps.Latency.averageSquare - ps.Latency.Average*ps.Latency.Average) } // Fail function update the raftPeerStats with a unsuccessful send func (ps *raftPeerStats) Fail() { - ps.FailCnt++ + ps.Counts.Fail++ } type statsQueue struct {