-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
Copy pathoptions.go
182 lines (151 loc) · 5.98 KB
/
options.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
package nsqd
import (
"crypto/md5"
"crypto/tls"
"hash/crc32"
"io"
"log"
"os"
"time"
"github.com/nsqio/nsq/internal/lg"
)
type Options struct {
// basic options
ID int64 `flag:"node-id" cfg:"id"`
LogLevel lg.LogLevel `flag:"log-level"`
LogPrefix string `flag:"log-prefix"`
Logger Logger
TCPAddress string `flag:"tcp-address"`
HTTPAddress string `flag:"http-address"`
HTTPSAddress string `flag:"https-address"`
BroadcastAddress string `flag:"broadcast-address"`
BroadcastTCPPort int `flag:"broadcast-tcp-port"`
BroadcastHTTPPort int `flag:"broadcast-http-port"`
NSQLookupdTCPAddresses []string `flag:"lookupd-tcp-address" cfg:"nsqlookupd_tcp_addresses"`
AuthHTTPAddresses []string `flag:"auth-http-address" cfg:"auth_http_addresses"`
AuthHTTPRequestMethod string `flag:"auth-http-request-method" cfg:"auth_http_request_method"`
HTTPClientConnectTimeout time.Duration `flag:"http-client-connect-timeout" cfg:"http_client_connect_timeout"`
HTTPClientRequestTimeout time.Duration `flag:"http-client-request-timeout" cfg:"http_client_request_timeout"`
TopologyRegion string `flag:"topology-region"`
TopologyZone string `flag:"topology-zone"`
// diskqueue options
DataPath string `flag:"data-path"`
MemQueueSize int64 `flag:"mem-queue-size"`
MaxBytesPerFile int64 `flag:"max-bytes-per-file"`
SyncEvery int64 `flag:"sync-every"`
SyncTimeout time.Duration `flag:"sync-timeout"`
QueueScanInterval time.Duration
QueueScanRefreshInterval time.Duration
QueueScanSelectionCount int `flag:"queue-scan-selection-count"`
QueueScanWorkerPoolMax int `flag:"queue-scan-worker-pool-max"`
QueueScanDirtyPercent float64
// msg and command options
MsgTimeout time.Duration `flag:"msg-timeout"`
MaxMsgTimeout time.Duration `flag:"max-msg-timeout"`
MaxMsgSize int64 `flag:"max-msg-size"`
MaxBodySize int64 `flag:"max-body-size"`
MaxReqTimeout time.Duration `flag:"max-req-timeout"`
ClientTimeout time.Duration
// client overridable configuration options
MaxHeartbeatInterval time.Duration `flag:"max-heartbeat-interval"`
MaxRdyCount int64 `flag:"max-rdy-count"`
MaxOutputBufferSize int64 `flag:"max-output-buffer-size"`
MaxOutputBufferTimeout time.Duration `flag:"max-output-buffer-timeout"`
MinOutputBufferTimeout time.Duration `flag:"min-output-buffer-timeout"`
OutputBufferTimeout time.Duration `flag:"output-buffer-timeout"`
MaxChannelConsumers int `flag:"max-channel-consumers"`
// statsd integration
StatsdAddress string `flag:"statsd-address"`
StatsdPrefix string `flag:"statsd-prefix"`
StatsdInterval time.Duration `flag:"statsd-interval"`
StatsdMemStats bool `flag:"statsd-mem-stats"`
StatsdUDPPacketSize int `flag:"statsd-udp-packet-size"`
StatsdExcludeEphemeral bool `flag:"statsd-exclude-ephemeral"`
// e2e message latency
E2EProcessingLatencyWindowTime time.Duration `flag:"e2e-processing-latency-window-time"`
E2EProcessingLatencyPercentiles []float64 `flag:"e2e-processing-latency-percentile" cfg:"e2e_processing_latency_percentiles"`
// TLS config
TLSCert string `flag:"tls-cert"`
TLSKey string `flag:"tls-key"`
TLSClientAuthPolicy string `flag:"tls-client-auth-policy"`
TLSRootCAFile string `flag:"tls-root-ca-file"`
TLSRequired int `flag:"tls-required"`
TLSMinVersion uint16 `flag:"tls-min-version"`
// compression
DeflateEnabled bool `flag:"deflate"`
MaxDeflateLevel int `flag:"max-deflate-level"`
SnappyEnabled bool `flag:"snappy"`
// experimental features
Experiments []string `flag:"enable-experiment" cfg:"enable_experiment"`
}
type Experiment string
const (
TopologyAwareConsumption Experiment = "topology-aware-consumption"
)
var AllExperiments = []Experiment{
TopologyAwareConsumption,
}
func (o Options) HasExperiment(e Experiment) bool {
for _, v := range o.Experiments {
if string(e) == v {
return true
}
}
return false
}
func NewOptions() *Options {
hostname, err := os.Hostname()
if err != nil {
log.Fatal(err)
}
h := md5.New()
io.WriteString(h, hostname)
defaultID := int64(crc32.ChecksumIEEE(h.Sum(nil)) % 1024)
return &Options{
ID: defaultID,
LogPrefix: "[nsqd] ",
LogLevel: lg.INFO,
TCPAddress: "0.0.0.0:4150",
HTTPAddress: "0.0.0.0:4151",
HTTPSAddress: "0.0.0.0:4152",
BroadcastAddress: hostname,
BroadcastTCPPort: 0,
BroadcastHTTPPort: 0,
NSQLookupdTCPAddresses: make([]string, 0),
AuthHTTPAddresses: make([]string, 0),
AuthHTTPRequestMethod: "get",
HTTPClientConnectTimeout: 2 * time.Second,
HTTPClientRequestTimeout: 5 * time.Second,
MemQueueSize: 10000,
MaxBytesPerFile: 100 * 1024 * 1024,
SyncEvery: 2500,
SyncTimeout: 2 * time.Second,
QueueScanInterval: 100 * time.Millisecond,
QueueScanRefreshInterval: 5 * time.Second,
QueueScanSelectionCount: 20,
QueueScanWorkerPoolMax: 4,
QueueScanDirtyPercent: 0.25,
MsgTimeout: 60 * time.Second,
MaxMsgTimeout: 15 * time.Minute,
MaxMsgSize: 1024 * 1024,
MaxBodySize: 5 * 1024 * 1024,
MaxReqTimeout: 1 * time.Hour,
ClientTimeout: 60 * time.Second,
MaxHeartbeatInterval: 60 * time.Second,
MaxRdyCount: 2500,
MaxOutputBufferSize: 64 * 1024,
MaxOutputBufferTimeout: 30 * time.Second,
MinOutputBufferTimeout: 25 * time.Millisecond,
OutputBufferTimeout: 250 * time.Millisecond,
MaxChannelConsumers: 0,
StatsdPrefix: "nsq.%s",
StatsdInterval: 60 * time.Second,
StatsdMemStats: true,
StatsdUDPPacketSize: 508,
E2EProcessingLatencyWindowTime: time.Duration(10 * time.Minute),
DeflateEnabled: true,
MaxDeflateLevel: 6,
SnappyEnabled: true,
TLSMinVersion: tls.VersionTLS10,
}
}