MCPcopy
hub / github.com/dgraph-io/dgraph / run

Function run

dgraph/cmd/increment/increment.go:161–238  ·  view source on GitHub ↗
(conf *viper.Viper)

Source from the content-addressed store, hash-verified

159}
160
161func run(conf *viper.Viper) {
162 trace.ApplyConfig(trace.Config{
163 DefaultSampler: trace.AlwaysSample(),
164 MaxAnnotationEventsPerSpan: 256,
165 })
166 x.RegisterExporters(conf, "dgraph.increment")
167
168 startTime := time.Now()
169 defer func() { fmt.Println("Total:", time.Since(startTime).Round(time.Millisecond)) }()
170
171 waitDur := conf.GetDuration("wait")
172 num := conf.GetInt("num")
173 conc := conf.GetInt("conc")
174 format := "0102 03:04:05.999"
175
176 // Do a sanity check on the passed credentials.
177 _ = z.NewSuperFlag(Increment.Conf.GetString("creds")).MergeAndCheckDefault(x.DefaultCreds)
178
179 var dg *dgo.Dgraph
180 sf := z.NewSuperFlag(conf.GetString("cloud"))
181 if addr := sf.GetString("addr"); len(addr) > 0 {
182 conn, err := dgo.DialCloud(addr, sf.GetString("jwt"))
183 x.Check(err)
184 dc := api.NewDgraphClient(conn)
185 dg = dgo.NewDgraphClient(dc)
186 } else {
187 dgTmp, closeFunc := x.GetDgraphClient(Increment.Conf, true)
188 defer closeFunc()
189 dg = dgTmp
190 }
191
192 processOne := func(i int) error {
193 txnStart := time.Now() // Start time of transaction
194 cnt, err := process(dg, conf)
195 now := time.Now().UTC().Format(format)
196 if err != nil {
197 return err
198 }
199 serverLat := cnt.qLatency + cnt.mLatency
200 clientLat := time.Since(txnStart).Round(time.Millisecond)
201 fmt.Printf(
202 "[w%d] %-17s Counter VAL: %d [ Ts: %d ] Latency: Q %s M %s S %s C %s D %s\n",
203 i, now, cnt.Val, cnt.startTs, cnt.qLatency, cnt.mLatency,
204 serverLat, clientLat, clientLat-serverLat)
205 return nil
206 }
207
208 // Run things serially first, if conc > 1.
209 if conc > 1 {
210 for range conc {
211 err := processOne(0)
212 x.Check(err)
213 num--
214 }
215 }
216
217 var wg sync.WaitGroup
218 f := func(worker int) {

Callers 1

initFunction · 0.70

Calls 8

RegisterExportersFunction · 0.92
CheckFunction · 0.92
GetDgraphClientFunction · 0.92
processFunction · 0.85
FormatMethod · 0.80
WaitMethod · 0.80
DoneMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected