MCPcopy
hub / github.com/elastic/go-elasticsearch / run

Method run

_examples/bulk/benchmarks/runner/runner.go:186–252  ·  view source on GitHub ↗

run executes a single benchmark run n, recording stats when measure is true.

(n int, measure bool)

Source from the content-addressed store, hash-verified

184
185// run executes a single benchmark run n, recording stats when measure is true.
186func (r *Runner) run(n int, measure bool) error {
187 if err := r.setup(); err != nil {
188 return fmt.Errorf("run: %s", err)
189 }
190
191 bi, err := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
192 Index: r.config.IndexName,
193 Client: r.config.Client,
194 Decoder: r.config.Decoder,
195 NumWorkers: r.config.NumWorkers,
196 FlushBytes: r.config.FlushBytes,
197 FlushInterval: time.Hour, // Disable automatic flushing
198 })
199 if err != nil {
200 return fmt.Errorf("run: %s", err)
201 }
202
203 start := time.Now().UTC()
204 for i := 1; i <= r.config.NumItems; i++ {
205 err := bi.Add(context.Background(), esutil.BulkIndexerItem{
206 Action: "index",
207 Body: bytes.NewReader(r.doc),
208 OnFailure: func(ctx context.Context, item esutil.BulkIndexerItem, res esutil.BulkIndexerResponseItem, err error) {
209 if err != nil {
210 log.Printf("ERROR: %s", err)
211 } else {
212 log.Printf("ERROR: %s: %s", res.Error.Type, res.Error.Reason)
213 }
214 },
215 })
216 if err != nil {
217 return fmt.Errorf("run: %s", err)
218 }
219 }
220
221 if err := bi.Close(context.Background()); err != nil {
222 return fmt.Errorf("run: %s", err)
223 }
224
225 duration := time.Since(start)
226
227 if measure {
228 biStats := bi.Stats()
229
230 var numThroughput uint64
231 if r.config.Mockserver {
232 numThroughput = biStats.NumAdded
233 } else {
234 numThroughput = biStats.NumFlushed
235 }
236 sample := 1000.0 / float64(duration/time.Millisecond) * float64(numThroughput)
237 r.samples = append(r.samples, sample)
238
239 log.Printf("%4d) add=%s\tflush=%s\tfail=%s\treqs=%s\tdur=%-6s\t%6s docs/sec\n",
240 n,
241 formatInt(int(biStats.NumAdded)),
242 formatInt(int(biStats.NumFlushed)),
243 formatInt(int(biStats.NumFailed)),

Callers 1

RunMethod · 0.95

Calls 8

setupMethod · 0.95
AddMethod · 0.95
CloseMethod · 0.95
StatsMethod · 0.95
NewBulkIndexerFunction · 0.92
formatIntFunction · 0.85
PrintfMethod · 0.80
TruncateMethod · 0.45

Tested by

no test coverage detected