在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數據庫/ nsqd
nsqadmin
常見問題
安裝
編譯客戶端庫
特性和擔保
工具
拓撲模式
設計
Docker
nsqd
內幕
性能
TCP 協議規(guī)范
nsqlookupd
介紹
產品配置
客戶端庫
快速開始

nsqd

nsqd 是一個守護進程,負責接收,排隊,投遞消息給客戶端。

它可以獨立運行,不過通常它是由 nsqlookupd 實例所在集群配置的(它在這能聲明 topics 和 channels,以便大家能找到)。

它在 2 個 TCP 端口監(jiān)聽,一個給客戶端,另一個是 HTTP API。同時,它也能在第三個端口監(jiān)聽 HTTPS。

命令行選項

-auth-http-address=: <addr>:<port> 查詢授權服務器 (可能會給多次)
-broadcast-address="": 通過 lookupd  注冊的地址(默認名是 OS)
-config="": 配置文件路徑
-data-path="": 緩存消息的磁盤路徑
-deflate=true: 運行協商壓縮特性(客戶端壓縮)
-e2e-processing-latency-percentile=: 消息處理時間的百分比(通過逗號可以多次指定,默認為 none)
-e2e-processing-latency-window-time=10m0s: 計算這段時間里,點對點時間延遲(例如,60s 僅計算過去 60 秒)
-http-address="0.0.0.0:4151": 為 HTTP 客戶端監(jiān)聽 <addr>:<port>
-https-address="": 為 HTTPS 客戶端 監(jiān)聽 <addr>:<port>
-lookupd-tcp-address=: 解析 TCP 地址名字 (可能會給多次)
-max-body-size=5123840: 單個命令體的最大尺寸
-max-bytes-per-file=104857600: 每個磁盤隊列文件的字節(jié)數
-max-deflate-level=6: 最大的壓縮比率等級(> values == > nsqd CPU usage)
-max-heartbeat-interval=1m0s: 在客戶端心跳間,最大的客戶端配置時間間隔
-max-message-size=1024768: (棄用 --max-msg-size) 單個消息體的最大字節(jié)數
-max-msg-size=1024768: 單個消息體的最大字節(jié)數
-max-msg-timeout=15m0s: 消息超時的最大時間間隔
-max-output-buffer-size=65536: 最大客戶端輸出緩存可配置大小(字節(jié))
-max-output-buffer-timeout=1s: 在 flushing 到客戶端前,最長的配置時間間隔。
-max-rdy-count=2500: 客戶端最大的 RDY 數量
-max-req-timeout=1h0m0s: 消息重新排隊的超時時間
-mem-queue-size=10000: 內存里的消息數(per topic/channel)
-msg-timeout="60s": 自動重新隊列消息前需要等待的時間
-snappy=true: 打開快速選項 (客戶端壓縮)
-statsd-address="": 統計進程的 UDP <addr>:<port>
-statsd-interval="60s": 從推送到統計的時間間隔
-statsd-mem-stats=true: 切換發(fā)送內存和 GC 統計數據
-statsd-prefix="nsq.%s": 發(fā)送給統計keys 的前綴(%s for host replacement)
-sync-every=2500: 磁盤隊列 fsync 的消息數
-sync-timeout=2s: 每個磁盤隊列 fsync 平均耗時
-tcp-address="0.0.0.0:4150": TCP 客戶端 監(jiān)聽的 <addr>:<port>
-tls-cert="": 證書文件路徑
-tls-client-auth-policy="": 客戶端證書授權策略 ('require' or 'require-verify')
-tls-key="": 私鑰路徑文件
-tls-required=false: 客戶端連接需求 TLS
-tls-root-ca-file="": 私鑰證書授權 PEM 路徑
-verbose=false: 打開日志
-version=false: 打印版本
-worker-id=0: 進程的唯一碼(默認是主機名的哈希值)

HTTP API

v1 命名空間 (as of nsqd v0.2.29+):

以拋棄的命名空間:

NOTE: 這些結束點返回 "wrapped" JSON:

{"status_code":200, "status_text":"OK", "data":{...}}

發(fā)送 Accept: application/vnd.nsq; version=1.0 頭將會協商使用未封裝的 JSON 響應格式 (as of nsqd v0.2.29+)。

/pub

發(fā)布一個消息

參數:

topic - the topic to publish to

POST body - the raw message bytes
$ curl -d "<message>" http://127.0.0.1:4151/pub?topic=message_topic`

/mpub

一個往返發(fā)布多個消息

參數:

topic - 發(fā)布到的話題(topic)
binary - bool ('true' or 'false') 允許二進制模式

POST body - `\n` 分離原始消息字節(jié)

注意:默認的 /mpub 希望消息使用 \n 切割,使用 ?binary=true 查詢參數來允許二進制模式,希望發(fā)送的消息體能成為以下的格式(HTTP 'Content-Length' 頭必須是將要發(fā)送的消息體的總大?。?/p>

[ 4-byte num messages ]
[ 4-byte message #1 size ][ N-byte binary data ]
      ... (repeated <num_messages> times)
$ curl -d "<message>\n<message>\n<message>" http://127.0.0.1:4151/mpub?topic=message_topic`

/topic/create

已經拋棄的別名 /create_topic

創(chuàng)建一個話題(topic)

參數:

話題(topic) - 將要創(chuàng)建的話題(topic)

/topic/delete

已經拋棄的別名 : /delete_topic

刪除一個已經存在的話題(topic) (和所有的通道(channel))

參數:

topic - 現有的話題(topic) to delete

/channel/create

已拋棄的別名: /create_channel

為現有的話題(topic) 創(chuàng)建一個通道(channel)

參數:

topic - 現有的話題(topic)
channel - the channel to create

/channel/delete

已拋棄的別名: /delete_channel

刪除現有的話題(topic) 一個的通道(channel)

參數:

topic - 現有的話題(topic)
channel - 待刪除的通道(channel)

/topic/empty

已拋棄的別名: /empty_topic

清空現有話題(topic) 隊列中所有的消息(內存和磁盤中)

參數:

topic - 待清空的話題(topic)

/channel/empty

已拋棄的別名: /empty_channel

清空現有通道(channel) 隊列中所有的消息(內存和磁盤中)

參數:

topic - 現有的話題(topic)
channel - 待清空的通道(channel)

/topic/pause

已拋棄的別名: /pause_topic

暫停已有話題(topic) 的所有通道(channel)的消息(消息將會在話題(topic) 里排隊)

參數:

topic - 現有的話題(topic)

/topic/unpause

已拋棄的別名: /unpause_topic

為現有的話題(topic) 的通道(channel) 重啟消息流

參數:

topic - 現有的話題(topic)

/channel/pause

已拋棄的別名: /channel_pause

暫停發(fā)送已有的通道(channel) 給消費者(消息將會隊列)

參數:

topic - 現有的話題(topic)
channel - 已有的通道(channel)將會被暫停

/channel/unpause

已拋棄的別名: /unpause_channel

重新發(fā)送通道(channel) 里的消息給消費者

參數:

topic - 現有的話題(topic)
channel - 將要暫停的通道(channel)

/stats

返回內部統計數據

參數

format - (可選) `text` or `json` (默認 = `text`)

/ping

監(jiān)控結束點,必須返回 OK。如果有問題返回 500。同時,如果寫消息到磁盤失敗將會返回錯誤狀態(tài)。

/info

返回版本信息

/debug/pprof

可用的調試節(jié)點的頁碼

/debug/pprof/profile

開始 30秒的 pprof CPU 配置,并通過請求返回。

注意,因為它在運行時的性能和時間,這個結束點并沒在 /debug/pprof 頁面列表中。

/debug/pprof/goroutine

為所有運行的 goroutines 返回棧記錄。

/debug/pprof/heap

返回堆和內存配置信息(前面的內容可作為 pprof 配置信息)

/debug/pprof/block

返回 goroutine 塊配置信息

/debug/pprof/threadcreate

返回 goroutine 棧記錄

Debugging and Profiling

nsqd 提供一套節(jié)點的配置信息,直接通過 Go 的 pprof 工具。如果你有 go 工具套裝,只要運行:

# memory profiling
$ go 工具 pprof http://localhost:4151/debug/pprof/heap

# cpu profiling
$ go 工具 pprof http://localhost:4151/debug/pprof/profile

TLS

為了加強安全性,可以通過 --tls-cert--tls-key 客戶端配置 nsqd,升級他們的鏈接為 TLS。

另外,你可以要求客戶端使用 --tls-required (nsqd v0.2.28+)協商 TLS。

你可以通過--tls-client-auth-policy (requirerequire-verify)配置一個 nsqd 客戶端證書:

  • require - 客戶端必須提供一個證書,否則將會被拒絕
  • require-verify - 客戶端必須提供一個有效的證書,根據 --tls-root-ca-file 指定的鏈接或者默認的 CA,否則將會被拒絕。

可以當做客戶端授權的表單(nsqd v0.2.28+)。

如果你想生成一個 password-less,自簽名證書,用:

$ openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes

AUTH

注意: 在 nsqd v0.2.29+ 可用

通過使用一個遵從 Auth HTTP 協議的授權服務器,指定 -auth-http-address=host:port 標志,你可以配置 nsqd。

注意: 希望當僅有 nsqd TCP 協議暴露給外部客戶端時使用授權,而不是 HTTP(S) 節(jié)點。參見底下說明:

Auth 服務器必須接受 HTTP 請求:

/auth?remote_ip=...&tls=...&auth_secret=...

返回結果格式如下:

{
  "ttl": 3600,
  "identity": "username",
  "identity_url": "http://....",
  "authorizations": [
    {
      "permissions": [
        "subscribe",
        "publish"
      ],
      "topic": ".*",
      "channels": [
        ".*"
      ]
    }
  ]
}

注意話題(topic) 和通道(channel) 字符串必須用 nsqd 的正則表達式來申請授權。nsqd 將會為 TTL 間隔,并會在這個間隔時間里重新請求授權。

通常情況,將會使用 TLS 來加強安全性。nsqd 和 授權服務器間通過信任的網絡通信(并沒被加密)。如果一個授權服務器通過遠程 IP 信息來授權,客戶端可以使用占位符(比如 .),作為 AUTH 命令(Auth 服務器忽略)。

授權服務器例子 pynsqauthd。

幫助服務器暴露 nsqlookupdnsqd /stats 數據給客戶端,從授權服務器通過權限過濾,在以下可以找到 nsqauthfilter。

當使用命令行工具,可以通過使用 --reader-opt 標志來授權。

$ nsq_tail ... -reader-opt="tls_v1,true" -reader-opt="auth_secret,$SECRET"

點對點處理延遲

你可以選擇設置 nsqd 來收集和發(fā)射點對點信息處理延遲,通過 --e2e-processing-latency-percentile 標志位來配置百分比。

使用概率百分比技術(參見 Effective Computation of Biased Quantiles over Data Streams)來計算值。我們通過 bmizerany 來使用 perks 包,它能實現這個算法。

我們內部維持 2 個通道(channel),每個通道(channel)存儲 N/2 分鐘的延遲數據。每個 N/2 分鐘我們重置了每個通道(channel)(并開始插入新的數據)。

因為我們僅在通道級別收集數據,對于話題我們聚合并合并所有的通道數量的 quantiles。如果數據在同一個 nsqd 實例上時,可以使用這個技術。然而當數據已經精確的通過 nsqd (通過 nsqlookupd),我們?yōu)槊總€ nsqd 取平均值。為了維持統計的精確性,除了平均值,我們也提供最大最小值。

注意: 如果沒有消費者連接,不能更新值,盡管消息隊列的點對點時間會緩慢增長。這是因為僅在 nsqd 收到從客戶端發(fā)來 FIN 消息時才會重新計算。當消費者重新連接,這些值將會重新調整。

Statsd / Graphite Integration

當使用 --statsd-address 來為statsd (或類似 statsdaemon)指定 UDP <addr>:<port> 時,nsqd 將會在 --statsd-interval 定期推送數據給 statsd(注意:這個間隔必須始終小于等于 graphite 的刷入間隔)。設置 nsqadmin 可以顯示圖標。

推薦以下配置(但是這些選擇必須建立在你的可用資源和要求上)。同時,statsd 的刷入間隔必須小于或者等于 storage-schemas.conf 的最小值,并且 nsqd 必須通過 --statsd-interval 來確認刷入時間小于等于時間間隔。

# storage-schemas.conf
[nsq]
pattern = ^nsq\..*
retentions = 1m:1d,5m:30d,15m:1y

# storage-aggregation.conf
[default_nsq]
pattern = ^nsq\..*
xFilesFactor = 0.2 
aggregationMethod = average

nsqd 實例將會推送給以下 statsd 路徑:

nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.backend_depth [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.depth [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.message_count
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.backend_depth [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.clients [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.deferred_count [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.depth [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.in_flight_count [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.message_count
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.requeue_count
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.timeout_count

# if --statsd-mem-stats is enabled
nsq.<nsqd_host>_<nsqd_port>.mem.heap_objects [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.heap_idle_bytes [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.heap_in_use_bytes [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.heap_released_bytes [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.gc_pause_usec_100 [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.gc_pause_usec_99 [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.gc_pause_usec_95 [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.mem.next_gc_bytes [gauge]
nsq.<nsqd_host>_<nsqd_port>.mem.gc_runs

# if --e2e-processing-latency-percentile is specified, for each percentile
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.e2e_processing_latency_<percent> [gauge]
nsq.<nsqd_host>_<nsqd_port>.topic.<topic_name>.channel.<channel_name>.e2e_processing_latency_<percent> [gauge]
上一篇:設計下一篇:內幕