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

Function BenchmarkBulkIndexer

esutil/bulk_indexer_benchmark_test.go:61–99  ·  view source on GitHub ↗
(b *testing.B)

Source from the content-addressed store, hash-verified

59}
60
61func BenchmarkBulkIndexer(b *testing.B) {
62 b.ReportAllocs()
63
64 b.Run("Basic", func(b *testing.B) {
65 b.ResetTimer()
66
67 es, err := elasticsearch.NewClient(elasticsearch.Config{Transport: &mockTransp{}})
68 if err != nil {
69 b.Fatalf("Unexpected error: %s", err)
70 }
71 defer func() {
72 _ = es.Close(context.Background())
73 }()
74 bi, err := esutil.NewBulkIndexer(esutil.BulkIndexerConfig{
75 Client: es,
76 FlushBytes: 1024,
77 })
78 if err != nil {
79 b.Fatalf("Unexpected error: %s", err)
80 }
81 defer func() { _ = bi.Close(context.Background()) }()
82
83 docID := make([]byte, 0, 16)
84 var docIDBuf bytes.Buffer
85 docIDBuf.Grow(cap(docID))
86
87 for i := 0; i < b.N; i++ {
88 docID = strconv.AppendInt(docID, int64(i), 10)
89 docIDBuf.Write(docID)
90 _ = bi.Add(context.Background(), esutil.BulkIndexerItem{
91 Action: "index",
92 DocumentID: docIDBuf.String(), // 1x alloc
93 Body: strings.NewReader(`{"foo":"bar"}`), // 1x alloc
94 })
95 docID = docID[:0]
96 docIDBuf.Reset()
97 }
98 })
99}

Callers

nothing calls this directly

Calls 6

CloseMethod · 0.95
AddMethod · 0.95
NewBulkIndexerFunction · 0.92
RunMethod · 0.45
WriteMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected