-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Prefer index name on URL for fixed index names and data streams (#35)
* Refactor and optimize index and data stream bulk request data * Add benchmarks * Rename class * Add templated index name benchmark * Remove comparison code * Fix URLs * Fixup * Add tests * Fix stock data sample array length * Finalise benchmarks and fix results * Fix BOM * Fix formatting
- Loading branch information
1 parent
feb057d
commit e2b11b0
Showing
16 changed files
with
524 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
....Ingest.Elasticsearch.Benchmarks/Benchmarks/BulkRequestCreationForDataStreamBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// 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 Elastic.Ingest.Elasticsearch.DataStreams; | ||
using Elastic.Ingest.Elasticsearch.Serialization; | ||
using Performance.Common; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks; | ||
|
||
public class BulkRequestCreationForDataStreamBenchmarks | ||
{ | ||
private static readonly int DocumentsToIndex = 1_000; | ||
|
||
private DataStreamChannelOptions<StockData>? _options; | ||
private HttpTransport? _transport; | ||
private TransportConfiguration? _transportConfiguration; | ||
private StockData[] _data = Array.Empty<StockData>(); | ||
private readonly BulkOperationHeader _bulkOperationHeader = new CreateOperation(); | ||
|
||
public Stream MemoryStream { get; } = new MemoryStream(); | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_transportConfiguration = new TransportConfiguration( | ||
new SingleNodePool(new("http://localhost:9200")), | ||
new InMemoryConnection(StockData.CreateSampleDataSuccessWithFilterPathResponseBytes(DocumentsToIndex))); | ||
|
||
_transport = new DefaultHttpTransport(_transportConfiguration); | ||
|
||
_options = new DataStreamChannelOptions<StockData>(_transport) | ||
{ | ||
BufferOptions = new Channels.BufferOptions | ||
{ | ||
OutboundBufferMaxSize = DocumentsToIndex | ||
} | ||
}; | ||
|
||
_data = StockData.CreateSampleData(DocumentsToIndex); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task WriteToStreamAsync() | ||
{ | ||
MemoryStream.Position = 0; | ||
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, _ => _bulkOperationHeader); | ||
var requestData = new RequestData(Elastic.Transport.HttpMethod.POST, "/_bulk", PostData.ReadOnlyMemory(bytes), _transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory); | ||
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...st.Elasticsearch.Benchmarks/Benchmarks/BulkRequestCreationWithFixedIndexNameBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// 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 Elastic.Ingest.Elasticsearch.Serialization; | ||
using Performance.Common; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks; | ||
|
||
public class BulkRequestCreationWithFixedIndexNameBenchmarks | ||
{ | ||
private static readonly int DocumentsToIndex = 1_000; | ||
|
||
private IndexChannelOptions<StockData>? _options; | ||
private HttpTransport? _transport; | ||
private TransportConfiguration? _transportConfiguration; | ||
private StockData[] _data = Array.Empty<StockData>(); | ||
|
||
public Stream MemoryStream { get; } = new MemoryStream(); | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_transportConfiguration = new TransportConfiguration( | ||
new SingleNodePool(new("http://localhost:9200")), | ||
new InMemoryConnection(StockData.CreateSampleDataSuccessWithFilterPathResponseBytes(DocumentsToIndex))); | ||
|
||
_transport = new DefaultHttpTransport(_transportConfiguration); | ||
|
||
_options = new IndexChannelOptions<StockData>(_transport) | ||
{ | ||
BufferOptions = new Channels.BufferOptions | ||
{ | ||
OutboundBufferMaxSize = DocumentsToIndex | ||
}, | ||
IndexFormat = "stock-data-v8" | ||
}; | ||
|
||
_data = StockData.CreateSampleData(DocumentsToIndex); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task WriteToStreamAsync() | ||
{ | ||
MemoryStream.Position = 0; | ||
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, e => BulkRequestDataFactory.CreateBulkOperationHeaderForIndex(e, _options!, true)); | ||
var requestData = new RequestData(Elastic.Transport.HttpMethod.POST, "/_bulk", PostData.ReadOnlyMemory(bytes), _transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory); | ||
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
...lasticsearch.Benchmarks/Benchmarks/BulkRequestCreationWithTemplatedIndexNameBenchmarks.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// 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 Elastic.Ingest.Elasticsearch.Serialization; | ||
using Performance.Common; | ||
|
||
namespace Elastic.Ingest.Elasticsearch.Benchmarks.Benchmarks; | ||
|
||
public class BulkRequestCreationWithTemplatedIndexNameBenchmarks | ||
{ | ||
private static readonly int DocumentsToIndex = 1_000; | ||
|
||
private IndexChannelOptions<StockData>? _options; | ||
private HttpTransport? _transport; | ||
private TransportConfiguration? _transportConfiguration; | ||
private StockData[] _data = Array.Empty<StockData>(); | ||
|
||
public Stream MemoryStream { get; } = new MemoryStream(); | ||
|
||
[GlobalSetup] | ||
public void Setup() | ||
{ | ||
_transportConfiguration = new TransportConfiguration( | ||
new SingleNodePool(new("http://localhost:9200")), | ||
new InMemoryConnection(StockData.CreateSampleDataSuccessWithFilterPathResponseBytes(DocumentsToIndex))); | ||
|
||
_transport = new DefaultHttpTransport(_transportConfiguration); | ||
|
||
_options = new IndexChannelOptions<StockData>(_transport) | ||
{ | ||
BufferOptions = new Channels.BufferOptions | ||
{ | ||
OutboundBufferMaxSize = DocumentsToIndex | ||
} | ||
}; | ||
|
||
_data = StockData.CreateSampleData(DocumentsToIndex); | ||
} | ||
|
||
[Benchmark(Baseline = true)] | ||
public async Task DynamicIndexName_WriteToStreamAsync() | ||
{ | ||
MemoryStream.Position = 0; | ||
var bytes = BulkRequestDataFactory.GetBytes(_data, _options!, e => BulkRequestDataFactory.CreateBulkOperationHeaderForIndex(e, _options!, false)); | ||
var requestData = new RequestData(Elastic.Transport.HttpMethod.POST, "/_bulk", PostData.ReadOnlyMemory(bytes), _transportConfiguration!, null!, ((ITransportConfiguration)_transportConfiguration!).MemoryStreamFactory); | ||
await requestData.PostData.WriteAsync(MemoryStream, _transportConfiguration!, CancellationToken.None); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.