Skip to content

Commit

Permalink
Make sure we always have min publish requests queued.
Browse files Browse the repository at this point in the history
  • Loading branch information
marcschier committed Apr 16, 2024
1 parent ff60685 commit 978a207
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 13 deletions.
2 changes: 1 addition & 1 deletion deploy/templates/azuredeploy.platform.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
},
"hostingPlanSku": {
"type": "string",
"defaultValue": "B1",
"defaultValue": "S1",
"allowedValues": [
"B1",
"B2",
Expand Down
43 changes: 31 additions & 12 deletions src/Azure.IIoT.OpcUa.Publisher/src/Stack/Services/OpcUaClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1042,23 +1042,27 @@ private void EnsureMinimumNumberOfPublishRequestsQueued()
return;
}

var minPublishRequests = MinPublishRequests ?? kMinPublishRequestCount;
if (minPublishRequests <= 0)
{
minPublishRequests = 1;
}
var percentage = PublishRequestsPerSubscriptionPercent ?? 100;
var desiredRequests = Math.Max(
MinPublishRequests ?? kMinPublishRequestCount,
var desiredRequests = Math.Max(minPublishRequests,
percentage == 100 || percentage < 0 ? created :
(int)Math.Ceiling(created * (percentage / 100.0)));
if (desiredRequests < 0)
if (desiredRequests <= 0)
{
_logger.LogDebug("Negative number of publish requests configured.");
desiredRequests = kMinPublishRequestCount;
// Dont allow negative or 0
desiredRequests = minPublishRequests;
}
if (_maxPublishRequests.HasValue && desiredRequests > _maxPublishRequests)
{
desiredRequests = _maxPublishRequests.Value;
}
if (desiredRequests <= 0)
{
desiredRequests = 1;
if (desiredRequests < minPublishRequests)
{
desiredRequests = minPublishRequests;
}
}
session.MinPublishRequestCount = desiredRequests;

Expand Down Expand Up @@ -1218,9 +1222,20 @@ internal void Session_HandlePublishError(ISession session, PublishErrorEventArgs
switch (e.Status.Code)
{
case StatusCodes.BadTooManyPublishRequests:
_maxPublishRequests = GoodPublishRequestCount;
_logger.LogDebug("Limiting number of queued publish requests to {Limit}...",
_maxPublishRequests);
var limit = GoodPublishRequestCount;
var minPublishRequests = MinPublishRequests ?? kMinPublishRequestCount;
if (minPublishRequests <= 0)
{
minPublishRequests = 1;
}
if (limit <= minPublishRequests)
{
break;
}
_maxPublishRequests = limit;
_logger.LogInformation(
"Too many publish request error: Limiting number of requests to {Limit}...",
limit);
break;
case StatusCodes.BadSessionIdInvalid:
case StatusCodes.BadSecureChannelClosed:
Expand Down Expand Up @@ -1339,6 +1354,10 @@ internal void Session_KeepAlive(ISession session, KeepAliveEventArgs e)
"Got Keep Alive error: {Error} ({TimeStamp}:{ServerState}",
e.Status, e.CurrentTime, e.Status);
}
else
{
EnsureMinimumNumberOfPublishRequestsQueued();
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 978a207

Please sign in to comment.