Merge pull request #624 from unihorn/36

chore(server/transporter): set RequestTimout reasonable
This commit is contained in:
Yicheng Qin 2014-04-17 15:19:10 -07:00
commit b0ac8a4b4b
3 changed files with 17 additions and 10 deletions

View File

@ -4,6 +4,7 @@ import (
"flag" "flag"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"math/rand"
"net" "net"
"net/url" "net/url"
"os" "os"
@ -11,6 +12,7 @@ import (
"reflect" "reflect"
"strconv" "strconv"
"strings" "strings"
"time"
"github.com/coreos/etcd/third_party/github.com/BurntSushi/toml" "github.com/coreos/etcd/third_party/github.com/BurntSushi/toml"
@ -98,6 +100,9 @@ func New() *Config {
c.Peer.Addr = "127.0.0.1:7001" c.Peer.Addr = "127.0.0.1:7001"
c.Peer.HeartbeatInterval = defaultHeartbeatInterval c.Peer.HeartbeatInterval = defaultHeartbeatInterval
c.Peer.ElectionTimeout = defaultElectionTimeout c.Peer.ElectionTimeout = defaultElectionTimeout
rand.Seed(time.Now().UTC().UnixNano())
// Make maximum twice as minimum.
c.RetryInterval = float64(50+rand.Int()%50) * defaultHeartbeatInterval / 1000
return c return c
} }

View File

@ -134,8 +134,14 @@ func (e *Etcd) Run() {
// Calculate all of our timeouts // Calculate all of our timeouts
heartbeatInterval := time.Duration(e.Config.Peer.HeartbeatInterval) * time.Millisecond heartbeatInterval := time.Duration(e.Config.Peer.HeartbeatInterval) * time.Millisecond
electionTimeout := time.Duration(e.Config.Peer.ElectionTimeout) * time.Millisecond electionTimeout := time.Duration(e.Config.Peer.ElectionTimeout) * time.Millisecond
dialTimeout := (3 * heartbeatInterval) + electionTimeout // TODO(yichengq): constant 1000 is a hack here. The reason to use this
responseHeaderTimeout := (3 * heartbeatInterval) + electionTimeout // is to ensure etcd instances could start successfully at the same time.
// Current problem for the failure comes from the lag between join command
// execution and join success.
// Fix it later. It should be removed when proper method is found and
// enough tests are provided.
dialTimeout := (3 * heartbeatInterval) + electionTimeout + 1000
responseHeaderTimeout := (3 * heartbeatInterval) + electionTimeout + 1000
// Create peer server // Create peer server
psConfig := server.PeerServerConfig{ psConfig := server.PeerServerConfig{

View File

@ -20,7 +20,6 @@ const (
// Transporter layer for communication between raft nodes // Transporter layer for communication between raft nodes
type transporter struct { type transporter struct {
requestTimeout time.Duration
followersStats *raftFollowersStats followersStats *raftFollowersStats
serverStats *raftServerStats serverStats *raftServerStats
registry *Registry registry *Registry
@ -43,9 +42,8 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
// HTTPS connections blocked. The patch for it is in progress, // HTTPS connections blocked. The patch for it is in progress,
// and would be available in Go1.3 // and would be available in Go1.3
// More: https://codereview.appspot.com/69280043/ // More: https://codereview.appspot.com/69280043/
ConnectTimeout: dialTimeout, ConnectTimeout: dialTimeout,
RequestTimeout: dialTimeout + responseHeaderTimeout, RequestTimeout: requestTimeout,
ReadWriteTimeout: responseHeaderTimeout,
} }
// Sending snapshot might take a long time so we use a different HTTP transporter // Sending snapshot might take a long time so we use a different HTTP transporter
@ -55,9 +53,8 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
// average RTT. // average RTT.
// It should be equal to (TCP max window size/RTT). // It should be equal to (TCP max window size/RTT).
sTr := &httpclient.Transport{ sTr := &httpclient.Transport{
ConnectTimeout: dialTimeout, ConnectTimeout: dialTimeout,
RequestTimeout: snapshotTimeout, RequestTimeout: snapshotTimeout,
ReadWriteTimeout: snapshotTimeout,
} }
t := transporter{ t := transporter{
@ -65,7 +62,6 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
transport: tr, transport: tr,
snapshotClient: &http.Client{Transport: sTr}, snapshotClient: &http.Client{Transport: sTr},
snapshotTransport: sTr, snapshotTransport: sTr,
requestTimeout: requestTimeout,
followersStats: followersStats, followersStats: followersStats,
serverStats: serverStats, serverStats: serverStats,
registry: registry, registry: registry,