-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBulkIngestionBenchmarks.cs
71 lines (58 loc) · 1.98 KB
/
BulkIngestionBenchmarks.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Licensed to Elasticsearch B.V under one or more agreements.
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information
using BenchmarkDotNet.Engines;
using Performance.Common;
namespace Elastic.Ingest.Elasticsearch.Benchmarks;
[SimpleJob(RunStrategy.Monitoring, invocationCount: 10, id: "BulkIngestionJob")]
public class BulkIngestionBenchmarks
{
private static readonly int MaxExportSize = 5_000;
private readonly ManualResetEvent _waitHandle = new(false);
private StockData[] _data = Array.Empty<StockData>();
private IndexChannelOptions<StockData>? _options;
#if DEBUG
private long _responses;
#endif
//[Params(100_000)]
public int DocumentsToIndex { get; set; } = 100_000;
[ParamsAllValues]
public bool DisableDiagnostics { get; set; }
[GlobalSetup]
public void Setup()
{
_data = StockData.CreateSampleData(DocumentsToIndex);
var transport = new DistributedTransport(
new TransportConfiguration(
new SingleNodePool(new("http://localhost:9200")),
new InMemoryRequestInvoker(StockData.CreateSampleDataSuccessWithFilterPathResponseBytes(MaxExportSize))));
#pragma warning disable CS0618 // Type or member is obsolete
_options = new IndexChannelOptions<StockData>(transport)
{
BufferOptions = new Channels.BufferOptions
{
OutboundBufferMaxSize = MaxExportSize
},
DisableDiagnostics = DisableDiagnostics,
IndexFormat = "stock-data-v8",
OutboundChannelExitedCallback = () => _waitHandle.Set(),
#if DEBUG
ExportResponseCallback = (response, a) =>
{
Interlocked.Add(ref _responses, a.Count);
Console.WriteLine(_responses);
},
PublishToOutboundChannelCallback = () => Console.WriteLine("PUBLISHED")
#endif
};
#pragma warning restore CS0618 // Type or member is obsolete
}
[Benchmark]
public void BulkAll()
{
var channel = new IndexChannel<StockData>(_options!);
channel.TryWriteMany(_data);
channel.TryComplete();
_waitHandle.WaitOne();
}
}