From 99366c6b42788dbb001d8e462eb2a5cf17c33b1d Mon Sep 17 00:00:00 2001 From: Hitoshi Mitake Date: Fri, 28 Apr 2017 11:39:32 +0900 Subject: [PATCH] benchmark: a new option of mvcc --txn-ops for enlarging a single txn This commit adds a new option --txn-ops to `benchmark mvcc put`. A number specified with this option will be used as a number of written keys in a single transaction. It will be useful for checking the effect of the batching. --- tools/benchmark/cmd/mvcc-put.go | 42 +++++++++++++++++++++------------ tools/benchmark/cmd/util.go | 11 +++++++++ 2 files changed, 38 insertions(+), 15 deletions(-) diff --git a/tools/benchmark/cmd/mvcc-put.go b/tools/benchmark/cmd/mvcc-put.go index bebb13d8c..2bf482d1b 100644 --- a/tools/benchmark/cmd/mvcc-put.go +++ b/tools/benchmark/cmd/mvcc-put.go @@ -36,19 +36,21 @@ var mvccPutCmd = &cobra.Command{ } var ( - totalNrKeys int - storageKeySize int - valueSize int - txn bool + mvccTotalRequests int + storageKeySize int + valueSize int + txn bool + nrTxnOps int ) func init() { mvccCmd.AddCommand(mvccPutCmd) - mvccPutCmd.Flags().IntVar(&totalNrKeys, "total", 100, "a total number of keys to put") + mvccPutCmd.Flags().IntVar(&mvccTotalRequests, "total", 100, "a total number of keys to put") mvccPutCmd.Flags().IntVar(&storageKeySize, "key-size", 64, "a size of key (Byte)") mvccPutCmd.Flags().IntVar(&valueSize, "value-size", 64, "a size of value (Byte)") mvccPutCmd.Flags().BoolVar(&txn, "txn", false, "put a key in transaction or not") + mvccPutCmd.Flags().IntVar(&nrTxnOps, "txn-ops", 1, "a number of keys to put per transaction") // TODO: after the PR https://github.com/spf13/cobra/pull/220 is merged, the below pprof related flags should be moved to RootCmd mvccPutCmd.Flags().StringVar(&cpuProfPath, "cpuprofile", "", "the path of file for storing cpu profile result") @@ -99,23 +101,33 @@ func mvccPutFunc(cmd *cobra.Command, args []string) { }() } - keys := createBytesSlice(storageKeySize, totalNrKeys) - vals := createBytesSlice(valueSize, totalNrKeys) + keys := createBytesSlice(storageKeySize, mvccTotalRequests*nrTxnOps) + vals := createBytesSlice(valueSize, mvccTotalRequests*nrTxnOps) - r := newReport() + weight := float64(nrTxnOps) + r := newWeightedReport() rrc := r.Results() rc := r.Run() - for i := 0; i < totalNrKeys; i++ { - st := time.Now() - if txn { + + if txn { + for i := 0; i < mvccTotalRequests; i++ { + st := time.Now() + tw := s.Write() - tw.Put(keys[i], vals[i], lease.NoLease) + for j := i; j < i+nrTxnOps; j++ { + tw.Put(keys[j], vals[j], lease.NoLease) + } tw.End() - } else { - s.Put(keys[i], vals[i], lease.NoLease) + + rrc <- report.Result{Start: st, End: time.Now(), Weight: weight} + } + } else { + for i := 0; i < mvccTotalRequests; i++ { + st := time.Now() + s.Put(keys[i], vals[i], lease.NoLease) + rrc <- report.Result{Start: st, End: time.Now()} } - rrc <- report.Result{Start: st, End: time.Now()} } close(r.Results()) diff --git a/tools/benchmark/cmd/util.go b/tools/benchmark/cmd/util.go index 7775acce4..88969ed6f 100644 --- a/tools/benchmark/cmd/util.go +++ b/tools/benchmark/cmd/util.go @@ -142,3 +142,14 @@ func newReport() report.Report { } return report.NewReport(p) } + +func newWeightedReport() report.Report { + p := "%4.4f" + if precise { + p = "%g" + } + if sample { + return report.NewReportSample(p) + } + return report.NewWeightedReport(report.NewReport(p), p) +}