mqttbmlatency

package module
v0.0.0-...-ce8efba Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 9, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

README

MQTT broker latency measure tool

功能:测量MQTT服务器转发时延。

测试场景:每一个topic都有一个订阅者和一个发布者,订阅者接收到消息时通过时间戳测量消息转发时延。
此外,测量结果还包括发布成功率、发布带宽、转发成功率等。

安装:

go get github.com/hui6075/mqtt-bm-latency

所有依赖包由manul构建。

A MQTT test tool to measure the broker's forwarding latency. Scenario: each topic has a subscriber and a publisher, the publisher publishes #count messages and the subscriber would measure the broker's forwarding latency by the timestamp inside each message's payload. Some other measurement include publish success ratio, publish bandwidth, forwarding success ratio would also be count.

Installation:

go get github.com/hui6075/mqtt-bm-latency

All dependencies are vendored with manul.

The tool supports multiple concurrent clients, configurable message size, etc:

> mqtt-bm-latency --help
Usage of ./mqtt-bm-latency:
  -broker string
        MQTT broker endpoint as scheme://host:port (default "tcp://localhost:1883")
  -topic string
        MQTT topic for outgoing messages (default "/test")
  -username string
        MQTT username (empty if auth disabled)
  -password string
        MQTT password (empty if auth disabled)
  -pubqos int
        QoS for published messages (default 1)
  -subqos int
        QoS for subscribed messages (default 1)
  -size int
        Size of the messages payload (bytes) (default 100)
  -clients int
        Number of clients pair to start (default 10)
  -count int
        Number of messages to send per pubclient (default 100)
  -keepalive int
        Keep alive period in seconds (default 60)
  -format string
        Benchmark results output format: text|json (default "text")
  -quiet
        Suppress logs while running




Two output formats supported: human-readable plain text and JSON.

Example use and output:

> mqtt-bm-latency --broker tcp://127.0.0.1:1883 --count 10 --size 100 --clients 10 --subqos 1 --pubqos 2 --format text
....

=========== PUBLISHER 0 ===========
Publish Success Ratio:   100.000% (10/10)
Runtime (s):             0.035
Pub time min (ms):       1.590
Pub time max (ms):       6.813
Pub time mean (ms):      2.831
Pub time std (ms):       1.594
Pub Bandwidth (msg/sec): 286.345

=========== SUBSCRIBER 4 ===========
Forward Success Ratio:       100.000% (10/10)
Forward latency min (ms):    6.000
Forward latency max (ms):    27.000
Forward latency std (ms):    6.867
Mean forward latency (ms):   15.400

================= TOTAL PUBLISHER (10) =================
Total Publish Success Ratio:   100.000% (100/100)
Total Runtime (sec):           0.037
Average Runtime (sec):         0.031
Pub time min (ms):             1.265
Pub time max (ms):             6.813
Pub time mean mean (ms):       2.462
Pub time mean std (ms):        0.242
Average Bandwidth (msg/sec):   321.516
Total Bandwidth (msg/sec):     3215.158

================= TOTAL SUBSCRIBER (10) =================
Total Forward Success Ratio:      100.000% (100/100)
Forward latency min (ms):         2.000
Forward latency max (ms):         27.000
Forward latency mean std (ms):    4.507
Total Mean forward latency (ms):  10.360

Similarly, in JSON:

> mqtt-bm-latency --broker tcp://127.0.0.1:1883 --count 10 --size 100 --clients 10 --subqos 1 --pubqos 2 --format json --quiet
{
        "publish runs": [{
                "id": 9,
                "pub_successes": 10,
                "failures": 0,
                "run_time": 0.036987145,
                "pub_time_min": 0.8713970000000001,
                "pub_time_max": 11.59584,
                "pub_time_mean": 2.8900005999999996,
                "pub_time_std": 3.0913799647375466,
                "publish_per_sec": 270.3642035631569
        },			...
	],
        "subscribe runs": [{
                "id": 9,
                "actual_published": 10,
                "received": 10,
                "fwd_success_ratio": 1,
                "fwd_time_min": 10,
                "fwd_time_max": 36,
                "fwd_time_mean": 20.8,
                "fwd_time_std": 9.101892355133874
        },			...
	],
        "publish totals": {
                "publish_success_ratio": 1,
                "successes": 100,
                "failures": 0,
                "total_run_time": 0.039432823000000006,
                "avg_run_time": 0.0363683729,
                "pub_time_min": 0.8713970000000001,
                "pub_time_max": 11.59584,
                "pub_time_mean_avg": 2.5923666000000005,
                "pub_time_mean_std": 0.2653321545301076,
                "total_msgs_per_sec": 2752.9351662099743,
                "avg_msgs_per_sec": 275.2935166209974
        },
        "receive totals": {
                "fwd_success_ratio": 1,
                "successes": 100,
                "actual_total_published": 100,
                "fwd_latency_min": 2,
                "fwd_latency_max": 37,
                "fwd_latency_mean_avg": 14.37,
                "fwd_latency_mean_std": 4.129581630679366
        }
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Start

func Start(broker string, topic string, qos int, size int, count int, clients int, quiet bool) []byte

Types

type JSONResults

type JSONResults struct {
	PubRuns   []*PubResults    `json:"publish runs"`
	SubRuns   []*SubResults    `json:"subscribe runs"`
	PubTotals *TotalPubResults `json:"publish totals"`
	SubTotals *TotalSubResults `json:"receive totals"`
}

JSONResults are used to export results as a JSON document

type Message

type Message struct {
	Topic     string
	QoS       byte
	Payload   interface{}
	Sent      time.Time
	Delivered time.Time
	Error     bool
}

Message describes a message

type PubClient

type PubClient struct {
	ID         int
	BrokerURL  string
	BrokerUser string
	BrokerPass string
	PubTopic   string
	MsgSize    int
	MsgCount   int
	PubQoS     byte
	KeepAlive  int
	Quiet      bool
}

type PubResults

type PubResults struct {
	ID          int     `json:"id"`
	Successes   int64   `json:"pub_successes"`
	Failures    int64   `json:"failures"`
	RunTime     float64 `json:"run_time"`
	PubTimeMin  float64 `json:"pub_time_min"`
	PubTimeMax  float64 `json:"pub_time_max"`
	PubTimeMean float64 `json:"pub_time_mean"`
	PubTimeStd  float64 `json:"pub_time_std"`
	PubsPerSec  float64 `json:"publish_per_sec"`
}

PubResults describes results of a single PUBLISHER / run

type SubClient

type SubClient struct {
	ID         int
	BrokerURL  string
	BrokerUser string
	BrokerPass string
	SubTopic   string
	SubQoS     byte
	KeepAlive  int
	Quiet      bool
}

type SubResults

type SubResults struct {
	ID             int     `json:"id"`
	Published      int64   `json:"actual_published"`
	Received       int64   `json:"received"`
	FwdRatio       float64 `json:"fwd_success_ratio"`
	FwdLatencyMin  float64 `json:"fwd_time_min"`
	FwdLatencyMax  float64 `json:"fwd_time_max"`
	FwdLatencyMean float64 `json:"fwd_time_mean"`
	FwdLatencyStd  float64 `json:"fwd_time_std"`
}

SubResults describes results of a single SUBSCRIBER / run

type TotalPubResults

type TotalPubResults struct {
	PubRatio        float64 `json:"publish_success_ratio"`
	Successes       int64   `json:"successes"`
	Failures        int64   `json:"failures"`
	TotalRunTime    float64 `json:"total_run_time"`
	AvgRunTime      float64 `json:"avg_run_time"`
	PubTimeMin      float64 `json:"pub_time_min"`
	PubTimeMax      float64 `json:"pub_time_max"`
	PubTimeMeanAvg  float64 `json:"pub_time_mean_avg"`
	PubTimeMeanStd  float64 `json:"pub_time_mean_std"`
	TotalMsgsPerSec float64 `json:"total_msgs_per_sec"`
	AvgMsgsPerSec   float64 `json:"avg_msgs_per_sec"`
}

TotalPubResults describes results of all PUBLISHER / runs

type TotalSubResults

type TotalSubResults struct {
	TotalFwdRatio     float64 `json:"fwd_success_ratio"`
	TotalReceived     int64   `json:"successes"`
	TotalPublished    int64   `json:"actual_total_published"`
	FwdLatencyMin     float64 `json:"fwd_latency_min"`
	FwdLatencyMax     float64 `json:"fwd_latency_max"`
	FwdLatencyMeanAvg float64 `json:"fwd_latency_mean_avg"`
	FwdLatencyMeanStd float64 `json:"fwd_latency_mean_std"`
}

TotalSubResults describes results of all SUBSCRIBER / runs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL