|
| 1 | +using BenchmarkDotNet.Attributes; |
| 2 | +using Grpc.Core; |
| 3 | +using Microsoft.Extensions.Logging; |
| 4 | +using Ydb.Sdk.Ado.BulkUpsert; |
| 5 | +using Ydb.Table; |
| 6 | + |
| 7 | +namespace Ydb.Sdk.Ado.Benchmarks; |
| 8 | + |
| 9 | +public class BulkUpsertImporterBenchmark |
| 10 | +{ |
| 11 | + private const int BatchSize = 15000; |
| 12 | + private readonly int _maxBatchByteSize = new YdbConnectionStringBuilder().MaxSendMessageSize; |
| 13 | + private IDriver _driver = null!; |
| 14 | + private IList<(Guid Guid, string String, int Int, double Double, DateTime DateTime)> _rows = null!; |
| 15 | + |
| 16 | + [GlobalSetup] |
| 17 | + public void Setup() |
| 18 | + { |
| 19 | + _driver = new BulkUpsertMockDriver(); |
| 20 | + _rows = Enumerable.Range(0, BatchSize) |
| 21 | + .Select(i => new ValueTuple<Guid, string, int, double, DateTime>(Guid.NewGuid(), |
| 22 | + Guid.NewGuid() + "_" + Guid.NewGuid(), i, i * 1.324, DateTime.Now)) |
| 23 | + .ToList(); |
| 24 | + } |
| 25 | + |
| 26 | + [Benchmark] |
| 27 | + public async Task FlushAsync_BulkUpsertImporter() |
| 28 | + { |
| 29 | + var bulkUpsertImporter = new BulkUpsertImporter(_driver, "table_name", ["c1", "c2", "c3", "c4", "c5"], |
| 30 | + _maxBatchByteSize, CancellationToken.None); |
| 31 | + |
| 32 | + foreach (var row in _rows) |
| 33 | + { |
| 34 | + await bulkUpsertImporter.AddRowAsync(row.Guid, row.String, row.Int, row.Double, row.DateTime); |
| 35 | + } |
| 36 | + await bulkUpsertImporter.FlushAsync(); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +internal class BulkUpsertMockDriver : IDriver |
| 41 | +{ |
| 42 | + public ValueTask DisposeAsync() => throw new NotImplementedException(); |
| 43 | + |
| 44 | + public void Dispose() => throw new NotImplementedException(); |
| 45 | + |
| 46 | + public Task<TResponse> |
| 47 | + UnaryCall<TRequest, TResponse>(Method<TRequest, TResponse> method, TRequest request, |
| 48 | + GrpcRequestSettings settings) where TRequest : class where TResponse : class => |
| 49 | + Task.FromResult((TResponse)(object)new BulkUpsertResponse |
| 50 | + { |
| 51 | + Operation = new Operations.Operation { Status = StatusIds.Types.StatusCode.Success } |
| 52 | + }); |
| 53 | + |
| 54 | + public ValueTask<IServerStream<TResponse>> ServerStreamCall<TRequest, |
| 55 | + TResponse>(Method<TRequest, TResponse> method, TRequest request, GrpcRequestSettings settings) where |
| 56 | + TRequest : class |
| 57 | + where TResponse : class => throw new NotImplementedException(); |
| 58 | + |
| 59 | + public ValueTask<IBidirectionalStream<TRequest, |
| 60 | + TResponse>> BidirectionalStreamCall<TRequest, TResponse>(Method<TRequest, TResponse> method, |
| 61 | + GrpcRequestSettings settings) where TRequest : class where TResponse : class => throw new |
| 62 | + NotImplementedException(); |
| 63 | + |
| 64 | + public ILoggerFactory LoggerFactory { get; } |
| 65 | +} |
0 commit comments