mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
benchmark: add rpc locks to stm benchmark
This commit is contained in:
parent
31e3899663
commit
6526097bfc
@ -23,6 +23,7 @@ import (
|
|||||||
|
|
||||||
v3 "github.com/coreos/etcd/clientv3"
|
v3 "github.com/coreos/etcd/clientv3"
|
||||||
v3sync "github.com/coreos/etcd/clientv3/concurrency"
|
v3sync "github.com/coreos/etcd/clientv3/concurrency"
|
||||||
|
"github.com/coreos/etcd/etcdserver/api/v3lock/v3lockpb"
|
||||||
"github.com/coreos/etcd/pkg/report"
|
"github.com/coreos/etcd/pkg/report"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -49,7 +50,7 @@ var (
|
|||||||
stmKeyCount int
|
stmKeyCount int
|
||||||
stmValSize int
|
stmValSize int
|
||||||
stmWritePercent int
|
stmWritePercent int
|
||||||
stmMutex bool
|
stmLocker string
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -60,7 +61,7 @@ func init() {
|
|||||||
stmCmd.Flags().IntVar(&stmTotal, "total", 10000, "Total number of completed STM transactions")
|
stmCmd.Flags().IntVar(&stmTotal, "total", 10000, "Total number of completed STM transactions")
|
||||||
stmCmd.Flags().IntVar(&stmKeysPerTxn, "keys-per-txn", 1, "Number of keys to access per transaction")
|
stmCmd.Flags().IntVar(&stmKeysPerTxn, "keys-per-txn", 1, "Number of keys to access per transaction")
|
||||||
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().BoolVar(&stmMutex, "use-mutex", false, "Wrap STM transaction in a distributed mutex")
|
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")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,23 +145,52 @@ func stmFunc(cmd *cobra.Command, args []string) {
|
|||||||
func doSTM(client *v3.Client, requests <-chan stmApply, results chan<- report.Result) {
|
func doSTM(client *v3.Client, requests <-chan stmApply, results chan<- report.Result) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
var m *v3sync.Mutex
|
lock, unlock := func() error { return nil }, func() error { return nil }
|
||||||
if stmMutex {
|
switch stmLocker {
|
||||||
|
case "lock-client":
|
||||||
s, err := v3sync.NewSession(client)
|
s, err := v3sync.NewSession(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
m = v3sync.NewMutex(s, "stmlock")
|
defer s.Close()
|
||||||
|
m := v3sync.NewMutex(s, "stmlock")
|
||||||
|
lock = func() error { return m.Lock(context.TODO()) }
|
||||||
|
unlock = func() error { return m.Unlock(context.TODO()) }
|
||||||
|
case "lock-rpc":
|
||||||
|
var lockKey []byte
|
||||||
|
s, err := v3sync.NewSession(client)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer s.Close()
|
||||||
|
lc := v3lockpb.NewLockClient(client.ActiveConnection())
|
||||||
|
lock = func() error {
|
||||||
|
req := &v3lockpb.LockRequest{Name: []byte("stmlock"), Lease: int64(s.Lease())}
|
||||||
|
resp, err := lc.Lock(context.TODO(), req)
|
||||||
|
if resp != nil {
|
||||||
|
lockKey = resp.Key
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
unlock = func() error {
|
||||||
|
req := &v3lockpb.UnlockRequest{Key: lockKey}
|
||||||
|
_, err := lc.Unlock(context.TODO(), req)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
case "stm":
|
||||||
|
default:
|
||||||
|
fmt.Fprintf(os.Stderr, "unexpected stm locker %q\n", stmLocker)
|
||||||
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
for applyf := range requests {
|
for applyf := range requests {
|
||||||
st := time.Now()
|
st := time.Now()
|
||||||
if m != nil {
|
if lerr := lock(); lerr != nil {
|
||||||
m.Lock(context.TODO())
|
panic(lerr)
|
||||||
}
|
}
|
||||||
_, err := v3sync.NewSTM(client, applyf, v3sync.WithIsolation(stmIso))
|
_, err := v3sync.NewSTM(client, applyf, v3sync.WithIsolation(stmIso))
|
||||||
if m != nil {
|
if lerr := unlock(); lerr != nil {
|
||||||
m.Unlock(context.TODO())
|
panic(lerr)
|
||||||
}
|
}
|
||||||
results <- report.Result{Err: err, Start: st, End: time.Now()}
|
results <- report.Result{Err: err, Start: st, End: time.Now()}
|
||||||
bar.Increment()
|
bar.Increment()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user