bench: rename functions

This commit is contained in:
Gyu-Ho Lee 2016-04-03 14:04:22 -07:00
parent 2f17ec2ee5
commit f0be55e7fc
5 changed files with 88 additions and 84 deletions

View File

@ -24,7 +24,7 @@ import (
var (
Command = &cobra.Command{
Use: "bench",
Short: "Low-level benchmark tool for etcd, Zookeeper, etcd2, consul.",
Short: "Low-level benchmark tool for etcdv2, etcdv3, Zookeeper, Consul.",
}
database string
@ -49,7 +49,7 @@ func init() {
}
func init() {
Command.PersistentFlags().StringVarP(&database, "database", "d", "etcd", "etcd, etcd2, zk, consul")
Command.PersistentFlags().StringVarP(&database, "database", "d", "etcdv3", "etcdv2, etcdv3, zk, consul")
Command.PersistentFlags().StringSliceVar(&endpoints, "endpoints", []string{"10.240.0.9:2181", "10.240.0.10:2181", "10.240.0.14:2181"}, "gRPC endpoints")
Command.PersistentFlags().UintVar(&totalConns, "conns", 1, "Total number of gRPC connections or Zookeeper connections")
Command.PersistentFlags().UintVar(&totalClients, "clients", 1, "Total number of gRPC clients (only for etcd)")

View File

@ -63,28 +63,6 @@ func init() {
putCmd.Flags().Int64Var(&etcdCompactionCycle, "etcd-compaction-cycle", 0, "Compact every X number of put requests. 0 means no compaction.")
}
type request struct {
etcdOp clientv3.Op
etcd2Op etcd2Op
zkOp zkOp
consulOp consulOp
}
type etcd2Op struct {
key string
value string
}
type zkOp struct {
key string
value []byte
}
type consulOp struct {
key string
value []byte
}
func putFunc(cmd *cobra.Command, args []string) {
if keySpaceSize <= 0 {
fmt.Fprintf(os.Stderr, "expected positive --key-space-size, got (%v)", keySpaceSize)
@ -103,11 +81,18 @@ func putFunc(cmd *cobra.Command, args []string) {
var etcdClients []*clientv3.Client
switch database {
case "etcd":
etcdClients = mustCreateClients(totalClients, totalConns)
case "etcdv2":
conns := mustCreateClientsEtcdv2(totalConns)
for i := range conns {
wg.Add(1)
go doPutEtcdv2(context.Background(), conns[i], requests)
}
case "etcdv3":
etcdClients = mustCreateClientsEtcdv3(totalClients, totalConns)
for i := range etcdClients {
wg.Add(1)
go doPut(context.Background(), etcdClients[i], requests)
go doPutEtcdv3(context.Background(), etcdClients[i], requests)
}
defer func() {
for i := range etcdClients {
@ -115,13 +100,6 @@ func putFunc(cmd *cobra.Command, args []string) {
}
}()
case "etcd2":
conns := mustCreateClientsEtcd2(totalConns)
for i := range conns {
wg.Add(1)
go doPutEtcd2(context.Background(), conns[i], requests)
}
case "zk":
conns := mustCreateConnsZk(totalConns)
defer func() {
@ -160,10 +138,10 @@ func putFunc(cmd *cobra.Command, args []string) {
k = keys[i]
}
switch database {
case "etcd":
requests <- request{etcdOp: clientv3.OpPut(string(k), v)}
case "etcd2":
requests <- request{etcd2Op: etcd2Op{key: string(k), value: v}}
case "etcdv2":
requests <- request{etcdv2Op: etcdv2Op{key: string(k), value: v}}
case "etcdv3":
requests <- request{etcdv3Op: clientv3.OpPut(string(k), v)}
case "zk":
requests <- request{zkOp: zkOp{key: "/" + string(k), value: []byte(v)}}
case "consul":
@ -179,15 +157,18 @@ func putFunc(cmd *cobra.Command, args []string) {
close(results)
<-pdoneC
// TODO: get total number of keys
}
func doPut(ctx context.Context, client clientv3.KV, requests <-chan request) {
func doPutEtcdv2(ctx context.Context, conn clientv2.KeysAPI, requests <-chan request) {
defer wg.Done()
for req := range requests {
op := req.etcdOp
op := req.etcdv2Op
st := time.Now()
_, err := client.Do(ctx, op)
_, err := conn.Set(context.Background(), op.key, op.value, nil)
var errStr string
if err != nil {
@ -198,14 +179,13 @@ func doPut(ctx context.Context, client clientv3.KV, requests <-chan request) {
}
}
func doPutEtcd2(ctx context.Context, conn clientv2.KeysAPI, requests <-chan request) {
func doPutEtcdv3(ctx context.Context, client clientv3.KV, requests <-chan request) {
defer wg.Done()
for req := range requests {
op := req.etcd2Op
op := req.etcdv3Op
st := time.Now()
_, err := conn.Set(context.Background(), op.key, op.value, nil)
_, err := client.Do(ctx, op)
var errStr string
if err != nil {

View File

@ -59,16 +59,16 @@ func rangeFunc(cmd *cobra.Command, args []string) {
v := randBytes(valSize)
vs := string(v)
switch database {
case "etcd":
fmt.Printf("PUT '%s' to etcd\n", k)
case "etcdv2":
fmt.Printf("PUT '%s' to etcdv2\n", k)
var err error
for i := 0; i < 5; i++ {
clients := mustCreateClients(1, 1)
_, err = clients[0].Do(context.Background(), clientv3.OpPut(k, vs))
clients := mustCreateClientsEtcdv2(totalConns)
_, err = clients[0].Set(context.Background(), k, vs, nil)
if err != nil {
continue
}
fmt.Printf("Done with PUT '%s' to etcd\n", k)
fmt.Printf("Done with PUT '%s' to etcdv2\n", k)
break
}
if err != nil {
@ -76,16 +76,16 @@ func rangeFunc(cmd *cobra.Command, args []string) {
os.Exit(1)
}
case "etcd2":
fmt.Printf("PUT '%s' to etcd2\n", k)
case "etcdv3":
fmt.Printf("PUT '%s' to etcd\n", k)
var err error
for i := 0; i < 5; i++ {
clients := mustCreateClientsEtcd2(totalConns)
_, err = clients[0].Set(context.Background(), k, vs, nil)
clients := mustCreateClientsEtcdv3(1, 1)
_, err = clients[0].Do(context.Background(), clientv3.OpPut(k, vs))
if err != nil {
continue
}
fmt.Printf("Done with PUT '%s' to etcd2\n", k)
fmt.Printf("Done with PUT '%s' to etcd\n", k)
break
}
if err != nil {
@ -141,7 +141,7 @@ func rangeFunc(cmd *cobra.Command, args []string) {
}
}
if database == "etcd" { // etcd2 quorum false by default
if database == "etcdv3" { // etcdv2 quorum false by default
if rangeConsistency == "l" {
fmt.Println("bench with linearizable range")
} else if rangeConsistency == "s" {
@ -162,11 +162,18 @@ func rangeFunc(cmd *cobra.Command, args []string) {
bar.Start()
switch database {
case "etcd":
clients := mustCreateClients(totalClients, totalConns)
case "etcdv2":
conns := mustCreateClientsEtcdv2(totalConns)
for i := range conns {
wg.Add(1)
go doRangeEtcdv2(conns[i], requests)
}
case "etcdv3":
clients := mustCreateClientsEtcdv3(totalClients, totalConns)
for i := range clients {
wg.Add(1)
go doRange(clients[i].KV, requests)
go doRangeEtcdv3(clients[i].KV, requests)
}
defer func() {
for i := range clients {
@ -174,13 +181,6 @@ func rangeFunc(cmd *cobra.Command, args []string) {
}
}()
case "etcd2":
conns := mustCreateClientsEtcd2(totalConns)
for i := range conns {
wg.Add(1)
go doRangeEtcd2(conns[i], requests)
}
case "zk":
conns := mustCreateConnsZk(totalConns)
defer func() {
@ -208,22 +208,23 @@ func rangeFunc(cmd *cobra.Command, args []string) {
go func() {
for i := 0; i < rangeTotal; i++ {
switch database {
case "etcd":
case "etcdv2":
// serializable read by default
requests <- request{etcdv2Op: etcdv2Op{key: k}}
case "etcdv3":
opts := []clientv3.OpOption{clientv3.WithRange(end)}
if rangeConsistency == "s" {
opts = append(opts, clientv3.WithSerializable())
}
requests <- request{etcdOp: clientv3.OpGet(k, opts...)}
// TODO: all below, serializable read by default
// make it configurable
case "etcd2":
requests <- request{etcd2Op: etcd2Op{key: k}}
requests <- request{etcdv3Op: clientv3.OpGet(k, opts...)}
case "zk":
// serializable read by default
requests <- request{zkOp: zkOp{key: k}}
case "consul":
// serializable read by default
requests <- request{consulOp: consulOp{key: k}}
}
}
@ -238,14 +239,14 @@ func rangeFunc(cmd *cobra.Command, args []string) {
<-pdoneC
}
func doRange(client clientv3.KV, requests <-chan request) {
func doRangeEtcdv2(conn clientv2.KeysAPI, requests <-chan request) {
defer wg.Done()
for req := range requests {
op := req.etcdOp
op := req.etcdv2Op
st := time.Now()
_, err := client.Do(context.Background(), op)
_, err := conn.Get(context.Background(), op.key, nil)
var errStr string
if err != nil {
@ -256,14 +257,14 @@ func doRange(client clientv3.KV, requests <-chan request) {
}
}
func doRangeEtcd2(conn clientv2.KeysAPI, requests <-chan request) {
func doRangeEtcdv3(client clientv3.KV, requests <-chan request) {
defer wg.Done()
for req := range requests {
op := req.etcd2Op
op := req.etcdv3Op
st := time.Now()
_, err := conn.Get(context.Background(), op.key, nil)
_, err := client.Do(context.Background(), op)
var errStr string
if err != nil {

View File

@ -30,13 +30,35 @@ import (
"github.com/samuel/go-zookeeper/zk"
)
type request struct {
etcdv2Op etcdv2Op
etcdv3Op clientv3.Op
zkOp zkOp
consulOp consulOp
}
type etcdv2Op struct {
key string
value string
}
type zkOp struct {
key string
value []byte
}
type consulOp struct {
key string
value []byte
}
var (
// dialTotal counts the number of mustCreateConn calls so that endpoint
// connections can be handed out in round-robin order
dialTotal int
)
func mustCreateConn() *clientv3.Client {
func mustCreateConnEtcdv3() *clientv3.Client {
endpoint := endpoints[dialTotal%len(endpoints)]
dialTotal++
cfg := clientv3.Config{Endpoints: []string{endpoint}}
@ -48,10 +70,10 @@ func mustCreateConn() *clientv3.Client {
return client
}
func mustCreateClients(totalClients, totalConns uint) []*clientv3.Client {
func mustCreateClientsEtcdv3(totalClients, totalConns uint) []*clientv3.Client {
conns := make([]*clientv3.Client, totalConns)
for i := range conns {
conns[i] = mustCreateConn()
conns[i] = mustCreateConnEtcdv3()
}
clients := make([]*clientv3.Client, totalClients)
@ -61,7 +83,7 @@ func mustCreateClients(totalClients, totalConns uint) []*clientv3.Client {
return clients
}
func mustCreateClientsEtcd2(total uint) []clientv2.KeysAPI {
func mustCreateClientsEtcdv2(total uint) []clientv2.KeysAPI {
cks := make([]clientv2.KeysAPI, total)
for i := range cks {
endpoint := endpoints[dialTotal%len(endpoints)]

View File

@ -20,10 +20,11 @@
// Available Commands:
// agent Database agent in remote servers.
// analyze Analyzes test results specific to dbtester.
// bench Low-level benchmark tool for etcd, Zookeeper, etcd2, consul.
// bench Low-level benchmark tool for etcdv2, etcdv3, Zookeeper, Consul.
// start Starts database through RPC calls.
// stop Stops database through RPC calls.
// restart Restarts database through RPC calls.
// script Generates cloud provisioning script.
// upload Uploads to cloud storage.
//
// Flags: