Add a logging statement for when batch size was larger than expected (25 megs) (#232)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.Buffers;
|
||||
using System.Buffers;
|
||||
|
||||
namespace Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
@@ -19,12 +19,13 @@ public static class BatchExtensions
|
||||
public static void AddBatchItem<T>(this IMemoryOwner<T> batch, T item)
|
||||
where T : IHasByteSize => ((Batch<T>)batch).Add(item);
|
||||
|
||||
public static int GetBatchSize<T>(this IMemoryOwner<T> batch, int maxBatchSize)
|
||||
public static int GetBatchSize<T>(this IMemoryOwner<T> batch, Action<string> logAsWarning, int maxBatchSize)
|
||||
where T : IHasByteSize
|
||||
{
|
||||
var currentSize = ((Batch<T>)batch).BatchByteSize;
|
||||
if (currentSize > maxBatchSize)
|
||||
{
|
||||
logAsWarning($"Batch size exceeded. Current size: {currentSize} bytes. Max size: {maxBatchSize} bytes.");
|
||||
return maxBatchSize;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ public static class ChannelExtensions
|
||||
{
|
||||
public static BatchingChannelReader<T, IMemoryOwner<T>> BatchByByteSize<T>(
|
||||
this ChannelReader<T> source,
|
||||
Action<string> logAsWarning,
|
||||
int batchSize,
|
||||
bool singleReader = false,
|
||||
bool allowSynchronousContinuations = false
|
||||
@@ -15,6 +16,7 @@ public static class ChannelExtensions
|
||||
where T : IHasByteSize =>
|
||||
new SizeBatchingChannelReader<T>(
|
||||
source ?? throw new ArgumentNullException(nameof(source)),
|
||||
logAsWarning,
|
||||
batchSize,
|
||||
singleReader,
|
||||
allowSynchronousContinuations
|
||||
|
||||
@@ -5,7 +5,7 @@ using Speckle.Sdk.Serialisation.V2.Send;
|
||||
|
||||
namespace Speckle.Sdk.Dependencies.Serialization;
|
||||
|
||||
public abstract class ChannelSaver<T>(CancellationToken cancellationToken)
|
||||
public abstract class ChannelSaver<T>(Action<string> logAsWarning, CancellationToken cancellationToken)
|
||||
where T : IHasByteSize
|
||||
{
|
||||
private const int SEND_CAPACITY = 500;
|
||||
@@ -32,7 +32,7 @@ public abstract class ChannelSaver<T>(CancellationToken cancellationToken)
|
||||
|
||||
public Task Start() =>
|
||||
_checkCacheChannel
|
||||
.Reader.BatchByByteSize(HTTP_SEND_CHUNK_SIZE)
|
||||
.Reader.BatchByByteSize(logAsWarning, HTTP_SEND_CHUNK_SIZE)
|
||||
.WithTimeout(HTTP_BATCH_TIMEOUT)
|
||||
.PipeAsync(
|
||||
MAX_PARALLELISM_HTTP,
|
||||
|
||||
@@ -11,6 +11,7 @@ public interface IHasByteSize
|
||||
|
||||
public sealed class SizeBatchingChannelReader<T>(
|
||||
ChannelReader<T> source,
|
||||
Action<string> logAsWarning,
|
||||
int batchSize,
|
||||
bool singleReader,
|
||||
bool syncCont = false
|
||||
@@ -33,5 +34,5 @@ public sealed class SizeBatchingChannelReader<T>(
|
||||
|
||||
protected override void AddBatchItem(IMemoryOwner<T> batch, T item) => batch.AddBatchItem(item);
|
||||
|
||||
protected override int GetBatchSize(IMemoryOwner<T> batch) => batch.GetBatchSize(_batchSize);
|
||||
protected override int GetBatchSize(IMemoryOwner<T> batch) => batch.GetBatchSize(logAsWarning, _batchSize);
|
||||
}
|
||||
|
||||
@@ -35,9 +35,13 @@ public sealed class SerializeProcess(
|
||||
ILoggerFactory loggerFactory,
|
||||
CancellationToken cancellationToken,
|
||||
SerializeProcessOptions? options = null
|
||||
#pragma warning disable CS9107 // Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
|
||||
) : ChannelSaver<BaseItem>(cancellationToken), ISerializeProcess
|
||||
#pragma warning restore CS9107 // Parameter is captured into the state of the enclosing type and its value is also passed to the base constructor. The value might be captured by the base class as well.
|
||||
#pragma warning disable CS9107
|
||||
#pragma warning disable CA2254
|
||||
)
|
||||
: ChannelSaver<BaseItem>(x => loggerFactory.CreateLogger<SerializeProcess>().LogWarning(x), cancellationToken),
|
||||
ISerializeProcess
|
||||
#pragma warning restore CA2254
|
||||
#pragma warning restore CS9107
|
||||
{
|
||||
//async dispose
|
||||
[SuppressMessage("Usage", "CA2213:Disposable fields should be disposed")]
|
||||
|
||||
@@ -12,6 +12,8 @@ public class BatchTests
|
||||
public int ByteSize { get; } = size;
|
||||
}
|
||||
|
||||
private static readonly Action<string> EMPTY_LOGGER = _ => { };
|
||||
|
||||
[Fact]
|
||||
public void TestBatchSize_Calc()
|
||||
{
|
||||
@@ -22,6 +24,16 @@ public class BatchTests
|
||||
batch.BatchByteSize.Should().Be(3);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Ensure_logging()
|
||||
{
|
||||
using var batch = new Batch<BatchItem>();
|
||||
batch.AddBatchItem(new BatchItem(2));
|
||||
bool called = false;
|
||||
batch.GetBatchSize(x => called = true, 1);
|
||||
called.Should().BeTrue();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TestBatchSize_Trim()
|
||||
{
|
||||
@@ -64,13 +76,13 @@ public class BatchTests
|
||||
|
||||
using var batch = BatchExtensions.CreateBatch<BatchItem>();
|
||||
batch.AddBatchItem(new BatchItem(2));
|
||||
bool full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
bool full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeFalse();
|
||||
batch.AddBatchItem(new BatchItem(2));
|
||||
full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeFalse();
|
||||
batch.AddBatchItem(new BatchItem(2));
|
||||
full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -81,7 +93,7 @@ public class BatchTests
|
||||
|
||||
using var batch = BatchExtensions.CreateBatch<BatchItem>();
|
||||
batch.AddBatchItem(new BatchItem(63));
|
||||
bool full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
bool full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeTrue();
|
||||
}
|
||||
|
||||
@@ -92,10 +104,10 @@ public class BatchTests
|
||||
|
||||
using var batch = BatchExtensions.CreateBatch<BatchItem>();
|
||||
batch.AddBatchItem(new BatchItem(2));
|
||||
bool full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
bool full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeFalse();
|
||||
batch.AddBatchItem(new BatchItem(63));
|
||||
full = batch.GetBatchSize(MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full = batch.GetBatchSize(EMPTY_LOGGER, MAX_BATCH_SIZE) == MAX_BATCH_SIZE;
|
||||
full.Should().BeTrue();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user