mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Merge pull request #624 from unihorn/36
chore(server/transporter): set RequestTimout reasonable
This commit is contained in:
commit
b0ac8a4b4b
@ -4,6 +4,7 @@ import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
@ -11,6 +12,7 @@ import (
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"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.HeartbeatInterval = defaultHeartbeatInterval
|
||||
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
|
||||
}
|
||||
|
||||
|
10
etcd/etcd.go
10
etcd/etcd.go
@ -134,8 +134,14 @@ func (e *Etcd) Run() {
|
||||
// Calculate all of our timeouts
|
||||
heartbeatInterval := time.Duration(e.Config.Peer.HeartbeatInterval) * time.Millisecond
|
||||
electionTimeout := time.Duration(e.Config.Peer.ElectionTimeout) * time.Millisecond
|
||||
dialTimeout := (3 * heartbeatInterval) + electionTimeout
|
||||
responseHeaderTimeout := (3 * heartbeatInterval) + electionTimeout
|
||||
// TODO(yichengq): constant 1000 is a hack here. The reason to use this
|
||||
// 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
|
||||
psConfig := server.PeerServerConfig{
|
||||
|
@ -20,7 +20,6 @@ const (
|
||||
|
||||
// Transporter layer for communication between raft nodes
|
||||
type transporter struct {
|
||||
requestTimeout time.Duration
|
||||
followersStats *raftFollowersStats
|
||||
serverStats *raftServerStats
|
||||
registry *Registry
|
||||
@ -44,8 +43,7 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
|
||||
// and would be available in Go1.3
|
||||
// More: https://codereview.appspot.com/69280043/
|
||||
ConnectTimeout: dialTimeout,
|
||||
RequestTimeout: dialTimeout + responseHeaderTimeout,
|
||||
ReadWriteTimeout: responseHeaderTimeout,
|
||||
RequestTimeout: requestTimeout,
|
||||
}
|
||||
|
||||
// Sending snapshot might take a long time so we use a different HTTP transporter
|
||||
@ -57,7 +55,6 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
|
||||
sTr := &httpclient.Transport{
|
||||
ConnectTimeout: dialTimeout,
|
||||
RequestTimeout: snapshotTimeout,
|
||||
ReadWriteTimeout: snapshotTimeout,
|
||||
}
|
||||
|
||||
t := transporter{
|
||||
@ -65,7 +62,6 @@ func NewTransporter(followersStats *raftFollowersStats, serverStats *raftServerS
|
||||
transport: tr,
|
||||
snapshotClient: &http.Client{Transport: sTr},
|
||||
snapshotTransport: sTr,
|
||||
requestTimeout: requestTimeout,
|
||||
followersStats: followersStats,
|
||||
serverStats: serverStats,
|
||||
registry: registry,
|
||||
|
Loading…
x
Reference in New Issue
Block a user