NATS 中文文档
  • 引言
  • 发布日志
  • NATS 2.0
  • 对比 NATS
  • FAQ
  • NATS Concepts
    • What is NATS
    • Subject-Based Messaging
    • Publish-Subscribe
    • Request-Reply
    • Queue Groups
    • Acknowledgements
    • Sequence Numbers
  • Developing With NATS
    • Introduction
    • Connecting
      • Connecting to the Default Server
      • Connecting to a Specific Server
      • Connecting to a Cluster
      • Connection Name
      • Setting a Connect Timeout
      • Ping/Pong Protocol
      • Turning Off Echo'd Messages
      • Miscellaneous functionalities
    • Automatic Reconnections
      • Disabling Reconnect
      • Set the Number of Reconnect Attempts
      • Avoiding the Thundering Herd
      • Pausing Between Reconnect Attempts
      • Listening for Reconnect Events
      • Buffering Messages During Reconnect Attempts
    • Securing Connections
      • Authenticating with a User and Password
      • Authenticating with a Token
      • Authenticating with an NKey
      • Authenticating with a Credentials File
      • Encrypting Connections with TLS
    • Receiving Messages
      • Synchronous Subscriptions
      • Asynchronous Subscriptions
      • Unsubscribing
      • Unsubscribing After N Messages
      • Replying to a Message
      • Wildcard Subscriptions
      • Queue Subscriptions
      • Draining Messages Before Disconnect
      • Structured Data
    • Sending Messages
      • Including a Reply Subject
      • Request-Reply Semantics
      • Caches, Flush and Ping
      • Sending Structured Data
    • Monitoring the Connection
      • Listen for Connection Events
      • Slow Consumers
    • Tutorials
      • Explore NATS Pub/Sub
      • Explore NATS Request/Reply
      • Explore NATS Queueing
      • Advanced Connect and Custom Dialer in Go
  • NATS Server
    • Installing
    • Running
      • Windows Service
    • Clients
    • Flags
    • Configuration
      • Securing NATS
        • Enabling TLS
        • Authentication
          • Tokens
          • Username/Password
          • TLS Authentication
          • NKeys
          • Authentication Timeout
        • Authorization
        • Multi Tenancy using Accounts
        • Decentralized JWT Authentication/Authorization
          • Account lookup using Resolver
          • Memory Resolver Tutorial
          • Mixed Authentication/Authorization Setup
      • Clustering
        • Configuration
        • TLS Authentication
      • Super-cluster with Gateways
        • Configuration
      • Leaf Nodes
        • Configuration
      • Logging
      • Monitoring
      • System Events
        • System Events & Decentralized JWT Tutorial
    • Managing A NATS Server
      • Upgrading a Cluster
      • Slow Consumers
      • Signals
    • NATS and Docker
      • Tutorial
      • Docker Swarm
      • Python and NGS Running in Docker
  • NATS Tools
    • Introduction
    • mkpasswd
    • nk
    • nsc
      • Basics
      • Streams
      • Services
      • Signing Keys
      • Revocation
      • Managed Operators
    • nats-account-server
      • Basics
      • Inspecting JWTs
      • Directory Store
      • Update Notifications
    • nats-top
      • Tutorial
    • nats-bench
  • NATS Streaming Concepts
    • Introduction
    • Relation to NATS
    • Client Connections
    • Channels
      • Message Log
      • Subscriptions
        • Regular
        • Durable
        • Queue Group
        • Redelivery
    • Store Interface
    • Store Encryption
    • Clustering
      • Supported Stores
      • Configuration
      • Auto Configuration
      • Containers
    • Fault Tolerance
      • Active Server
      • Standby Servers
      • Shared State
      • Failover
    • Partitioning
    • Monitoring
      • Endpoints
  • Developing With NATS Streaming
    • Introduction
    • Connecting to NATS Streaming
    • Publishing to a Channel
    • Receiving Messages from a Channel
    • Durable Subscriptions
    • Queue Subscriptions
    • Acknowledgements
    • The Streaming Protocol
  • NATS Streaming Server
    • Important Changes
    • Installing
    • Running
    • Configuring
      • Command Line Arguments
      • Configuration File
      • Store Limits
      • 持久化
        • 文件存储
        • SQL 存储
      • Securing
    • Process Signaling
    • Windows Service
    • Embedding NATS Streaming Server
    • Docker Swarm
  • NATS Protocol
    • Protocol Demo
    • Client Protocol
      • Developing a Client
    • NATS Cluster Protocol
  • 在 Kubernetes中使用NATS
    • 序言
    • 安装 NATS 和 NATS Streaming
    • 创建一个 Kubernetes 集群
    • 容错(Fault Tolerance)模式下的NATS Streaming 集群
    • NATS 和 Prometheus Operator
    • NATS 集群和证书管理
    • 使用 cfssl 来提高 NATS 集群的安全性
    • 使用负载均衡器(Load Balancer) 为NATS提供外部访问
    • 使用Helm在Digital Ocean 创建一个NATS 超级集群
    • 使用Helm从0到 K8s到 子节点
由 GitBook 提供支持
在本页
  • Prerequisites
  • Start the NATS server with monitoring enabled
  • Installing and running the benchmark utility
  • Run a publisher throughput test
  • Run a publish/subscribe throughput test
  • Run a 1:N throughput test
  • Run a N:M throughput test

这有帮助吗?

  1. NATS Tools

nats-bench

上一页Tutorial下一页Introduction

最后更新于4年前

这有帮助吗?

NATS is fast and lightweight and places a priority on performance. NATS provides tools for measuring performance. In this tutorial you learn how to benchmark and tune NATS on your systems and environment.

Prerequisites

Start the NATS server with monitoring enabled

% nats-server -m 8222

Verify that the NATS server starts successfully, as well as the HTTP monitor:

[18541] 2016/10/31 13:26:32.037819 [INF] Starting nats-server version 0.9.4
[18541] 2016/10/31 13:26:32.037912 [INF] Starting http monitor on 0.0.0.0:8222
[18541] 2016/10/31 13:26:32.037997 [INF] Listening for client connections on 0.0.0.0:4222
[18541] 2016/10/31 13:26:32.038020 [INF] Server is ready

Installing and running the benchmark utility

The NATS benchmark can be installed and run via Go. Ensure your golang environment is setup.

There are two approaches; you can either install the nats-bench utility in the directory specified in your GOBIN environment variable:

% go install $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench/main.go

... or you can simply run it via go run:

% go run $GOPATH/src/github.com/nats-io/nats.go/examples/nats-bench/main.go

On windows use the % environment variable syntax, replacing $GOPATH with %GOPATH%.

For the purpose of this tutorial, we'll assume that you chose the first option, and that you've added the GOBIN environment variable to your PATH.

The nats-bench utility is straightforward to use. The options are as follows:

% nats-bench -h
Usage: nats-bench [-s server (nats://localhost:4222)] [--tls] [-np NUM_PUBLISHERS] [-ns NUM_SUBSCRIBERS] [-n NUM_MSGS] [-ms MESSAGE_SIZE] [-csv csvfile] <subject>

The options are self-explanatory. Each publisher or subscriber runs in its own go routine with its own NATS connection.

Run a publisher throughput test

Let's run a test to see how fast a single publisher can publish one million 16 byte messages to the NATS server.

% nats-bench -np 1 -n 100000 -ms 16 foo

The output tells you the number of messages and the number of payload bytes that the client was able to publish per second:

Starting benchmark [msgs=100000, msgsize=16, pubs=1, subs=0]
Pub stats: 7,055,644 msgs/sec ~ 107.66 MB/sec

Now increase the number of messages published:

% nats-bench -np 1 -n 10000000 -ms 16 foo
Starting benchmark [msgs=10000000, msgsize=16, pubs=1, subs=0]
Pub stats: 7,671,570 msgs/sec ~ 117.06 MB/sec

Run a publish/subscribe throughput test

When using both publishers and subscribers, nats-bench reports aggregate, as well as individual publish and subscribe throughput performance.

Let's look at throughput for a single publisher with a single subscriber:

% nats-bench -np 1 -ns 1 -n 100000 -ms 16 foo

Note that the output shows the aggregate throughput as well as the individual publisher and subscriber performance:

Starting benchmark [msgs=100000, msgsize=16, pubs=1, subs=1]
NATS Pub/Sub stats: 2,009,230 msgs/sec ~ 30.66 MB/sec
 Pub stats: 1,076,537 msgs/sec ~ 16.43 MB/sec
 Sub stats: 1,004,615 msgs/sec ~ 15.33 MB/sec

Run a 1:N throughput test

When specifying multiple publishers, or multiple subscribers, nats-bench will also report statistics for each publisher and subscriber individually, along with min/max/avg and standard deviation.

Let's increase both the number of messages, and the number of subscribers.:

% nats-bench -np 1 -ns 5 -n 10000000 -ms 16 foo

Output:

Starting benchmark [msgs=10000000, msgsize=16, pubs=1, subs=5]
NATS Pub/Sub stats: 5,730,851 msgs/sec ~ 87.45 MB/sec
 Pub stats: 955,279 msgs/sec ~ 14.58 MB/sec
 Sub stats: 4,775,709 msgs/sec ~ 72.87 MB/sec
  [1] 955,157 msgs/sec ~ 14.57 MB/sec (10000000 msgs)
  [2] 955,150 msgs/sec ~ 14.57 MB/sec (10000000 msgs)
  [3] 955,157 msgs/sec ~ 14.57 MB/sec (10000000 msgs)
  [4] 955,156 msgs/sec ~ 14.57 MB/sec (10000000 msgs)
  [5] 955,153 msgs/sec ~ 14.57 MB/sec (10000000 msgs)
  min 955,150 | avg 955,154 | max 955,157 | stddev 2 msgs

Run a N:M throughput test

When more than 1 publisher is specified, nats-bench evenly distributes the total number of messages (-n) across the number of publishers (-np).

Now let's increase the number of publishers and examine the output:

% nats-bench -np 5 -ns 5 -n 10000000 -ms 16 foo

The output:

Starting benchmark [msgs=10000000, msgsize=16, pubs=5, subs=5]
NATS Pub/Sub stats: 6,716,465 msgs/sec ~ 102.49 MB/sec
 Pub stats: 1,119,653 msgs/sec ~ 17.08 MB/sec
  [1] 226,395 msgs/sec ~ 3.45 MB/sec (2000000 msgs)
  [2] 225,955 msgs/sec ~ 3.45 MB/sec (2000000 msgs)
  [3] 225,889 msgs/sec ~ 3.45 MB/sec (2000000 msgs)
  [4] 224,552 msgs/sec ~ 3.43 MB/sec (2000000 msgs)
  [5] 223,933 msgs/sec ~ 3.42 MB/sec (2000000 msgs)
  min 223,933 | avg 225,344 | max 226,395 | stddev 937 msgs
 Sub stats: 5,597,054 msgs/sec ~ 85.40 MB/sec
  [1] 1,119,461 msgs/sec ~ 17.08 MB/sec (10000000 msgs)
  [2] 1,119,466 msgs/sec ~ 17.08 MB/sec (10000000 msgs)
  [3] 1,119,444 msgs/sec ~ 17.08 MB/sec (10000000 msgs)
  [4] 1,119,444 msgs/sec ~ 17.08 MB/sec (10000000 msgs)
  [5] 1,119,430 msgs/sec ~ 17.08 MB/sec (10000000 msgs)
  min 1,119,430 | avg 1,119,449 | max 1,119,466 | stddev 12 msgs
Set up your Go environment
Install the NATS server