mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
tools/benchmark: use clientv3
This commit is contained in:
parent
9a5a3ebc79
commit
a7b6bbff3f
@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
|
||||||
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -67,22 +66,14 @@ func putFunc(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
k, v := make([]byte, keySize), mustRandBytes(valSize)
|
k, v := make([]byte, keySize), mustRandBytes(valSize)
|
||||||
|
|
||||||
conns := make([]*grpc.ClientConn, totalConns)
|
clients := mustCreateClients(totalClients, totalConns)
|
||||||
for i := range conns {
|
|
||||||
conns[i] = mustCreateConn()
|
|
||||||
}
|
|
||||||
|
|
||||||
clients := make([]etcdserverpb.KVClient, totalClients)
|
|
||||||
for i := range clients {
|
|
||||||
clients[i] = etcdserverpb.NewKVClient(conns[i%int(totalConns)])
|
|
||||||
}
|
|
||||||
|
|
||||||
bar.Format("Bom !")
|
bar.Format("Bom !")
|
||||||
bar.Start()
|
bar.Start()
|
||||||
|
|
||||||
for i := range clients {
|
for i := range clients {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go doPut(context.Background(), clients[i], requests)
|
go doPut(context.Background(), clients[i].KV, requests)
|
||||||
}
|
}
|
||||||
|
|
||||||
pdoneC := printReport(results)
|
pdoneC := printReport(results)
|
||||||
|
@ -22,7 +22,6 @@ import (
|
|||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
|
||||||
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
"github.com/coreos/etcd/etcdserver/etcdserverpb"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,22 +58,14 @@ func rangeFunc(cmd *cobra.Command, args []string) {
|
|||||||
requests := make(chan etcdserverpb.RangeRequest, totalClients)
|
requests := make(chan etcdserverpb.RangeRequest, totalClients)
|
||||||
bar = pb.New(rangeTotal)
|
bar = pb.New(rangeTotal)
|
||||||
|
|
||||||
conns := make([]*grpc.ClientConn, totalConns)
|
clients := mustCreateClients(totalClients, totalConns)
|
||||||
for i := range conns {
|
|
||||||
conns[i] = mustCreateConn()
|
|
||||||
}
|
|
||||||
|
|
||||||
clients := make([]etcdserverpb.KVClient, totalClients)
|
|
||||||
for i := range clients {
|
|
||||||
clients[i] = etcdserverpb.NewKVClient(conns[i%int(totalConns)])
|
|
||||||
}
|
|
||||||
|
|
||||||
bar.Format("Bom !")
|
bar.Format("Bom !")
|
||||||
bar.Start()
|
bar.Start()
|
||||||
|
|
||||||
for i := range clients {
|
for i := range clients {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go doRange(clients[i], requests)
|
go doRange(clients[i].KV, requests)
|
||||||
}
|
}
|
||||||
|
|
||||||
pdoneC := printReport(results)
|
pdoneC := printReport(results)
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
"github.com/coreos/etcd/clientv3"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -29,16 +29,29 @@ var (
|
|||||||
dialTotal int
|
dialTotal int
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustCreateConn() *grpc.ClientConn {
|
func mustCreateConn() *clientv3.Client {
|
||||||
eps := strings.Split(endpoints, ",")
|
eps := strings.Split(endpoints, ",")
|
||||||
endpoint := eps[dialTotal%len(eps)]
|
endpoint := eps[dialTotal%len(eps)]
|
||||||
dialTotal++
|
dialTotal++
|
||||||
conn, err := grpc.Dial(endpoint, grpc.WithInsecure())
|
client, err := clientv3.NewFromURL(endpoint)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "dial error: %v\n", err)
|
fmt.Fprintf(os.Stderr, "dial error: %v\n", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return conn
|
return client
|
||||||
|
}
|
||||||
|
|
||||||
|
func mustCreateClients(totalClients, totalConns uint) []*clientv3.Client {
|
||||||
|
conns := make([]*clientv3.Client, totalConns)
|
||||||
|
for i := range conns {
|
||||||
|
conns[i] = mustCreateConn()
|
||||||
|
}
|
||||||
|
|
||||||
|
clients := make([]*clientv3.Client, totalClients)
|
||||||
|
for i := range clients {
|
||||||
|
clients[i] = conns[i%int(totalConns)].Clone()
|
||||||
|
}
|
||||||
|
return clients
|
||||||
}
|
}
|
||||||
|
|
||||||
func mustRandBytes(n int) []byte {
|
func mustRandBytes(n int) []byte {
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/cheggaaa/pb"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
"github.com/coreos/etcd/Godeps/_workspace/src/github.com/spf13/cobra"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
"github.com/coreos/etcd/Godeps/_workspace/src/golang.org/x/net/context"
|
||||||
"github.com/coreos/etcd/Godeps/_workspace/src/google.golang.org/grpc"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// watchCmd represents the watch command
|
// watchCmd represents the watch command
|
||||||
@ -72,20 +71,12 @@ func watchFunc(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
requests := make(chan etcdserverpb.WatchRequest, totalClients)
|
requests := make(chan etcdserverpb.WatchRequest, totalClients)
|
||||||
|
|
||||||
conns := make([]*grpc.ClientConn, totalConns)
|
clients := mustCreateClients(totalClients, totalConns)
|
||||||
for i := range conns {
|
|
||||||
conns[i] = mustCreateConn()
|
|
||||||
}
|
|
||||||
|
|
||||||
clients := make([]etcdserverpb.WatchClient, totalClients)
|
|
||||||
for i := range clients {
|
|
||||||
clients[i] = etcdserverpb.NewWatchClient(conns[i%int(totalConns)])
|
|
||||||
}
|
|
||||||
|
|
||||||
streams := make([]etcdserverpb.Watch_WatchClient, watchTotalStreams)
|
streams := make([]etcdserverpb.Watch_WatchClient, watchTotalStreams)
|
||||||
var err error
|
var err error
|
||||||
for i := range streams {
|
for i := range streams {
|
||||||
streams[i], err = clients[i%int(totalClients)].Watch(context.TODO())
|
streams[i], err = clients[i%len(clients)].Watch.Watch(context.TODO())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintln(os.Stderr, "Failed to create watch stream:", err)
|
fmt.Fprintln(os.Stderr, "Failed to create watch stream:", err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
@ -124,7 +115,6 @@ func watchFunc(cmd *cobra.Command, args []string) {
|
|||||||
<-pdoneC
|
<-pdoneC
|
||||||
|
|
||||||
// put phase
|
// put phase
|
||||||
kv := etcdserverpb.NewKVClient(conns[0])
|
|
||||||
// total number of puts * number of watchers on each key
|
// total number of puts * number of watchers on each key
|
||||||
eventsTotal := watchPutTotal * (watchTotal / watchedKeyTotal)
|
eventsTotal := watchPutTotal * (watchTotal / watchedKeyTotal)
|
||||||
|
|
||||||
@ -138,7 +128,7 @@ func watchFunc(cmd *cobra.Command, args []string) {
|
|||||||
|
|
||||||
for i := 0; i < watchPutTotal; i++ {
|
for i := 0; i < watchPutTotal; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go doPut(context.TODO(), kv, putreqc)
|
go doPut(context.TODO(), clients[i%len(clients)].KV, putreqc)
|
||||||
}
|
}
|
||||||
|
|
||||||
pdoneC = printRate(results)
|
pdoneC = printRate(results)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user