Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[For internal investigation][Do note merge] Add logs around semaphore waitasync and release. #1062

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ public class AzureStorageOrchestrationServiceSettings
/// </summary>
public int MaxStorageOperationConcurrency { get; set; } = Environment.ProcessorCount * 25;

/// <summary>
/// Max wait time to wait for semaphore to process after which log should be added.
/// </summary>
public int MaxWaitForSemaphoreLoggingInSeconds { get; set; } = 20;

/// <summary>
/// Gets the maximum number of orchestrator actions to checkpoint at a time.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<PatchVersion>1</PatchVersion>

<VersionPrefix>$(MajorVersion).$(MinorVersion).$(PatchVersion)</VersionPrefix>
<FileVersion>$(VersionPrefix).0</FileVersion>
<FileVersion>$(VersionPrefix)-semaphorelogs.4</FileVersion>
<!-- FileVersionRevision is expected to be set by the CI. This is useful for distinguishing between multiple builds of the same version. -->
<FileVersion Condition="'$(FileVersionRevision)' != ''">$(VersionPrefix).$(FileVersionRevision)</FileVersion>
<!-- The assembly version is only the major/minor pair, making it easier to do in-place upgrades -->
Expand Down
36 changes: 36 additions & 0 deletions src/DurableTask.AzureStorage/Storage/AzureStorageClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace DurableTask.AzureStorage.Storage
{
using System;
using System.Diagnostics;
using System.Threading;
using System.Threading.Tasks;
using DurableTask.AzureStorage.Monitoring;
Expand Down Expand Up @@ -127,9 +128,16 @@ public Task MakeTableStorageRequest(Func<OperationContext, CancellationToken, Ta

private async Task<T> MakeStorageRequest<T>(Func<OperationContext, CancellationToken, Task<T>> storageRequest, string accountName, string operationName, string? clientRequestId = null, bool force = false)
{
Guid guid = Guid.NewGuid();

if (!force)
{
var cTkWait = new CancellationTokenSource();
_ = WaitAndLog(guid, "Wait", cTkWait.Token);

await requestThrottleSemaphore.WaitAsync();

cTkWait.Cancel();
}

try
Expand All @@ -144,7 +152,12 @@ private async Task<T> MakeStorageRequest<T>(Func<OperationContext, CancellationT
{
if (!force)
{
var cTkRelease = new CancellationTokenSource();
_ = WaitAndLog(guid, "Release", cTkRelease.Token);

requestThrottleSemaphore.Release();

cTkRelease.Cancel();
}
}
}
Expand All @@ -160,5 +173,28 @@ private Task MakeStorageRequest(Func<OperationContext, CancellationToken, Task>

private static string GetAccountName(StorageCredentials credentials, AzureStorageOrchestrationServiceSettings settings, StorageUri serviceUri, string service) =>
credentials.AccountName ?? settings.StorageAccountDetails?.AccountName ?? serviceUri.GetAccountName(service) ?? "(unknown)";

private async Task WaitAndLog(Guid guid, string waitOrRelease, CancellationToken cTk)
{
if (this.Settings.MaxWaitForSemaphoreLoggingInSeconds >= 0)
{
await Task.Delay(this.Settings.MaxWaitForSemaphoreLoggingInSeconds * 1000, cTk);

if (!cTk.IsCancellationRequested)
{
StackTrace stackTrace = new StackTrace();

this.Settings?.Logger.PartitionManagerInfo(
this.Settings?.StorageAccountDetails?.AccountName,
this.Settings?.TaskHubName,
this.Settings?.WorkerId,
string.Empty,
$"Before {waitOrRelease} Id:{guid.ToString()}, processId: {Thread.CurrentThread.ManagedThreadId}" +
$"| Semaphore currentCount = {requestThrottleSemaphore.CurrentCount}" +
$"| Semaphore initialCount = {this.Settings?.MaxStorageOperationConcurrency}" +
$"| StackTrace : {stackTrace.ToString()}");
}
}
}
}
}