Skip to content

Commit f85ffe2

Browse files
authored
Merge pull request #271 from Project-MONAI/AC-930-nds-improve-preformance
small improvements
2 parents fcd0247 + e6ea3b6 commit f85ffe2

File tree

4 files changed

+27
-19
lines changed

4 files changed

+27
-19
lines changed

src/InformaticsGateway/Services/Connectors/PayloadAssembler.cs

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -123,31 +123,36 @@ private async void OnTimedEvent(Object source, System.Timers.ElapsedEventArgs e)
123123
try
124124
{
125125
await _intializedTask.ConfigureAwait(false);
126+
126127
_timer.Enabled = false;
127-
_logger.BucketsActive(_payloads.Count);
128+
if (_payloads.Count > 0)
129+
{
130+
_logger.BucketsActive(_payloads.Count);
131+
}
128132
foreach (var key in _payloads.Keys)
129133
{
130134
_logger.BucketElapsedTime(key);
131135
var payload = await _payloads[key].Task.ConfigureAwait(false);
132136
using var loggerScope = _logger.BeginScope(new LoggingDataDictionary<string, object> { { "CorrelationId", payload.CorrelationId } });
133-
if (payload.HasTimedOut)
137+
138+
if (payload.IsUploadCompleted())
139+
{
140+
if (_payloads.TryRemove(key, out _))
141+
{
142+
await QueueBucketForNotification(key, payload).ConfigureAwait(false);
143+
}
144+
else
145+
{
146+
_logger.BucketRemoveError(key);
147+
}
148+
}
149+
else if (payload.HasTimedOut)
134150
{
135151
if (payload.AnyUploadFailures())
136152
{
137153
_payloads.TryRemove(key, out _);
138154
_logger.PayloadRemovedWithFailureUploads(key);
139155
}
140-
else if (payload.IsUploadCompleted())
141-
{
142-
if (_payloads.TryRemove(key, out _))
143-
{
144-
await QueueBucketForNotification(key, payload).ConfigureAwait(false);
145-
}
146-
else
147-
{
148-
_logger.BucketRemoveError(key);
149-
}
150-
}
151156
}
152157
}
153158
}

src/InformaticsGateway/Services/Storage/IObjectUploadQueue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717

1818
using System.Threading;
19+
using System.Threading.Tasks;
1920
using Monai.Deploy.InformaticsGateway.Api.Storage;
2021

2122
namespace Monai.Deploy.InformaticsGateway.Services.Storage
@@ -36,6 +37,6 @@ internal interface IObjectUploadQueue
3637
/// The default implementation blocks the call until a file is available from the queue.
3738
/// </summary>
3839
/// <param name="cancellationToken">Propagates notification that operations should be canceled.</param>
39-
FileStorageMetadata Dequeue(CancellationToken cancellationToken);
40+
Task<FileStorageMetadata> Dequeue(CancellationToken cancellationToken);
4041
}
4142
}

src/InformaticsGateway/Services/Storage/ObjectUploadQueue.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
using System;
1818
using System.Collections.Concurrent;
19-
using System.Collections.Generic;
2019
using System.Diagnostics;
2120
using System.Threading;
21+
using System.Threading.Tasks;
2222
using Ardalis.GuardClauses;
2323
using Microsoft.Extensions.Logging;
2424
using Monai.Deploy.InformaticsGateway.Api.Storage;
@@ -47,7 +47,7 @@ public void Queue(FileStorageMetadata file)
4747
_logger.InstanceAddedToUploadQueue(file.Id, _workItems.Count, process.WorkingSet64 / 1024.0);
4848
}
4949

50-
public FileStorageMetadata Dequeue(CancellationToken cancellationToken)
50+
public async Task<FileStorageMetadata> Dequeue(CancellationToken cancellationToken)
5151
{
5252
while (!cancellationToken.IsCancellationRequested)
5353
{
@@ -56,6 +56,10 @@ public FileStorageMetadata Dequeue(CancellationToken cancellationToken)
5656
_logger.InstanceInUploadQueue(_workItems.Count);
5757
return reuslt;
5858
}
59+
if (_workItems.IsEmpty)
60+
{
61+
await Task.Delay(100, cancellationToken).ConfigureAwait(false);
62+
}
5963
}
6064
throw new OperationCanceledException("Cancellation requested.");
6165
}

src/InformaticsGateway/Services/Storage/ObjectUploadService.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
using System.Diagnostics;
2121
using System.Threading;
2222
using System.Threading.Tasks;
23-
using System.Threading.Tasks.Dataflow;
2423
using Ardalis.GuardClauses;
2524
using Microsoft.Extensions.DependencyInjection;
2625
using Microsoft.Extensions.Hosting;
@@ -32,7 +31,6 @@
3231
using Monai.Deploy.InformaticsGateway.Common;
3332
using Monai.Deploy.InformaticsGateway.Configuration;
3433
using Monai.Deploy.InformaticsGateway.Logging;
35-
using Monai.Deploy.InformaticsGateway.Repositories;
3634
using Monai.Deploy.InformaticsGateway.Services.Common;
3735
using Monai.Deploy.Storage.API;
3836
using Polly;
@@ -106,7 +104,7 @@ private async Task StartWorker(int thread, CancellationToken cancellationToken)
106104
{
107105
try
108106
{
109-
var item = _uplaodQueue.Dequeue(cancellationToken);
107+
var item = await _uplaodQueue.Dequeue(cancellationToken);
110108
await ProcessObject(item);
111109
}
112110
catch (OperationCanceledException ex)

0 commit comments

Comments
 (0)