| 1234567891011121314151617181920212223242526272829303132 |
- namespace Admin.NET.Plugin.AiDOP.DataPlatform.Core.Connectors;
- public sealed record RelationalCapacityBatch(int Rows, long RawBytes, decimal SourceMs,
- decimal RawMs, decimal CleanMs, decimal HandoffMs, decimal ReconcileMs)
- {
- public decimal TotalMs => SourceMs + RawMs + CleanMs + HandoffMs + ReconcileMs;
- }
- public sealed record RelationalCapacityEstimate(long? SourceRows, string SourceRowsBasis, int SampleRows, int SampleBatches,
- long SampleRawBytes, decimal? RawBytesPerRow, long? FullRawBytes, decimal? FullSecondsLow, decimal? FullSecondsHigh)
- {
- public static RelationalCapacityEstimate FromSamples(long? catalogRows, IReadOnlyList<RelationalCapacityBatch> batches,
- bool reachedEnd = false)
- {
- var valid = batches.Where(batch => batch.Rows > 0 && batch.RawBytes > 0).ToArray();
- var rows = valid.Sum(batch => batch.Rows);
- var bytes = valid.Sum(batch => batch.RawBytes);
- long? sourceRows = reachedEnd ? rows : catalogRows.HasValue ? Math.Max(catalogRows.Value, rows) : null;
- var basis = reachedEnd ? "sample" : catalogRows is null ? "unknown" : catalogRows < rows ? "sample-floor" : "catalog";
- if (rows == 0)
- return new(sourceRows, basis, 0, 0, 0, null, sourceRows == 0 ? 0 : null, null, null);
- var bytesPerRow = (decimal)bytes / rows;
- var projectedBytes = decimal.Ceiling(bytesPerRow * sourceRows.GetValueOrDefault());
- var measuredRates = valid.Where(batch => batch.TotalMs > 0).Select(batch => batch.TotalMs / batch.Rows).ToArray();
- decimal? Forecast(decimal rate) => sourceRows.HasValue ? decimal.Round(rate * sourceRows.Value / 1000, 3) : null;
- return new(sourceRows, basis, rows, valid.Length, bytes, decimal.Round(bytesPerRow, 2),
- sourceRows.HasValue && projectedBytes <= long.MaxValue ? (long)projectedBytes : null,
- measuredRates.Length > 0 ? Forecast(measuredRates.Min()) : null,
- measuredRates.Length > 0 ? Forecast(measuredRates.Max()) : null);
- }
- }
|