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

Function init

_benchmarks/benchmarks/actions/005_bulk.go:34–109  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

32)
33
34func init() {
35 benchmarks.Register(
36 benchmarks.Action{
37 Name: "bulk",
38 Category: "core",
39
40 NumWarmups: 10,
41 NumRepetitions: 1000,
42 NumOperations: 10000,
43
44 SetupFunc: func(n int, c runner.Config) (*esapi.Response, error) {
45 var (
46 res *esapi.Response
47 err error
48
49 indexName = "test-bench-bulk"
50 indexSettings = `{"settings": { "number_of_shards": 3, "refresh_interval":"5s"}}`
51 )
52 res, _ = c.RunnerClient.Indices.Delete([]string{indexName})
53 if res != nil && res.Body != nil {
54 res.Body.Close()
55 }
56 res, err = c.RunnerClient.Indices.Create(
57 indexName,
58 c.RunnerClient.Indices.Create.WithBody(strings.NewReader(indexSettings)),
59 c.RunnerClient.Indices.Create.WithWaitForActiveShards("1"))
60 if err != nil {
61 return res, err
62 }
63 res.Body.Close()
64 return res, err
65 },
66
67 RunnerFunc: func(n int, c runner.Config) (*esapi.Response, error) {
68 var (
69 res *esapi.Response
70 err error
71
72 indexName = "test-bench-bulk"
73 opMeta = []byte("{ \"index\" : {} }\n")
74 opBody bytes.Buffer
75 )
76
77 opBody.Reset()
78
79 docBody := bytes.NewBuffer(bytes.ReplaceAll(benchmarks.DataSources["small"].Bytes(), []byte("\n"), []byte("")))
80 docBody.WriteRune('\n')
81
82 for i := 0; i < c.NumOperations; i++ {
83 var copyDocBody bytes.Buffer
84 tr := io.TeeReader(docBody, &copyDocBody)
85 opBody.Write(opMeta)
86 opBody.ReadFrom(tr)
87 docBody = &copyDocBody
88 }
89
90 res, err = c.RunnerClient.Bulk(&opBody, c.RunnerClient.Bulk.WithIndex(indexName))
91 if err != nil {

Callers

nothing calls this directly

Calls 11

CloseMethod · 0.65
DeleteMethod · 0.45
CreateMethod · 0.45
WithBodyMethod · 0.45
BytesMethod · 0.45
WriteMethod · 0.45
BulkMethod · 0.45
WithIndexMethod · 0.45
BoolMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected