MCPcopy
hub / github.com/etcd-io/etcd / putFunc

Function putFunc

tools/benchmark/cmd/put.go:74–137  ·  view source on GitHub ↗
(cmd *cobra.Command, _ []string)

Source from the content-addressed store, hash-verified

72}
73
74func 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()

Callers

nothing calls this directly

Calls 13

mustCreateClientsFunction · 0.85
mustRandBytesFunction · 0.85
compactKVFunction · 0.85
hashKVFunction · 0.85
LimitMethod · 0.80
newReportFunction · 0.70
StartMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65
DoMethod · 0.65
ResultsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…