mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
benchmark: add rate limiting to stm
This commit is contained in:
parent
6526097bfc
commit
b6e4858a25
@ -17,6 +17,7 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"encoding/binary"
|
"encoding/binary"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
@ -28,6 +29,7 @@ import (
|
|||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
"gopkg.in/cheggaaa/pb.v1"
|
"gopkg.in/cheggaaa/pb.v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -51,6 +53,7 @@ var (
|
|||||||
stmValSize int
|
stmValSize int
|
||||||
stmWritePercent int
|
stmWritePercent int
|
||||||
stmLocker string
|
stmLocker string
|
||||||
|
stmRate int
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -63,6 +66,7 @@ func init() {
|
|||||||
stmCmd.Flags().IntVar(&stmWritePercent, "txn-wr-percent", 50, "Percentage of keys to overwrite per transaction")
|
stmCmd.Flags().IntVar(&stmWritePercent, "txn-wr-percent", 50, "Percentage of keys to overwrite per transaction")
|
||||||
stmCmd.Flags().StringVar(&stmLocker, "stm-locker", "stm", "Wrap STM transaction with a custom locking mechanism (stm, lock-client, lock-rpc)")
|
stmCmd.Flags().StringVar(&stmLocker, "stm-locker", "stm", "Wrap STM transaction with a custom locking mechanism (stm, lock-client, lock-rpc)")
|
||||||
stmCmd.Flags().IntVar(&stmValSize, "val-size", 8, "Value size of each STM put request")
|
stmCmd.Flags().IntVar(&stmValSize, "val-size", 8, "Value size of each STM put request")
|
||||||
|
stmCmd.Flags().IntVar(&stmRate, "rate", 0, "Maximum STM transactions per second (0 is no limit)")
|
||||||
}
|
}
|
||||||
|
|
||||||
func stmFunc(cmd *cobra.Command, args []string) {
|
func stmFunc(cmd *cobra.Command, args []string) {
|
||||||
@ -95,6 +99,11 @@ func stmFunc(cmd *cobra.Command, args []string) {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if stmRate == 0 {
|
||||||
|
stmRate = math.MaxInt32
|
||||||
|
}
|
||||||
|
limit := rate.NewLimiter(rate.Limit(stmRate), 1)
|
||||||
|
|
||||||
requests := make(chan stmApply, totalClients)
|
requests := make(chan stmApply, totalClients)
|
||||||
clients := mustCreateClients(totalClients, totalConns)
|
clients := mustCreateClients(totalClients, totalConns)
|
||||||
|
|
||||||
@ -119,6 +128,7 @@ func stmFunc(cmd *cobra.Command, args []string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
applyf := func(s v3sync.STM) error {
|
applyf := func(s v3sync.STM) error {
|
||||||
|
limit.Wait(context.Background())
|
||||||
wrs := int(float32(len(kset)*stmWritePercent) / 100.0)
|
wrs := int(float32(len(kset)*stmWritePercent) / 100.0)
|
||||||
for k := range kset {
|
for k := range kset {
|
||||||
s.Get(k)
|
s.Get(k)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user