-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5289624
commit 7b4fa11
Showing
12 changed files
with
780 additions
and
190 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
src/Orleans.Runtime/Catalog/ActivationData.Diagnostics.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Orleans.Configuration; | ||
|
||
namespace Orleans.Runtime; | ||
|
||
internal partial class ActivationData | ||
{ | ||
public void AnalyzeWorkload(DateTime now, IMessageCenter messageCenter, MessageFactory messageFactory, SiloMessagingOptions options) | ||
{ | ||
var slowRunningRequestDuration = options.RequestProcessingWarningTime; | ||
var longQueueTimeDuration = options.RequestQueueDelayWarningTime; | ||
|
||
List<string> diagnostics = null; | ||
lock (this) | ||
{ | ||
if (State != ActivationState.Valid) | ||
{ | ||
return; | ||
} | ||
|
||
if (_blockingRequest is Message request) | ||
{ | ||
TimeSpan? timeSinceQueued = default; | ||
if (_runningRequests.TryGetValue(request, out var waitTime)) | ||
{ | ||
timeSinceQueued = waitTime.Elapsed; | ||
} | ||
|
||
var executionTime = _busyDuration.Elapsed; | ||
if (executionTime >= slowRunningRequestDuration) | ||
{ | ||
GetStatusList(ref diagnostics); | ||
if (timeSinceQueued.HasValue) | ||
{ | ||
diagnostics.Add($"Message {request} was enqueued {timeSinceQueued} ago and has now been executing for {executionTime}."); | ||
} | ||
else | ||
{ | ||
diagnostics.Add($"Message {request} has been executing for {executionTime}."); | ||
} | ||
|
||
if (request is Message msg) | ||
{ | ||
var response = messageFactory.CreateDiagnosticResponseMessage(msg, isExecuting: true, isWaiting: false, diagnostics); | ||
messageCenter.SendMessage(response); | ||
} | ||
} | ||
} | ||
else if (_blockingRequest is GrainTimer timer) | ||
{ | ||
/* | ||
var executionTime = timer.GetElapsed(); | ||
if (executionTime >= slowRunningRequestDuration) | ||
{ | ||
GetStatusList(ref diagnostics); | ||
diagnostics.Add($"Timer {timer} has been executing for {executionTime}."); | ||
var response = messageFactory.CreateDiagnosticResponseMessage(timer, isExecuting: true, isWaiting: false, diagnostics); | ||
messageCenter.SendMessage(response); | ||
} | ||
*/ | ||
} | ||
|
||
foreach (var running in _runningRequests) | ||
{ | ||
var message = running.Key; | ||
var runDuration = running.Value; | ||
if (ReferenceEquals(message, _blockingRequest)) continue; | ||
|
||
// Check how long they've been executing. | ||
var executionTime = runDuration.Elapsed; | ||
if (executionTime >= slowRunningRequestDuration) | ||
{ | ||
// Interleaving message X has been executing for a long time | ||
GetStatusList(ref diagnostics); | ||
var messageDiagnostics = new List<string>(diagnostics) | ||
{ | ||
$"Interleaving message {message} has been executing for {executionTime}." | ||
}; | ||
|
||
if (message is Message msg) | ||
{ | ||
var response = messageFactory.CreateDiagnosticResponseMessage(msg, isExecuting: true, isWaiting: false, messageDiagnostics); | ||
messageCenter.SendMessage(response); | ||
} | ||
} | ||
} | ||
|
||
var queueLength = 1; | ||
foreach (var pair in _waitingRequests) | ||
{ | ||
var message = pair.Request; | ||
var queuedTime = pair.QueuedTime.Elapsed; | ||
if (queuedTime >= longQueueTimeDuration) | ||
{ | ||
// Message X has been enqueued on the target grain for Y and is currently position QueueLength in queue for processing. | ||
GetStatusList(ref diagnostics); | ||
var messageDiagnostics = new List<string>(diagnostics) | ||
{ | ||
$"Message {message} has been enqueued on the target grain for {queuedTime} and is currently position {queueLength} in queue for processing." | ||
}; | ||
|
||
if (message is Message msg) | ||
{ | ||
var response = messageFactory.CreateDiagnosticResponseMessage(msg, isExecuting: false, isWaiting: true, messageDiagnostics); | ||
messageCenter.SendMessage(response); | ||
} | ||
} | ||
|
||
queueLength++; | ||
} | ||
} | ||
|
||
void GetStatusList(ref List<string> diagnostics) | ||
{ | ||
if (diagnostics is not null) return; | ||
|
||
diagnostics = new List<string> | ||
{ | ||
ToDetailedString(), | ||
$"TaskScheduler status: {_workItemGroup.DumpStatus()}" | ||
}; | ||
} | ||
} | ||
} |
Oops, something went wrong.