Skip to content

Commit

Permalink
add modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
rogeralsing committed Jan 21, 2024
1 parent 2110812 commit 4ff0fb1
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions src/Proto.Remote/Endpoints/Endpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,21 +386,27 @@ private async Task RunAsync()
var t1 = _remoteDelivers.Reader.WaitToReadAsync(CancellationToken).AsTask();
var t2 = _remotePriorityDelivers.Reader.WaitToReadAsync(CancellationToken).AsTask();
await Task.WhenAny(t1, t2);

var i = 0;
while (true)
{
var didWrite = false;
if (_remotePriorityDelivers.Reader.TryRead(out var remoteDeliver))
RemoteDeliver? remoteDeliver;

//we don´t need complete priority, we need "enough" important messages to get over
if (i++ % 10 == 0)
{
messages.Add(remoteDeliver);
didWrite = true;
if (_remotePriorityDelivers.Reader.TryRead(out remoteDeliver))
{
messages.Add(remoteDeliver);
didWrite = true;
}

if (messages.Count >= RemoteConfig.EndpointWriterOptions.EndpointWriterBatchSize)
{
break;
}
}

if (messages.Count >= RemoteConfig.EndpointWriterOptions.EndpointWriterBatchSize)
{
break;
}

if (_remoteDelivers.Reader.TryRead(out remoteDeliver))
{
messages.Add(remoteDeliver);
Expand Down

0 comments on commit 4ff0fb1

Please sign in to comment.