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

Function mixedTxnFunc

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

Source from the content-addressed store, hash-verified

70}
71
72func mixedTxnFunc(cmd *cobra.Command, _ []string) {
73 if keySpaceSize <= 0 {
74 fmt.Fprintf(os.Stderr, "expected positive --key-space-size, got (%v)", keySpaceSize)
75 os.Exit(1)
76 }
77
78 if rangeConsistency == "l" {
79 fmt.Println("bench with linearizable range")
80 } else if rangeConsistency == "s" {
81 fmt.Println("bench with serializable range")
82 } else {
83 fmt.Fprintln(os.Stderr, cmd.Usage())
84 os.Exit(1)
85 }
86
87 requests := make(chan request, totalClients)
88 if mixedTxnRate == 0 {
89 mixedTxnRate = math.MaxInt32
90 }
91 limit := rate.NewLimiter(rate.Limit(mixedTxnRate), 1)
92 clients := mustCreateClients(totalClients, totalConns)
93 k, v := make([]byte, keySize), string(mustRandBytes(valSize))
94
95 bar = pb.New(mixedTxnTotal)
96 bar.Start()
97
98 reportRead := newReport()
99 reportWrite := newReport()
100 for i := range clients {
101 wg.Add(1)
102 go func(c *v3.Client) {
103 defer wg.Done()
104 for req := range requests {
105 limit.Wait(context.Background())
106 st := time.Now()
107 _, err := c.Txn(context.TODO()).Then(req.op).Commit()
108 if req.isWrite {
109 reportWrite.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
110 } else {
111 reportRead.Results() <- report.Result{Err: err, Start: st, End: time.Now()}
112 }
113 bar.Increment()
114 }
115 }(clients[i])
116 }
117
118 go func() {
119 for i := 0; i < mixedTxnTotal; i++ {
120 var req request
121 if rand.Float64() < mixedTxnReadWriteRatio/(1+mixedTxnReadWriteRatio) {
122 opts := []v3.OpOption{v3.WithRange(mixedTxnEndKey)}
123 if rangeConsistency == "s" {
124 opts = append(opts, v3.WithSerializable())
125 }
126 opts = append(opts, v3.WithPrefix(), v3.WithLimit(mixedTxnRangeLimit))
127 req.op = v3.OpGet("", opts...)
128 req.isWrite = false
129 readOpsTotal++

Callers

nothing calls this directly

Calls 15

mustCreateClientsFunction · 0.85
mustRandBytesFunction · 0.85
LimitMethod · 0.80
WithRangeMethod · 0.80
WithPrefixMethod · 0.80
newReportFunction · 0.70
StartMethod · 0.65
AddMethod · 0.65
DoneMethod · 0.65
WaitMethod · 0.65
CommitMethod · 0.65
ThenMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…