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

Function txnPutFunc

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

Source from the content-addressed store, hash-verified

56}
57
58func txnPutFunc(_ *cobra.Command, _ []string) {
59 if keySpaceSize <= 0 {
60 fmt.Fprintf(os.Stderr, "expected positive --key-space-size, got (%v)", keySpaceSize)
61 os.Exit(1)
62 }
63
64 if txnPutOpsPerTxn > keySpaceSize {
65 fmt.Fprintf(os.Stderr, "expected --txn-ops no larger than --key-space-size, "+
66 "got txn-ops(%v) key-space-size(%v)\n", txnPutOpsPerTxn, keySpaceSize)
67 os.Exit(1)
68 }
69
70 requests := make(chan []v3.Op, totalClients)
71 if txnPutRate == 0 {
72 txnPutRate = math.MaxInt32
73 }
74 limit := rate.NewLimiter(rate.Limit(txnPutRate), 1)
75 clients := mustCreateClients(totalClients, totalConns)
76 k, v := make([]byte, keySize), string(mustRandBytes(valSize))
77
78 bar = pb.New(txnPutTotal)
79 bar.Start()
80
81 r := newReport()
82 for i := range clients {
83 wg.Add(1)
84 go func(c *v3.Client) {
85 defer wg.Done()
86 for ops := range requests {
87 limit.Wait(context.Background())
88 st := time.Now()
89 _, err := c.Txn(context.TODO()).Then(ops...).Commit()
90 r.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
91 bar.Increment()
92 }
93 }(clients[i])
94 }
95
96 go func() {
97 for i := 0; i < txnPutTotal; i++ {
98 ops := make([]v3.Op, txnPutOpsPerTxn)
99 for j := 0; j < txnPutOpsPerTxn; j++ {
100 binary.PutVarint(k, int64(((i*txnPutOpsPerTxn)+j)%keySpaceSize))
101 ops[j] = v3.OpPut(string(k), v)
102 }
103 requests <- ops
104 }
105 close(requests)
106 }()
107
108 rc := r.Run()
109 wg.Wait()
110 close(r.Results())
111 bar.Finish()
112 fmt.Println(<-rc)
113}

Callers

nothing calls this directly

Calls 13

mustCreateClientsFunction · 0.85
mustRandBytesFunction · 0.85
LimitMethod · 0.80
newReportFunction · 0.70
StartMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65
CommitMethod · 0.65
ThenMethod · 0.65
TxnMethod · 0.65
ResultsMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…