Browse Source

tmbench: Make tx size configurable

* Make the parameter for tx size in bytes -s <size>, w/ default value 250
pull/1943/head
ValarDragon 6 years ago
committed by Anton Kaliaev
parent
commit
b7925cd34f
3 changed files with 13 additions and 9 deletions
  1. +3
    -1
      tm-bench/README.md
  2. +5
    -2
      tm-bench/main.go
  3. +5
    -6
      tm-bench/transacter.go

+ 3
- 1
tm-bench/README.md View File

@ -34,7 +34,7 @@ with the last command being in a seperate window.
## Usage
tm-bench [-c 1] [-T 10] [-r 1000] [endpoints]
tm-bench [-c 1] [-T 10] [-r 1000] [-s 250] [endpoints]
Examples:
tm-bench localhost:26657
@ -45,6 +45,8 @@ with the last command being in a seperate window.
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
## Development


+ 5
- 2
tm-bench/main.go View File

@ -27,13 +27,14 @@ type statistics struct {
}
func main() {
var duration, txsRate, connections int
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")
@ -101,6 +102,7 @@ Examples:
endpoints,
connections,
txsRate,
txSize,
"broadcast_tx_"+broadcastTxMethod,
)
@ -228,12 +230,13 @@ 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, broadcastTxMethod)
t := newTransacter(e, connections, txsRate, txSize, broadcastTxMethod)
t.SetLogger(logger)
if err := t.Start(); err != nil {
fmt.Fprintln(os.Stderr, err)


+ 5
- 6
tm-bench/transacter.go View File

@ -25,14 +25,12 @@ const (
sendTimeout = 10 * time.Second
// see https://github.com/tendermint/go-rpc/blob/develop/server/handlers.go#L313
pingPeriod = (30 * 9 / 10) * time.Second
// the size of a transaction in bytes.
txSize = 250
)
type transacter struct {
Target string
Rate int
Size int
Connections int
BroadcastTxMethod string
@ -43,10 +41,11 @@ type transacter struct {
logger log.Logger
}
func newTransacter(target string, connections, rate int, broadcastTxMethod string) *transacter {
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),
@ -152,7 +151,7 @@ func (t *transacter) sendLoop(connIndex int) {
for i := 0; i < t.Rate; i++ {
// each transaction embeds connection index, tx number and hash of the hostname
tx := generateTx(connIndex, txNumber, hostnameHash)
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)
@ -207,7 +206,7 @@ func connect(host string) (*websocket.Conn, *http.Response, error) {
return websocket.DefaultDialer.Dial(u.String(), nil)
}
func generateTx(connIndex int, txNumber int, hostnameHash [md5.Size]byte) []byte {
func generateTx(connIndex int, txNumber int, txSize int, hostnameHash [md5.Size]byte) []byte {
tx := make([]byte, txSize)
binary.PutUvarint(tx[:8], uint64(connIndex))


Loading…
Cancel
Save