*: make dial timeout configurable

Dial timeout is set shorter because
1. etcd is supposed to work in good environment, and the new value is long
enough
2. shorter dial timeout makes dial fail faster, which is good for
performance
This commit is contained in:
Yicheng Qin 2015-02-12 22:23:10 -08:00
parent 55cd03ff4b
commit 2c94e2d771
5 changed files with 6 additions and 5 deletions

View File

@ -92,7 +92,7 @@ func startEtcd(cfg *config) (<-chan struct{}, error) {
log.Printf("no data-dir provided, using default data-dir ./%s", cfg.dir) log.Printf("no data-dir provided, using default data-dir ./%s", cfg.dir)
} }
pt, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout) pt, err := transport.NewTimeoutTransport(cfg.peerTLSInfo, rafthttp.DialTimeout, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -623,7 +623,7 @@ func mustNewHTTPClient(t *testing.T, eps []string) client.Client {
} }
func mustNewTransport(t *testing.T) *http.Transport { func mustNewTransport(t *testing.T) *http.Transport {
tr, err := transport.NewTimeoutTransport(transport.TLSInfo{}, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout) tr, err := transport.NewTimeoutTransport(transport.TLSInfo{}, rafthttp.DialTimeout, rafthttp.ConnReadTimeout, rafthttp.ConnWriteTimeout)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -23,14 +23,14 @@ import (
// NewTimeoutTransport returns a transport created using the given TLS info. // NewTimeoutTransport returns a transport created using the given TLS info.
// If read/write on the created connection blocks longer than its time limit, // If read/write on the created connection blocks longer than its time limit,
// it will return timeout error. // it will return timeout error.
func NewTimeoutTransport(info TLSInfo, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) { func NewTimeoutTransport(info TLSInfo, dialtimeoutd, rdtimeoutd, wtimeoutd time.Duration) (*http.Transport, error) {
tr, err := NewTransport(info) tr, err := NewTransport(info)
if err != nil { if err != nil {
return nil, err return nil, err
} }
tr.Dial = (&rwTimeoutDialer{ tr.Dial = (&rwTimeoutDialer{
Dialer: net.Dialer{ Dialer: net.Dialer{
Timeout: 30 * time.Second, Timeout: dialtimeoutd,
KeepAlive: 30 * time.Second, KeepAlive: 30 * time.Second,
}, },
rdtimeoutd: rdtimeoutd, rdtimeoutd: rdtimeoutd,

View File

@ -24,7 +24,7 @@ import (
// TestNewTimeoutTransport tests that NewTimeoutTransport returns a transport // TestNewTimeoutTransport tests that NewTimeoutTransport returns a transport
// that can dial out timeout connections. // that can dial out timeout connections.
func TestNewTimeoutTransport(t *testing.T) { func TestNewTimeoutTransport(t *testing.T) {
tr, err := NewTimeoutTransport(TLSInfo{}, time.Hour, time.Hour) tr, err := NewTimeoutTransport(TLSInfo{}, time.Hour, time.Hour, time.Hour)
if err != nil { if err != nil {
t.Fatalf("unexpected NewTimeoutTransport error: %v", err) t.Fatalf("unexpected NewTimeoutTransport error: %v", err)
} }

View File

@ -30,6 +30,7 @@ const (
appRespBatchMs = 50 appRespBatchMs = 50
propBatchMs = 10 propBatchMs = 10
DialTimeout = time.Second
ConnReadTimeout = 5 * time.Second ConnReadTimeout = 5 * time.Second
ConnWriteTimeout = 5 * time.Second ConnWriteTimeout = 5 * time.Second
) )