mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-12 21:01:21 +00:00
mv tools files to tools repo
This commit is contained in:
6
tools/tm-bench/Dockerfile
Normal file
6
tools/tm-bench/Dockerfile
Normal file
@ -0,0 +1,6 @@
|
||||
FROM alpine:3.7
|
||||
|
||||
WORKDIR /app
|
||||
COPY tm-bench /app/tm-bench
|
||||
|
||||
ENTRYPOINT ["./tm-bench"]
|
12
tools/tm-bench/Dockerfile.dev
Normal file
12
tools/tm-bench/Dockerfile.dev
Normal file
@ -0,0 +1,12 @@
|
||||
FROM golang:latest
|
||||
|
||||
RUN mkdir -p /go/src/github.com/tendermint/tools/tm-bench
|
||||
WORKDIR /go/src/github.com/tendermint/tools/tm-bench
|
||||
|
||||
COPY Makefile /go/src/github.com/tendermint/tools/tm-bench/
|
||||
|
||||
RUN make get_tools
|
||||
|
||||
COPY . /go/src/github.com/tendermint/tools/tm-bench
|
||||
|
||||
RUN make get_vendor_deps
|
337
tools/tm-bench/Gopkg.lock
generated
Normal file
337
tools/tm-bench/Gopkg.lock
generated
Normal file
@ -0,0 +1,337 @@
|
||||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/beorn7/perks"
|
||||
packages = ["quantile"]
|
||||
revision = "3a771d992973f24aa725d07868b467d1ddfceafb"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/btcsuite/btcd"
|
||||
packages = ["btcec"]
|
||||
revision = "675abc5df3c5531bc741b56a765e35623459da6d"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/davecgh/go-spew"
|
||||
packages = ["spew"]
|
||||
revision = "346938d642f2ec3594ed81d874461961cd0faa76"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/ebuchman/fail-test"
|
||||
packages = ["."]
|
||||
revision = "95f809107225be108efcf10a3509e4ea6ceef3c4"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-kit/kit"
|
||||
packages = [
|
||||
"log",
|
||||
"log/level",
|
||||
"log/term",
|
||||
"metrics",
|
||||
"metrics/discard",
|
||||
"metrics/internal/lv",
|
||||
"metrics/prometheus"
|
||||
]
|
||||
revision = "4dc7be5d2d12881735283bcab7352178e190fc71"
|
||||
version = "v0.6.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-logfmt/logfmt"
|
||||
packages = ["."]
|
||||
revision = "390ab7935ee28ec6b286364bba9b4dd6410cb3d5"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/go-stack/stack"
|
||||
packages = ["."]
|
||||
revision = "259ab82a6cad3992b4e21ff5cac294ccb06474bc"
|
||||
version = "v1.7.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gogo/protobuf"
|
||||
packages = [
|
||||
"gogoproto",
|
||||
"jsonpb",
|
||||
"proto",
|
||||
"protoc-gen-gogo/descriptor",
|
||||
"sortkeys",
|
||||
"types"
|
||||
]
|
||||
revision = "1adfc126b41513cc696b209667c8656ea7aac67c"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/golang/protobuf"
|
||||
packages = [
|
||||
"proto",
|
||||
"ptypes",
|
||||
"ptypes/any",
|
||||
"ptypes/duration",
|
||||
"ptypes/timestamp"
|
||||
]
|
||||
revision = "925541529c1fa6821df4e44ce2723319eb2be768"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/golang/snappy"
|
||||
packages = ["."]
|
||||
revision = "553a641470496b2327abcac10b36396bd98e45c9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/gorilla/websocket"
|
||||
packages = ["."]
|
||||
revision = "ea4d1f681babbce9545c9c5f3d5194a789c89f5b"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/jmhodges/levigo"
|
||||
packages = ["."]
|
||||
revision = "c42d9e0ca023e2198120196f842701bb4c55d7b9"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/kr/logfmt"
|
||||
packages = ["."]
|
||||
revision = "b84e30acd515aadc4b783ad4ff83aff3299bdfe0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/matttproud/golang_protobuf_extensions"
|
||||
packages = ["pbutil"]
|
||||
revision = "c12348ce28de40eed0136aa2b644d0ee0650e56c"
|
||||
version = "v1.0.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/pkg/errors"
|
||||
packages = ["."]
|
||||
revision = "645ef00459ed84a119197bfb8d8205042c6df63d"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/prometheus/client_golang"
|
||||
packages = [
|
||||
"prometheus",
|
||||
"prometheus/promhttp"
|
||||
]
|
||||
revision = "c5b7fccd204277076155f10851dad72b76a49317"
|
||||
version = "v0.8.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/prometheus/client_model"
|
||||
packages = ["go"]
|
||||
revision = "99fa1f4be8e564e8a6b613da7fa6f46c9edafc6c"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/prometheus/common"
|
||||
packages = [
|
||||
"expfmt",
|
||||
"internal/bitbucket.org/ww/goautoneg",
|
||||
"model"
|
||||
]
|
||||
revision = "7600349dcfe1abd18d72d3a1770870d9800a7801"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/prometheus/procfs"
|
||||
packages = [
|
||||
".",
|
||||
"internal/util",
|
||||
"nfs",
|
||||
"xfs"
|
||||
]
|
||||
revision = "7d6f385de8bea29190f15ba9931442a0eaef9af7"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/rcrowley/go-metrics"
|
||||
packages = ["."]
|
||||
revision = "e2704e165165ec55d062f5919b4b29494e9fa790"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/syndtr/goleveldb"
|
||||
packages = [
|
||||
"leveldb",
|
||||
"leveldb/cache",
|
||||
"leveldb/comparer",
|
||||
"leveldb/errors",
|
||||
"leveldb/filter",
|
||||
"leveldb/iterator",
|
||||
"leveldb/journal",
|
||||
"leveldb/memdb",
|
||||
"leveldb/opt",
|
||||
"leveldb/storage",
|
||||
"leveldb/table",
|
||||
"leveldb/util"
|
||||
]
|
||||
revision = "ae970a0732be3a1f5311da86118d37b9f4bd2a5a"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "github.com/tendermint/ed25519"
|
||||
packages = [
|
||||
".",
|
||||
"edwards25519",
|
||||
"extra25519"
|
||||
]
|
||||
revision = "d8387025d2b9d158cf4efb07e7ebf814bcce2057"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/tendermint/go-amino"
|
||||
packages = ["."]
|
||||
revision = "2106ca61d91029c931fd54968c2bb02dc96b1412"
|
||||
version = "0.10.1"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/tendermint/tendermint"
|
||||
packages = [
|
||||
"abci/client",
|
||||
"abci/example/code",
|
||||
"abci/example/kvstore",
|
||||
"abci/types",
|
||||
"blockchain",
|
||||
"config",
|
||||
"consensus",
|
||||
"consensus/types",
|
||||
"crypto",
|
||||
"crypto/tmhash",
|
||||
"evidence",
|
||||
"libs/events",
|
||||
"libs/pubsub",
|
||||
"libs/pubsub/query",
|
||||
"mempool",
|
||||
"node",
|
||||
"p2p",
|
||||
"p2p/conn",
|
||||
"p2p/pex",
|
||||
"p2p/upnp",
|
||||
"privval",
|
||||
"proxy",
|
||||
"rpc/client",
|
||||
"rpc/core",
|
||||
"rpc/core/types",
|
||||
"rpc/grpc",
|
||||
"rpc/lib",
|
||||
"rpc/lib/client",
|
||||
"rpc/lib/server",
|
||||
"rpc/lib/types",
|
||||
"state",
|
||||
"state/txindex",
|
||||
"state/txindex/kv",
|
||||
"state/txindex/null",
|
||||
"types",
|
||||
"version"
|
||||
]
|
||||
revision = "aa20c45ae99bb57a8efa2be7b09898e8967d1965"
|
||||
version = "v0.21.1-rc1"
|
||||
|
||||
[[projects]]
|
||||
branch = "develop"
|
||||
name = "github.com/tendermint/tmlibs"
|
||||
packages = [
|
||||
"autofile",
|
||||
"clist",
|
||||
"common",
|
||||
"db",
|
||||
"flowrate",
|
||||
"log",
|
||||
"merkle",
|
||||
"merkle/tmhash"
|
||||
]
|
||||
revision = "56f44670ebd5a4e99e55f3f7d6f4d360ef5f1973"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = [
|
||||
"curve25519",
|
||||
"nacl/box",
|
||||
"nacl/secretbox",
|
||||
"openpgp/armor",
|
||||
"openpgp/errors",
|
||||
"poly1305",
|
||||
"ripemd160",
|
||||
"salsa20/salsa"
|
||||
]
|
||||
revision = "1f94bef427e370e425e55b172f3b5e300ef38304"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/net"
|
||||
packages = [
|
||||
"context",
|
||||
"http/httpguts",
|
||||
"http2",
|
||||
"http2/hpack",
|
||||
"idna",
|
||||
"internal/timeseries",
|
||||
"lex/httplex",
|
||||
"netutil",
|
||||
"trace"
|
||||
]
|
||||
revision = "640f4622ab692b87c2f3a94265e6f579fe38263d"
|
||||
|
||||
[[projects]]
|
||||
name = "golang.org/x/text"
|
||||
packages = [
|
||||
"collate",
|
||||
"collate/build",
|
||||
"internal/colltab",
|
||||
"internal/gen",
|
||||
"internal/tag",
|
||||
"internal/triegen",
|
||||
"internal/ucd",
|
||||
"language",
|
||||
"secure/bidirule",
|
||||
"transform",
|
||||
"unicode/bidi",
|
||||
"unicode/cldr",
|
||||
"unicode/norm",
|
||||
"unicode/rangetable"
|
||||
]
|
||||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "google.golang.org/genproto"
|
||||
packages = ["googleapis/rpc/status"]
|
||||
revision = "86e600f69ee4704c6efbf6a2a40a5c10700e76c2"
|
||||
|
||||
[[projects]]
|
||||
name = "google.golang.org/grpc"
|
||||
packages = [
|
||||
".",
|
||||
"balancer",
|
||||
"codes",
|
||||
"connectivity",
|
||||
"credentials",
|
||||
"grpclb/grpc_lb_v1/messages",
|
||||
"grpclog",
|
||||
"internal",
|
||||
"keepalive",
|
||||
"metadata",
|
||||
"naming",
|
||||
"peer",
|
||||
"resolver",
|
||||
"stats",
|
||||
"status",
|
||||
"tap",
|
||||
"transport"
|
||||
]
|
||||
revision = "5b3c4e850e90a4cf6a20ebd46c8b32a0a3afcb9e"
|
||||
version = "v1.7.5"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "65c380641dcebca21a6343c9ea36bab5cbebff696e27c74d0735077f63272248"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
54
tools/tm-bench/Gopkg.toml
Normal file
54
tools/tm-bench/Gopkg.toml
Normal file
@ -0,0 +1,54 @@
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://golang.github.io/dep/docs/Gopkg.toml.html
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
#
|
||||
# [prune]
|
||||
# non-go = false
|
||||
# go-tests = true
|
||||
# unused-packages = true
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/go-kit/kit"
|
||||
version = "^0.6.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/gorilla/websocket"
|
||||
version = "^1.2.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/pkg/errors"
|
||||
version = "^0.8.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/rcrowley/go-metrics"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/tendermint/tendermint"
|
||||
branch = "develop"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/tendermint/tmlibs"
|
||||
branch = "develop"
|
||||
|
||||
[prune]
|
||||
go-tests = true
|
||||
unused-packages = true
|
204
tools/tm-bench/LICENSE
Normal file
204
tools/tm-bench/LICENSE
Normal file
@ -0,0 +1,204 @@
|
||||
Tendermint Bench
|
||||
Copyright 2017 Tendermint
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
116
tools/tm-bench/Makefile
Normal file
116
tools/tm-bench/Makefile
Normal file
@ -0,0 +1,116 @@
|
||||
DIST_DIRS := find * -type d -exec
|
||||
VERSION := $(shell perl -ne '/^var version.*"([^"]+)".*$$/ && print "v$$1\n"' main.go)
|
||||
GOTOOLS = \
|
||||
github.com/mitchellh/gox \
|
||||
github.com/golang/dep/cmd/dep \
|
||||
gopkg.in/alecthomas/gometalinter.v2
|
||||
|
||||
all: check get_vendor_deps build test install metalinter
|
||||
|
||||
check: check_tools
|
||||
|
||||
########################################
|
||||
### Tools & dependencies
|
||||
|
||||
check_tools:
|
||||
@# https://stackoverflow.com/a/25668869
|
||||
@echo "Found tools: $(foreach tool,$(GOTOOLS_CHECK),\
|
||||
$(if $(shell which $(tool)),$(tool),$(error "No $(tool) in PATH")))"
|
||||
|
||||
get_tools:
|
||||
@echo "--> Installing tools"
|
||||
go get -u -v $(GOTOOLS)
|
||||
@gometalinter.v2 --install
|
||||
|
||||
update_tools:
|
||||
@echo "--> Updating tools"
|
||||
@go get -u $(GOTOOLS)
|
||||
|
||||
get_vendor_deps:
|
||||
@rm -rf vendor/
|
||||
@echo "--> Running dep ensure"
|
||||
@dep ensure
|
||||
|
||||
########################################
|
||||
### Build
|
||||
|
||||
build:
|
||||
@go build
|
||||
|
||||
install:
|
||||
@go install
|
||||
|
||||
test:
|
||||
@go test -race
|
||||
|
||||
build-all: check_tools
|
||||
rm -rf ./dist
|
||||
gox -verbose \
|
||||
-ldflags "-s -w" \
|
||||
-arch="amd64 386 arm arm64" \
|
||||
-os="linux darwin windows freebsd" \
|
||||
-osarch="!darwin/arm !darwin/arm64" \
|
||||
-output="dist/{{.OS}}-{{.Arch}}/{{.Dir}}" .
|
||||
|
||||
dist: build-all
|
||||
cd dist && \
|
||||
$(DIST_DIRS) cp ../LICENSE {} \; && \
|
||||
$(DIST_DIRS) cp ../README.rst {} \; && \
|
||||
$(DIST_DIRS) tar -zcf tm-bench-${VERSION}-{}.tar.gz {} \; && \
|
||||
shasum -a256 ./*.tar.gz > "./tm-bench_${VERSION}_SHA256SUMS" && \
|
||||
cd ..
|
||||
|
||||
########################################
|
||||
### Docker
|
||||
|
||||
build-docker:
|
||||
rm -f ./tm-bench
|
||||
docker run -it --rm -v "$(PWD):/go/src/app" -w "/go/src/app" -e "CGO_ENABLED=0" golang:alpine go build -ldflags "-s -w" -o tm-bench
|
||||
docker build -t "tendermint/bench" .
|
||||
|
||||
clean:
|
||||
rm -f ./tm-bench
|
||||
rm -rf ./dist
|
||||
|
||||
########################################
|
||||
### Formatting, linting, and vetting
|
||||
|
||||
fmt:
|
||||
@go fmt ./...
|
||||
|
||||
metalinter:
|
||||
@echo "==> Running linter"
|
||||
gometalinter.v2 --vendor --deadline=600s --disable-all \
|
||||
--enable=maligned \
|
||||
--enable=deadcode \
|
||||
--enable=goconst \
|
||||
--enable=goimports \
|
||||
--enable=gosimple \
|
||||
--enable=ineffassign \
|
||||
--enable=megacheck \
|
||||
--enable=misspell \
|
||||
--enable=staticcheck \
|
||||
--enable=safesql \
|
||||
--enable=structcheck \
|
||||
--enable=unconvert \
|
||||
--enable=unused \
|
||||
--enable=varcheck \
|
||||
--enable=vetshadow \
|
||||
./...
|
||||
#--enable=gas \
|
||||
#--enable=dupl \
|
||||
#--enable=errcheck \
|
||||
#--enable=gocyclo \
|
||||
#--enable=golint \ <== comments on anything exported
|
||||
#--enable=gotype \
|
||||
#--enable=interfacer \
|
||||
#--enable=unparam \
|
||||
#--enable=vet \
|
||||
|
||||
metalinter_all:
|
||||
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
|
||||
|
||||
# To avoid unintended conflicts with file names, always add to .PHONY
|
||||
# unless there is a reason not to.
|
||||
# https://www.gnu.org/software/make/manual/html_node/Phony-Targets.html
|
||||
.PHONY: check check_tools get_tools update_tools get_vendor_deps build install test build-all dist fmt metalinter metalinter_all build-docker clean
|
69
tools/tm-bench/README.md
Normal file
69
tools/tm-bench/README.md
Normal file
@ -0,0 +1,69 @@
|
||||
# tm-bench
|
||||
|
||||
Tendermint blockchain benchmarking tool:
|
||||
|
||||
- https://github.com/tendermint/tools/tree/master/tm-bench
|
||||
|
||||
For example, the following:
|
||||
|
||||
tm-bench -T 10 -r 1000 localhost:26657
|
||||
|
||||
will output:
|
||||
|
||||
Stats Avg StdDev Max Total
|
||||
Txs/sec 818 532 1549 9000
|
||||
Blocks/sec 0.818 0.386 1 9
|
||||
|
||||
|
||||
## Quick Start
|
||||
|
||||
[Install Tendermint](https://github.com/tendermint/tendermint#install)
|
||||
This currently is setup to work on tendermint's develop branch. Please ensure
|
||||
you are on that. (If not, update `tendermint` and `tmlibs` in gopkg.toml to use
|
||||
the master branch.)
|
||||
|
||||
then run:
|
||||
|
||||
tendermint init
|
||||
tendermint node --proxy_app=kvstore
|
||||
|
||||
tm-bench localhost:26657
|
||||
|
||||
with the last command being in a seperate window.
|
||||
|
||||
## Usage
|
||||
|
||||
tm-bench [-c 1] [-T 10] [-r 1000] [-s 250] [endpoints]
|
||||
|
||||
Examples:
|
||||
tm-bench localhost:26657
|
||||
Flags:
|
||||
-T int
|
||||
Exit after the specified amount of time in seconds (default 10)
|
||||
-c int
|
||||
Connections to keep open per endpoint (default 1)
|
||||
-r int
|
||||
Txs per second to send in a connection (default 1000)
|
||||
-s int
|
||||
Size per tx in bytes
|
||||
-v Verbose output
|
||||
|
||||
## How stats are collected
|
||||
|
||||
These stats are derived by having each connection send transactions at the
|
||||
specified rate (or as close as it can get) for the specified time. After the
|
||||
specified time, it iterates over all of the blocks that were created in that
|
||||
time. The average and stddev per second are computed based off of that, by
|
||||
grouping the data by second.
|
||||
|
||||
To send transactions at the specified rate in each connection, we loop
|
||||
through the number of transactions. If its too slow, the loop stops at one second.
|
||||
If its too fast, we wait until the one second mark ends. The transactions per
|
||||
second stat is computed based off of what ends up in the block.
|
||||
|
||||
Each of the connections is handled via two separate goroutines.
|
||||
|
||||
## Development
|
||||
|
||||
make get_vendor_deps
|
||||
make test
|
18
tools/tm-bench/bench_test.go
Normal file
18
tools/tm-bench/bench_test.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func BenchmarkTimingPerTx(b *testing.B) {
|
||||
startTime := time.Now()
|
||||
endTime := startTime.Add(time.Second)
|
||||
for i := 0; i < b.N; i++ {
|
||||
if i%20 == 0 {
|
||||
if time.Now().After(endTime) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
300
tools/tm-bench/main.go
Normal file
300
tools/tm-bench/main.go
Normal file
@ -0,0 +1,300 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"flag"
|
||||
"fmt"
|
||||
"math"
|
||||
"os"
|
||||
"strings"
|
||||
"text/tabwriter"
|
||||
"time"
|
||||
|
||||
"github.com/go-kit/kit/log/term"
|
||||
metrics "github.com/rcrowley/go-metrics"
|
||||
tmrpc "github.com/tendermint/tendermint/rpc/client"
|
||||
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
var version = "0.3.0"
|
||||
|
||||
var logger = log.NewNopLogger()
|
||||
|
||||
type statistics struct {
|
||||
TxsThroughput metrics.Histogram `json:"txs_per_sec"`
|
||||
BlocksThroughput metrics.Histogram `json:"blocks_per_sec"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
var duration, txsRate, connections, txSize int
|
||||
var verbose bool
|
||||
var outputFormat, broadcastTxMethod string
|
||||
|
||||
flag.IntVar(&connections, "c", 1, "Connections to keep open per endpoint")
|
||||
flag.IntVar(&duration, "T", 10, "Exit after the specified amount of time in seconds")
|
||||
flag.IntVar(&txsRate, "r", 1000, "Txs per second to send in a connection")
|
||||
flag.IntVar(&txSize, "s", 250, "The size of a transaction in bytes.")
|
||||
flag.StringVar(&outputFormat, "output-format", "plain", "Output format: plain or json")
|
||||
flag.StringVar(&broadcastTxMethod, "broadcast-tx-method", "async", "Broadcast method: async (no guarantees; fastest), sync (ensures tx is checked) or commit (ensures tx is checked and committed; slowest)")
|
||||
flag.BoolVar(&verbose, "v", false, "Verbose output")
|
||||
|
||||
flag.Usage = func() {
|
||||
fmt.Println(`Tendermint blockchain benchmarking tool.
|
||||
|
||||
Usage:
|
||||
tm-bench [-c 1] [-T 10] [-r 1000] [endpoints] [-output-format <plain|json> [-broadcast-tx-method <async|sync|commit>]]
|
||||
|
||||
Examples:
|
||||
tm-bench localhost:26657`)
|
||||
fmt.Println("Flags:")
|
||||
flag.PrintDefaults()
|
||||
}
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if flag.NArg() == 0 {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if verbose {
|
||||
if outputFormat == "json" {
|
||||
fmt.Fprintln(os.Stderr, "Verbose mode not supported with json output.")
|
||||
os.Exit(1)
|
||||
}
|
||||
// Color errors red
|
||||
colorFn := func(keyvals ...interface{}) term.FgBgColor {
|
||||
for i := 1; i < len(keyvals); i += 2 {
|
||||
if _, ok := keyvals[i].(error); ok {
|
||||
return term.FgBgColor{Fg: term.White, Bg: term.Red}
|
||||
}
|
||||
}
|
||||
return term.FgBgColor{}
|
||||
}
|
||||
logger = log.NewTMLoggerWithColorFn(log.NewSyncWriter(os.Stdout), colorFn)
|
||||
|
||||
fmt.Printf("Running %ds test @ %s\n", duration, flag.Arg(0))
|
||||
}
|
||||
|
||||
if broadcastTxMethod != "async" &&
|
||||
broadcastTxMethod != "sync" &&
|
||||
broadcastTxMethod != "commit" {
|
||||
fmt.Fprintln(
|
||||
os.Stderr,
|
||||
"broadcast-tx-method should be either 'sync', 'async' or 'commit'.",
|
||||
)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
var (
|
||||
endpoints = strings.Split(flag.Arg(0), ",")
|
||||
client = tmrpc.NewHTTP(endpoints[0], "/websocket")
|
||||
initialHeight = latestBlockHeight(client)
|
||||
)
|
||||
logger.Info("Latest block height", "h", initialHeight)
|
||||
|
||||
// record time start
|
||||
timeStart := time.Now()
|
||||
logger.Info("Time started", "t", timeStart)
|
||||
|
||||
transacters := startTransacters(
|
||||
endpoints,
|
||||
connections,
|
||||
txsRate,
|
||||
txSize,
|
||||
"broadcast_tx_"+broadcastTxMethod,
|
||||
)
|
||||
endTime := time.Duration(duration) * time.Second
|
||||
select {
|
||||
case <-time.After(endTime):
|
||||
for i, t := range transacters {
|
||||
t.Stop()
|
||||
numCrashes := countCrashes(t.connsBroken)
|
||||
if numCrashes != 0 {
|
||||
fmt.Printf("%d connections crashed on transacter #%d\n", numCrashes, i)
|
||||
}
|
||||
}
|
||||
|
||||
timeStop := time.Now()
|
||||
logger.Info("Time stopped", "t", timeStop)
|
||||
|
||||
stats, err := calculateStatistics(
|
||||
client,
|
||||
initialHeight,
|
||||
timeStart,
|
||||
timeStop,
|
||||
duration,
|
||||
)
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
printStatistics(stats, outputFormat)
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
func latestBlockHeight(client tmrpc.Client) int64 {
|
||||
status, err := client.Status()
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
return status.SyncInfo.LatestBlockHeight
|
||||
}
|
||||
|
||||
func countCrashes(crashes []bool) int {
|
||||
count := 0
|
||||
for i := 0; i < len(crashes); i++ {
|
||||
if crashes[i] {
|
||||
count++
|
||||
}
|
||||
}
|
||||
return count
|
||||
}
|
||||
|
||||
// calculateStatistics calculates the tx / second, and blocks / second based
|
||||
// off of the number the transactions and number of blocks that occurred from
|
||||
// the start block, and the end time.
|
||||
func calculateStatistics(
|
||||
client tmrpc.Client,
|
||||
minHeight int64,
|
||||
timeStart, timeStop time.Time,
|
||||
duration int,
|
||||
) (*statistics, error) {
|
||||
stats := &statistics{
|
||||
BlocksThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)),
|
||||
TxsThroughput: metrics.NewHistogram(metrics.NewUniformSample(1000)),
|
||||
}
|
||||
|
||||
// get blocks between minHeight and last height
|
||||
// This returns max(minHeight,(last_height - 20)) to last_height
|
||||
info, err := client.BlockchainInfo(minHeight, 0)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var (
|
||||
blockMetas = info.BlockMetas
|
||||
lastHeight = info.LastHeight
|
||||
diff = lastHeight - minHeight
|
||||
offset = len(blockMetas)
|
||||
)
|
||||
|
||||
for offset < int(diff) {
|
||||
// get blocks between minHeight and last height
|
||||
info, err := client.BlockchainInfo(minHeight, lastHeight-int64(offset))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
blockMetas = append(blockMetas, info.BlockMetas...)
|
||||
offset = len(blockMetas)
|
||||
}
|
||||
|
||||
var (
|
||||
numBlocksPerSec = make(map[int64]int64)
|
||||
numTxsPerSec = make(map[int64]int64)
|
||||
)
|
||||
|
||||
// because during some seconds blocks won't be created...
|
||||
for i := int64(0); i < int64(duration); i++ {
|
||||
numBlocksPerSec[i] = 0
|
||||
numTxsPerSec[i] = 0
|
||||
}
|
||||
|
||||
// iterates from max height to min height
|
||||
for _, blockMeta := range blockMetas {
|
||||
// check if block was created after timeStart
|
||||
if blockMeta.Header.Time.Before(timeStart) {
|
||||
break
|
||||
}
|
||||
|
||||
// check if block was created before timeStop
|
||||
if blockMeta.Header.Time.After(timeStop) {
|
||||
continue
|
||||
}
|
||||
sec := secondsSinceTimeStart(timeStart, blockMeta.Header.Time)
|
||||
|
||||
// increase number of blocks for that second
|
||||
numBlocksPerSec[sec]++
|
||||
|
||||
// increase number of txs for that second
|
||||
numTxsPerSec[sec] += blockMeta.Header.NumTxs
|
||||
}
|
||||
|
||||
for _, n := range numBlocksPerSec {
|
||||
stats.BlocksThroughput.Update(n)
|
||||
}
|
||||
|
||||
for _, n := range numTxsPerSec {
|
||||
stats.TxsThroughput.Update(n)
|
||||
}
|
||||
|
||||
return stats, nil
|
||||
}
|
||||
|
||||
func secondsSinceTimeStart(timeStart, timePassed time.Time) int64 {
|
||||
return int64(math.Round(timePassed.Sub(timeStart).Seconds()))
|
||||
}
|
||||
|
||||
func startTransacters(
|
||||
endpoints []string,
|
||||
connections,
|
||||
txsRate int,
|
||||
txSize int,
|
||||
broadcastTxMethod string,
|
||||
) []*transacter {
|
||||
transacters := make([]*transacter, len(endpoints))
|
||||
|
||||
for i, e := range endpoints {
|
||||
t := newTransacter(e, connections, txsRate, txSize, broadcastTxMethod)
|
||||
t.SetLogger(logger)
|
||||
if err := t.Start(); err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
transacters[i] = t
|
||||
}
|
||||
|
||||
return transacters
|
||||
}
|
||||
|
||||
func printStatistics(stats *statistics, outputFormat string) {
|
||||
if outputFormat == "json" {
|
||||
result, err := json.Marshal(struct {
|
||||
TxsThroughput float64 `json:"txs_per_sec_avg"`
|
||||
BlocksThroughput float64 `json:"blocks_per_sec_avg"`
|
||||
}{stats.TxsThroughput.Mean(), stats.BlocksThroughput.Mean()})
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Println(string(result))
|
||||
} else {
|
||||
w := tabwriter.NewWriter(os.Stdout, 0, 0, 5, ' ', 0)
|
||||
fmt.Fprintln(w, "Stats\tAvg\tStdDev\tMax\tTotal\t")
|
||||
fmt.Fprintln(
|
||||
w,
|
||||
fmt.Sprintf(
|
||||
"Txs/sec\t%.0f\t%.0f\t%d\t%d\t",
|
||||
stats.TxsThroughput.Mean(),
|
||||
stats.TxsThroughput.StdDev(),
|
||||
stats.TxsThroughput.Max(),
|
||||
stats.TxsThroughput.Sum(),
|
||||
),
|
||||
)
|
||||
fmt.Fprintln(
|
||||
w,
|
||||
fmt.Sprintf("Blocks/sec\t%.3f\t%.3f\t%d\t%d\t",
|
||||
stats.BlocksThroughput.Mean(),
|
||||
stats.BlocksThroughput.StdDev(),
|
||||
stats.BlocksThroughput.Max(),
|
||||
stats.BlocksThroughput.Sum(),
|
||||
),
|
||||
)
|
||||
w.Flush()
|
||||
}
|
||||
}
|
252
tools/tm-bench/transacter.go
Normal file
252
tools/tm-bench/transacter.go
Normal file
@ -0,0 +1,252 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/binary"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/pkg/errors"
|
||||
rpctypes "github.com/tendermint/tendermint/rpc/lib/types"
|
||||
|
||||
"github.com/tendermint/tmlibs/log"
|
||||
)
|
||||
|
||||
const (
|
||||
sendTimeout = 10 * time.Second
|
||||
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
|
||||
pingPeriod = (30 * 9 / 10) * time.Second
|
||||
)
|
||||
|
||||
type transacter struct {
|
||||
Target string
|
||||
Rate int
|
||||
Size int
|
||||
Connections int
|
||||
BroadcastTxMethod string
|
||||
|
||||
conns []*websocket.Conn
|
||||
connsBroken []bool
|
||||
wg sync.WaitGroup
|
||||
stopped bool
|
||||
|
||||
logger log.Logger
|
||||
}
|
||||
|
||||
func newTransacter(target string, connections, rate int, size int, broadcastTxMethod string) *transacter {
|
||||
return &transacter{
|
||||
Target: target,
|
||||
Rate: rate,
|
||||
Size: size,
|
||||
Connections: connections,
|
||||
BroadcastTxMethod: broadcastTxMethod,
|
||||
conns: make([]*websocket.Conn, connections),
|
||||
connsBroken: make([]bool, connections),
|
||||
logger: log.NewNopLogger(),
|
||||
}
|
||||
}
|
||||
|
||||
// SetLogger lets you set your own logger
|
||||
func (t *transacter) SetLogger(l log.Logger) {
|
||||
t.logger = l
|
||||
}
|
||||
|
||||
// Start opens N = `t.Connections` connections to the target and creates read
|
||||
// and write goroutines for each connection.
|
||||
func (t *transacter) Start() error {
|
||||
t.stopped = false
|
||||
|
||||
rand.Seed(time.Now().Unix())
|
||||
|
||||
for i := 0; i < t.Connections; i++ {
|
||||
c, _, err := connect(t.Target)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
t.conns[i] = c
|
||||
}
|
||||
|
||||
t.wg.Add(2 * t.Connections)
|
||||
for i := 0; i < t.Connections; i++ {
|
||||
go t.sendLoop(i)
|
||||
go t.receiveLoop(i)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop closes the connections.
|
||||
func (t *transacter) Stop() {
|
||||
t.stopped = true
|
||||
t.wg.Wait()
|
||||
for _, c := range t.conns {
|
||||
c.Close()
|
||||
}
|
||||
}
|
||||
|
||||
// receiveLoop reads messages from the connection (empty in case of
|
||||
// `broadcast_tx_async`).
|
||||
func (t *transacter) receiveLoop(connIndex int) {
|
||||
c := t.conns[connIndex]
|
||||
defer t.wg.Done()
|
||||
for {
|
||||
_, _, err := c.ReadMessage()
|
||||
if err != nil {
|
||||
if !websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||
t.logger.Error(
|
||||
fmt.Sprintf("failed to read response on conn %d", connIndex),
|
||||
"err",
|
||||
err,
|
||||
)
|
||||
}
|
||||
return
|
||||
}
|
||||
if t.stopped || t.connsBroken[connIndex] {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sendLoop generates transactions at a given rate.
|
||||
func (t *transacter) sendLoop(connIndex int) {
|
||||
c := t.conns[connIndex]
|
||||
|
||||
c.SetPingHandler(func(message string) error {
|
||||
err := c.WriteControl(websocket.PongMessage, []byte(message), time.Now().Add(sendTimeout))
|
||||
if err == websocket.ErrCloseSent {
|
||||
return nil
|
||||
} else if e, ok := err.(net.Error); ok && e.Temporary() {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
})
|
||||
|
||||
logger := t.logger.With("addr", c.RemoteAddr())
|
||||
|
||||
var txNumber = 0
|
||||
|
||||
pingsTicker := time.NewTicker(pingPeriod)
|
||||
txsTicker := time.NewTicker(1 * time.Second)
|
||||
defer func() {
|
||||
pingsTicker.Stop()
|
||||
txsTicker.Stop()
|
||||
t.wg.Done()
|
||||
}()
|
||||
|
||||
// hash of the host name is a part of each tx
|
||||
var hostnameHash [md5.Size]byte
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
hostname = "127.0.0.1"
|
||||
}
|
||||
hostnameHash = md5.Sum([]byte(hostname))
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-txsTicker.C:
|
||||
startTime := time.Now()
|
||||
endTime := startTime.Add(time.Second)
|
||||
numTxSent := t.Rate
|
||||
|
||||
for i := 0; i < t.Rate; i++ {
|
||||
// each transaction embeds connection index, tx number and hash of the hostname
|
||||
tx := generateTx(connIndex, txNumber, t.Size, hostnameHash)
|
||||
paramsJSON, err := json.Marshal(map[string]interface{}{"tx": hex.EncodeToString(tx)})
|
||||
if err != nil {
|
||||
fmt.Printf("failed to encode params: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
rawParamsJSON := json.RawMessage(paramsJSON)
|
||||
|
||||
c.SetWriteDeadline(time.Now().Add(sendTimeout))
|
||||
err = c.WriteJSON(rpctypes.RPCRequest{
|
||||
JSONRPC: "2.0",
|
||||
ID: "tm-bench",
|
||||
Method: t.BroadcastTxMethod,
|
||||
Params: rawParamsJSON,
|
||||
})
|
||||
if err != nil {
|
||||
err = errors.Wrap(err,
|
||||
fmt.Sprintf("txs send failed on connection #%d", connIndex))
|
||||
t.connsBroken[connIndex] = true
|
||||
logger.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
// Time added here is 7.13 ns/op, not significant enough to worry about
|
||||
if i%20 == 0 {
|
||||
if time.Now().After(endTime) {
|
||||
// Plus one accounts for sending this tx
|
||||
numTxSent = i + 1
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
txNumber++
|
||||
}
|
||||
|
||||
timeToSend := time.Now().Sub(startTime)
|
||||
logger.Info(fmt.Sprintf("sent %d transactions", numTxSent), "took", timeToSend)
|
||||
if timeToSend < 1*time.Second {
|
||||
sleepTime := time.Second - timeToSend
|
||||
logger.Debug(fmt.Sprintf("connection #%d is sleeping for %f seconds", connIndex, sleepTime.Seconds()))
|
||||
time.Sleep(sleepTime)
|
||||
}
|
||||
|
||||
case <-pingsTicker.C:
|
||||
// go-rpc server closes the connection in the absence of pings
|
||||
c.SetWriteDeadline(time.Now().Add(sendTimeout))
|
||||
if err := c.WriteMessage(websocket.PingMessage, []byte{}); err != nil {
|
||||
err = errors.Wrap(err,
|
||||
fmt.Sprintf("failed to write ping message on conn #%d", connIndex))
|
||||
logger.Error(err.Error())
|
||||
t.connsBroken[connIndex] = true
|
||||
}
|
||||
}
|
||||
|
||||
if t.stopped {
|
||||
// To cleanly close a connection, a client should send a close
|
||||
// frame and wait for the server to close the connection.
|
||||
c.SetWriteDeadline(time.Now().Add(sendTimeout))
|
||||
err := c.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, ""))
|
||||
if err != nil {
|
||||
err = errors.Wrap(err,
|
||||
fmt.Sprintf("failed to write close message on conn #%d", connIndex))
|
||||
logger.Error(err.Error())
|
||||
t.connsBroken[connIndex] = true
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func connect(host string) (*websocket.Conn, *http.Response, error) {
|
||||
u := url.URL{Scheme: "ws", Host: host, Path: "/websocket"}
|
||||
return websocket.DefaultDialer.Dial(u.String(), nil)
|
||||
}
|
||||
|
||||
func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]byte) []byte {
|
||||
tx := make([]byte, txSize)
|
||||
|
||||
binary.PutUvarint(tx[:8], uint64(connIndex))
|
||||
binary.PutUvarint(tx[8:16], uint64(txNumber))
|
||||
copy(tx[16:32], hostnameHash[:16])
|
||||
binary.PutUvarint(tx[32:40], uint64(time.Now().Unix()))
|
||||
|
||||
// 40-* random data
|
||||
if _, err := rand.Read(tx[40:]); err != nil {
|
||||
panic(errors.Wrap(err, "failed to read random bytes"))
|
||||
}
|
||||
|
||||
return tx
|
||||
}
|
Reference in New Issue
Block a user