options.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package nsqd
  2. import (
  3. "crypto/md5"
  4. "crypto/tls"
  5. "hash/crc32"
  6. "io"
  7. "log"
  8. "os"
  9. "time"
  10. "github.com/nsqio/nsq/internal/lg"
  11. )
  12. type Options struct {
  13. // basic options
  14. ID int64 `flag:"node-id" cfg:"id"`
  15. LogLevel lg.LogLevel `flag:"log-level"`
  16. LogPrefix string `flag:"log-prefix"`
  17. Logger Logger
  18. TCPAddress string `flag:"tcp-address"`
  19. HTTPAddress string `flag:"http-address"`
  20. HTTPSAddress string `flag:"https-address"`
  21. BroadcastAddress string `flag:"broadcast-address"`
  22. BroadcastTCPPort int `flag:"broadcast-tcp-port"`
  23. BroadcastHTTPPort int `flag:"broadcast-http-port"`
  24. NSQLookupdTCPAddresses []string `flag:"lookupd-tcp-address" cfg:"nsqlookupd_tcp_addresses"`
  25. AuthHTTPAddresses []string `flag:"auth-http-address" cfg:"auth_http_addresses"`
  26. HTTPClientConnectTimeout time.Duration `flag:"http-client-connect-timeout" cfg:"http_client_connect_timeout"`
  27. HTTPClientRequestTimeout time.Duration `flag:"http-client-request-timeout" cfg:"http_client_request_timeout"`
  28. // diskqueue options
  29. DataPath string `flag:"data-path"`
  30. MemQueueSize int64 `flag:"mem-queue-size"`
  31. MaxBytesPerFile int64 `flag:"max-bytes-per-file"`
  32. SyncEvery int64 `flag:"sync-every"`
  33. SyncTimeout time.Duration `flag:"sync-timeout"`
  34. QueueScanInterval time.Duration
  35. QueueScanRefreshInterval time.Duration
  36. QueueScanSelectionCount int `flag:"queue-scan-selection-count"`
  37. QueueScanWorkerPoolMax int `flag:"queue-scan-worker-pool-max"`
  38. QueueScanDirtyPercent float64
  39. // msg and command options
  40. MsgTimeout time.Duration `flag:"msg-timeout"`
  41. MaxMsgTimeout time.Duration `flag:"max-msg-timeout"`
  42. MaxMsgSize int64 `flag:"max-msg-size"`
  43. MaxBodySize int64 `flag:"max-body-size"`
  44. MaxReqTimeout time.Duration `flag:"max-req-timeout"`
  45. ClientTimeout time.Duration
  46. // client overridable configuration options
  47. MaxHeartbeatInterval time.Duration `flag:"max-heartbeat-interval"`
  48. MaxRdyCount int64 `flag:"max-rdy-count"`
  49. MaxOutputBufferSize int64 `flag:"max-output-buffer-size"`
  50. MaxOutputBufferTimeout time.Duration `flag:"max-output-buffer-timeout"`
  51. MinOutputBufferTimeout time.Duration `flag:"min-output-buffer-timeout"`
  52. OutputBufferTimeout time.Duration `flag:"output-buffer-timeout"`
  53. MaxChannelConsumers int `flag:"max-channel-consumers"`
  54. // statsd integration
  55. StatsdAddress string `flag:"statsd-address"`
  56. StatsdPrefix string `flag:"statsd-prefix"`
  57. StatsdInterval time.Duration `flag:"statsd-interval"`
  58. StatsdMemStats bool `flag:"statsd-mem-stats"`
  59. StatsdUDPPacketSize int `flag:"statsd-udp-packet-size"`
  60. StatsdExcludeEphemeral bool `flag:"statsd-exclude-ephemeral"`
  61. // e2e message latency
  62. E2EProcessingLatencyWindowTime time.Duration `flag:"e2e-processing-latency-window-time"`
  63. E2EProcessingLatencyPercentiles []float64 `flag:"e2e-processing-latency-percentile" cfg:"e2e_processing_latency_percentiles"`
  64. // TLS config
  65. TLSCert string `flag:"tls-cert"`
  66. TLSKey string `flag:"tls-key"`
  67. TLSClientAuthPolicy string `flag:"tls-client-auth-policy"`
  68. TLSRootCAFile string `flag:"tls-root-ca-file"`
  69. TLSRequired int `flag:"tls-required"`
  70. TLSMinVersion uint16 `flag:"tls-min-version"`
  71. // compression
  72. DeflateEnabled bool `flag:"deflate"`
  73. MaxDeflateLevel int `flag:"max-deflate-level"`
  74. SnappyEnabled bool `flag:"snappy"`
  75. QosEnabled bool `flag:"qos"`
  76. RtEnabled bool `flag:"rt"`
  77. FifoEnabled bool `flag:"fifo"`
  78. }
  79. func NewOptions() *Options {
  80. hostname, err := os.Hostname()
  81. if err != nil {
  82. log.Fatal(err)
  83. }
  84. h := md5.New()
  85. io.WriteString(h, hostname)
  86. defaultID := int64(crc32.ChecksumIEEE(h.Sum(nil)) % 1024)
  87. return &Options{
  88. ID: defaultID,
  89. LogPrefix: "[smqd] ",
  90. LogLevel: lg.INFO,
  91. TCPAddress: "0.0.0.0:9050",
  92. HTTPAddress: "0.0.0.0:9051",
  93. HTTPSAddress: "0.0.0.0:9052",
  94. BroadcastAddress: hostname,
  95. BroadcastTCPPort: 0,
  96. BroadcastHTTPPort: 0,
  97. NSQLookupdTCPAddresses: make([]string, 0),
  98. AuthHTTPAddresses: make([]string, 0),
  99. HTTPClientConnectTimeout: 2 * time.Second,
  100. HTTPClientRequestTimeout: 5 * time.Second,
  101. MemQueueSize: 10000,
  102. MaxBytesPerFile: 100 * 1024 * 1024,
  103. SyncEvery: 2500,
  104. SyncTimeout: 2 * time.Second,
  105. QueueScanInterval: 100 * time.Millisecond,
  106. QueueScanRefreshInterval: 5 * time.Second,
  107. QueueScanSelectionCount: 20,
  108. QueueScanWorkerPoolMax: 4,
  109. QueueScanDirtyPercent: 0.25,
  110. MsgTimeout: 60 * time.Second,
  111. MaxMsgTimeout: 15 * time.Minute,
  112. MaxMsgSize: 1024 * 1024,
  113. MaxBodySize: 5 * 1024 * 1024,
  114. MaxReqTimeout: 1 * time.Hour,
  115. ClientTimeout: 60 * time.Second,
  116. MaxHeartbeatInterval: 60 * time.Second,
  117. MaxRdyCount: 2500,
  118. MaxOutputBufferSize: 64 * 1024,
  119. MaxOutputBufferTimeout: 30 * time.Second,
  120. MinOutputBufferTimeout: 25 * time.Millisecond,
  121. OutputBufferTimeout: 250 * time.Millisecond,
  122. MaxChannelConsumers: 0,
  123. StatsdPrefix: "nsq.%s",
  124. StatsdInterval: 60 * time.Second,
  125. StatsdMemStats: true,
  126. StatsdUDPPacketSize: 508,
  127. E2EProcessingLatencyWindowTime: time.Duration(10 * time.Minute),
  128. DeflateEnabled: true,
  129. MaxDeflateLevel: 6,
  130. SnappyEnabled: true,
  131. QosEnabled: false,
  132. RtEnabled: true,
  133. FifoEnabled: false,
  134. TLSMinVersion: tls.VersionTLS10,
  135. }
  136. }