From a32af8d43c10726cf8f3baa62c1343328e338605 Mon Sep 17 00:00:00 2001 From: Mikhail Salosin Date: Fri, 23 May 2014 17:54:22 +0400 Subject: [PATCH] nsqd: Make REQ timeout limit configurable --- apps/nsqd/nsqd.go | 1 + contrib/nsqd.cfg.example | 3 +++ nsqd/options.go | 2 ++ nsqd/protocol_v2.go | 6 ++---- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/nsqd/nsqd.go b/apps/nsqd/nsqd.go index ca09a47df..92ed91d04 100644 --- a/apps/nsqd/nsqd.go +++ b/apps/nsqd/nsqd.go @@ -41,6 +41,7 @@ var ( msgTimeout = flagSet.String("msg-timeout", "60s", "duration to wait before auto-requeing a message") maxMsgTimeout = flagSet.Duration("max-msg-timeout", 15*time.Minute, "maximum duration before a message will timeout") maxMsgSize = flagSet.Int64("max-msg-size", 1024768, "maximum size of a single message in bytes") + maxReqTimeout = flagSet.Duration("max-req-timeout", 1*time.Hour, "maximum requeuing timeout for a message") // remove, deprecated maxMessageSize = flagSet.Int64("max-message-size", 1024768, "(deprecated use --max-msg-size) maximum size of a single message in bytes") maxBodySize = flagSet.Int64("max-body-size", 5*1024768, "maximum size of a single command body") diff --git a/contrib/nsqd.cfg.example b/contrib/nsqd.cfg.example index 4ebe508ef..c3d156a11 100644 --- a/contrib/nsqd.cfg.example +++ b/contrib/nsqd.cfg.example @@ -47,6 +47,9 @@ max_msg_timeout = "15m" ## maximum size of a single message in bytes max_msg_size = 1024768 +## maximum requeuing timeout for a message +max_req_timeout = "1h" + ## maximum size of a single command body max_body_size = 5123840 diff --git a/nsqd/options.go b/nsqd/options.go index f974d38b9..e595a0bd0 100644 --- a/nsqd/options.go +++ b/nsqd/options.go @@ -31,6 +31,7 @@ type nsqdOptions struct { MaxMsgTimeout time.Duration `flag:"max-msg-timeout"` MaxMsgSize int64 `flag:"max-msg-size" deprecated:"max-message-size" cfg:"max_msg_size"` MaxBodySize int64 `flag:"max-body-size"` + MaxReqTimeout time.Duration `flag:"max-req-timeout"` ClientTimeout time.Duration // client overridable configuration options @@ -83,6 +84,7 @@ func NewNSQDOptions() *nsqdOptions { MaxMsgTimeout: 15 * time.Minute, MaxMsgSize: 1024768, MaxBodySize: 5 * 1024768, + MaxReqTimeout: 1 * time.Hour, ClientTimeout: 60 * time.Second, MaxHeartbeatInterval: 60 * time.Second, diff --git a/nsqd/protocol_v2.go b/nsqd/protocol_v2.go index 273afcd93..0bc5127b2 100644 --- a/nsqd/protocol_v2.go +++ b/nsqd/protocol_v2.go @@ -18,8 +18,6 @@ import ( "github.com/bitly/nsq/util" ) -const maxTimeout = time.Hour - var separatorBytes = []byte(" ") var heartbeatBytes = []byte("_heartbeat_") var okBytes = []byte("OK") @@ -557,9 +555,9 @@ func (p *protocolV2) REQ(client *clientV2, params [][]byte) ([]byte, error) { } timeoutDuration := time.Duration(timeoutMs) * time.Millisecond - if timeoutDuration < 0 || timeoutDuration > maxTimeout { + if timeoutDuration < 0 || timeoutDuration > p.context.nsqd.options.MaxReqTimeout { return nil, util.NewFatalClientErr(nil, "E_INVALID", - fmt.Sprintf("REQ timeout %d out of range 0-%d", timeoutDuration, maxTimeout)) + fmt.Sprintf("REQ timeout %d out of range 0-%d", timeoutDuration, p.context.nsqd.options.MaxReqTimeout)) } err = client.Channel.RequeueMessage(client.ID, id, timeoutDuration)