Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nsqd: Make REQ timeout limit configurable Fixes #348 #352

Merged
merged 1 commit into from
May 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions apps/nsqd/nsqd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions contrib/nsqd.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 2 additions & 0 deletions nsqd/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a line to the default config file provided in the repository for this new option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

ClientTimeout time.Duration

// client overridable configuration options
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions nsqd/protocol_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down