From 40b66d1f1838ddfb926606ec7e925b0f00b2d6b9 Mon Sep 17 00:00:00 2001 From: "Sahdev P. Zala" Date: Tue, 19 Jun 2018 15:07:02 -0400 Subject: [PATCH 1/2] Etcdctl: benchmark for hashkv performance The benchmark as a sub command of put when provided will fetch hashkv and checks the time taken to get it. Fixed # 8910 Provider a way to etcd user to check how long it takes to get hashkv in user enviornment. The command ouput will provide time taken to get hashkv along with db file size. --- tools/benchmark/cmd/put.go | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tools/benchmark/cmd/put.go b/tools/benchmark/cmd/put.go index ff4373e2d..611572461 100644 --- a/tools/benchmark/cmd/put.go +++ b/tools/benchmark/cmd/put.go @@ -21,11 +21,13 @@ import ( "math" "math/rand" "os" + "strings" "time" v3 "github.com/coreos/etcd/clientv3" "github.com/coreos/etcd/pkg/report" + "github.com/dustin/go-humanize" "github.com/spf13/cobra" "golang.org/x/time/rate" "gopkg.in/cheggaaa/pb.v1" @@ -51,6 +53,8 @@ var ( compactInterval time.Duration compactIndexDelta int64 + + checkHashkv bool ) func init() { @@ -64,6 +68,7 @@ func init() { putCmd.Flags().BoolVar(&seqKeys, "sequential-keys", false, "Use sequential keys") putCmd.Flags().DurationVar(&compactInterval, "compact-interval", 0, `Interval to compact database (do not duplicate this with etcd's 'auto-compaction-retention' flag) (e.g. --compact-interval=5m compacts every 5-minute)`) putCmd.Flags().Int64Var(&compactIndexDelta, "compact-index-delta", 1000, "Delta between current revision and compact revision (e.g. current revision 10000, compact at 9000)") + putCmd.Flags().BoolVar(&checkHashkv, "check-hashkv", false, "Check hashkv") } func putFunc(cmd *cobra.Command, args []string) { @@ -126,6 +131,11 @@ func putFunc(cmd *cobra.Command, args []string) { close(r.Results()) bar.Finish() fmt.Println(<-rc) + + // Check hashkv + if checkHashkv { + hashKV(cmd, clients) + } } func compactKV(clients []*v3.Client) { @@ -150,3 +160,39 @@ func max(n1, n2 int64) int64 { } return n2 } + +func hashKV(cmd *cobra.Command, clients []*v3.Client) { + var epHashKVRev int64 + eps, err := cmd.Flags().GetStringSlice("endpoints") + if err != nil { + panic(err) + } + for i, ip := range eps { + eps[i] = strings.TrimSpace(ip) + } + st := time.Now() + var results string + ctx, cancel := context.WithCancel(context.Background()) + clients[0].HashKV(ctx, eps[0], epHashKVRev) + host := eps[0] + + resphash, errhash := clients[0].HashKV(ctx, host, epHashKVRev) + respstatus, errstatus := clients[0].Status(ctx, host) + cancel() + if errhash != nil { + fmt.Fprintf(os.Stderr, "Failed to get the hashkv of endpoint %s (%v)\n", host, errhash) + panic(err) + } + results += fmt.Sprintf("\nHaskKV Summary:\n") + results += fmt.Sprintf(" HashKV: %v\n", resphash.Hash) + results += fmt.Sprintf(" Endpoint: %v\n", host) + results += fmt.Sprintf(" Time taken to get hashkv: %v\n", time.Since(st).String()) + + // Get the db size + if errstatus != nil { + fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", host, errstatus) + panic(err) + } + results += fmt.Sprintf(" DB size: %s", humanize.Bytes(uint64(respstatus.DbSize))) + fmt.Println(results) +} From 18f85684da4fa983d60aa1e82e84496b4e60b763 Mon Sep 17 00:00:00 2001 From: Gyuho Lee Date: Mon, 13 Aug 2018 19:19:46 -0700 Subject: [PATCH 2/2] tools/benchmark: clean up formatting Signed-off-by: Gyuho Lee --- tools/benchmark/cmd/put.go | 40 ++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 23 deletions(-) diff --git a/tools/benchmark/cmd/put.go b/tools/benchmark/cmd/put.go index 611572461..3d61fefa6 100644 --- a/tools/benchmark/cmd/put.go +++ b/tools/benchmark/cmd/put.go @@ -68,7 +68,7 @@ func init() { putCmd.Flags().BoolVar(&seqKeys, "sequential-keys", false, "Use sequential keys") putCmd.Flags().DurationVar(&compactInterval, "compact-interval", 0, `Interval to compact database (do not duplicate this with etcd's 'auto-compaction-retention' flag) (e.g. --compact-interval=5m compacts every 5-minute)`) putCmd.Flags().Int64Var(&compactIndexDelta, "compact-index-delta", 1000, "Delta between current revision and compact revision (e.g. current revision 10000, compact at 9000)") - putCmd.Flags().BoolVar(&checkHashkv, "check-hashkv", false, "Check hashkv") + putCmd.Flags().BoolVar(&checkHashkv, "check-hashkv", false, "'true' to check hashkv") } func putFunc(cmd *cobra.Command, args []string) { @@ -132,7 +132,6 @@ func putFunc(cmd *cobra.Command, args []string) { bar.Finish() fmt.Println(<-rc) - // Check hashkv if checkHashkv { hashKV(cmd, clients) } @@ -162,7 +161,6 @@ func max(n1, n2 int64) int64 { } func hashKV(cmd *cobra.Command, clients []*v3.Client) { - var epHashKVRev int64 eps, err := cmd.Flags().GetStringSlice("endpoints") if err != nil { panic(err) @@ -170,29 +168,25 @@ func hashKV(cmd *cobra.Command, clients []*v3.Client) { for i, ip := range eps { eps[i] = strings.TrimSpace(ip) } - st := time.Now() - var results string - ctx, cancel := context.WithCancel(context.Background()) - clients[0].HashKV(ctx, eps[0], epHashKVRev) host := eps[0] - resphash, errhash := clients[0].HashKV(ctx, host, epHashKVRev) - respstatus, errstatus := clients[0].Status(ctx, host) - cancel() - if errhash != nil { - fmt.Fprintf(os.Stderr, "Failed to get the hashkv of endpoint %s (%v)\n", host, errhash) + st := time.Now() + clients[0].HashKV(context.Background(), eps[0], 0) + rh, eh := clients[0].HashKV(context.Background(), host, 0) + if eh != nil { + fmt.Fprintf(os.Stderr, "Failed to get the hashkv of endpoint %s (%v)\n", host, eh) + panic(err) + } + rt, es := clients[0].Status(context.Background(), host) + if es != nil { + fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", host, es) panic(err) } - results += fmt.Sprintf("\nHaskKV Summary:\n") - results += fmt.Sprintf(" HashKV: %v\n", resphash.Hash) - results += fmt.Sprintf(" Endpoint: %v\n", host) - results += fmt.Sprintf(" Time taken to get hashkv: %v\n", time.Since(st).String()) - // Get the db size - if errstatus != nil { - fmt.Fprintf(os.Stderr, "Failed to get the status of endpoint %s (%v)\n", host, errstatus) - panic(err) - } - results += fmt.Sprintf(" DB size: %s", humanize.Bytes(uint64(respstatus.DbSize))) - fmt.Println(results) + rs := "HaskKV Summary:\n" + rs += fmt.Sprintf("\tHashKV: %d\n", rh.Hash) + rs += fmt.Sprintf("\tEndpoint: %s\n", host) + rs += fmt.Sprintf("\tTime taken to get hashkv: %v\n", time.Since(st)) + rs += fmt.Sprintf("\tDB size: %s", humanize.Bytes(uint64(rt.DbSize))) + fmt.Println(rs) }