(cmd *cobra.Command, _ []string)
| 72 | } |
| 73 | |
| 74 | func putFunc(cmd *cobra.Command, _ []string) { |
| 75 | if keySpaceSize <= 0 { |
| 76 | fmt.Fprintf(os.Stderr, "expected positive --key-space-size, got (%v)", keySpaceSize) |
| 77 | os.Exit(1) |
| 78 | } |
| 79 | |
| 80 | requests := make(chan v3.Op, totalClients) |
| 81 | if putRate == 0 { |
| 82 | putRate = math.MaxInt32 |
| 83 | } |
| 84 | limit := rate.NewLimiter(rate.Limit(putRate), 1) |
| 85 | clients := mustCreateClients(totalClients, totalConns) |
| 86 | k, v := make([]byte, keySize), string(mustRandBytes(valSize)) |
| 87 | |
| 88 | bar = pb.New(putTotal) |
| 89 | bar.Start() |
| 90 | |
| 91 | r := newReport() |
| 92 | for i := range clients { |
| 93 | wg.Add(1) |
| 94 | go func(c *v3.Client) { |
| 95 | defer wg.Done() |
| 96 | for op := range requests { |
| 97 | limit.Wait(context.Background()) |
| 98 | |
| 99 | st := time.Now() |
| 100 | _, err := c.Do(context.Background(), op) |
| 101 | r.Results() <- report.Result{Err: err, Start: st, End: time.Now()} |
| 102 | bar.Increment() |
| 103 | } |
| 104 | }(clients[i]) |
| 105 | } |
| 106 | |
| 107 | go func() { |
| 108 | for i := 0; i < putTotal; i++ { |
| 109 | if seqKeys { |
| 110 | binary.PutVarint(k, int64(i%keySpaceSize)) |
| 111 | } else { |
| 112 | binary.PutVarint(k, int64(rand.Intn(keySpaceSize))) |
| 113 | } |
| 114 | requests <- v3.OpPut(string(k), v) |
| 115 | } |
| 116 | close(requests) |
| 117 | }() |
| 118 | |
| 119 | if compactInterval > 0 { |
| 120 | go func() { |
| 121 | for { |
| 122 | time.Sleep(compactInterval) |
| 123 | compactKV(clients) |
| 124 | } |
| 125 | }() |
| 126 | } |
| 127 | |
| 128 | rc := r.Run() |
| 129 | wg.Wait() |
| 130 | close(r.Results()) |
| 131 | bar.Finish() |
nothing calls this directly
no test coverage detected
searching dependent graphs…