Skip to content

Commit

Permalink
Merge pull request #7141 from heyitsanthony/rate-limit-range
Browse files Browse the repository at this point in the history
benchmark: option to rate limit range benchmark
  • Loading branch information
Anthony Romano authored Jan 11, 2017
2 parents 43dd751 + 6e730af commit 0df543d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tools/benchmark/cmd/range.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cmd

import (
"fmt"
"math"
"os"
"time"

Expand All @@ -24,6 +25,7 @@ import (

"github.com/spf13/cobra"
"golang.org/x/net/context"
"golang.org/x/time/rate"
"gopkg.in/cheggaaa/pb.v1"
)

Expand All @@ -36,12 +38,14 @@ var rangeCmd = &cobra.Command{
}

var (
rangeRate int
rangeTotal int
rangeConsistency string
)

func init() {
RootCmd.AddCommand(rangeCmd)
rangeCmd.Flags().IntVar(&rangeRate, "rate", 0, "Maximum range requests per second (0 is no limit)")
rangeCmd.Flags().IntVar(&rangeTotal, "total", 10000, "Total number of range requests")
rangeCmd.Flags().StringVar(&rangeConsistency, "consistency", "l", "Linearizable(l) or Serializable(s)")
}
Expand All @@ -67,6 +71,11 @@ func rangeFunc(cmd *cobra.Command, args []string) {
os.Exit(1)
}

if rangeRate == 0 {
rangeRate = math.MaxInt32
}
limit := rate.NewLimiter(rate.Limit(rangeRate), 1)

requests := make(chan v3.Op, totalClients)
clients := mustCreateClients(totalClients, totalConns)

Expand All @@ -80,6 +89,8 @@ func rangeFunc(cmd *cobra.Command, args []string) {
go func(c *v3.Client) {
defer wg.Done()
for op := range requests {
limit.Wait(context.Background())

st := time.Now()
_, err := c.Do(context.Background(), op)
r.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
Expand Down

0 comments on commit 0df543d

Please sign in to comment.