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

Expose activation working set as a metric #8291

Merged
merged 6 commits into from
Jan 30, 2023
Merged
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
7 changes: 7 additions & 0 deletions src/Orleans.Core/Diagnostics/Metrics/CatalogInstruments.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,15 @@ internal static class CatalogInstruments
internal static readonly Counter<int> ActivationsDestroyed = Instruments.Meter.CreateCounter<int>(InstrumentNames.CATALOG_ACTIVATION_DESTROYED);

internal static ObservableGauge<int> ActivationCount;

internal static void RegisterActivationCountObserve(Func<int> observeValue)
{
ActivationCount = Instruments.Meter.CreateObservableGauge(InstrumentNames.CATALOG_ACTIVATION_COUNT, observeValue);
}

internal static ObservableGauge<int> ActivationWorkingSet;
internal static void RegisterActivationWorkingSetObserve(Func<int> observeValue)
{
ActivationWorkingSet = Instruments.Meter.CreateObservableGauge(InstrumentNames.CATALOG_ACTIVATION_WORKING_SET, observeValue);
}
}
1 change: 1 addition & 0 deletions src/Orleans.Core/Diagnostics/Metrics/InstrumentNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ internal static class InstrumentNames

// Catalog
public const string CATALOG_ACTIVATION_COUNT = "orleans-catalog-activations";
public const string CATALOG_ACTIVATION_WORKING_SET = "orleans-catalog-activation-working-set";
public const string CATALOG_ACTIVATION_CREATED = "orleans-catalog-activation-created";
public const string CATALOG_ACTIVATION_DESTROYED = "orleans-catalog-activation-destroyed";
public const string CATALOG_ACTIVATION_FAILED_TO_ACTIVATE = "orleans-catalog-activation-failed-to-activate";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal static class MessagingInstruments
internal static readonly Counter<int> ReroutedMessagesCounter = Instruments.Meter.CreateCounter<int>(InstrumentNames.MESSAGING_REROUTED);
internal static readonly Counter<int> ExpiredMessagesCounter = Instruments.Meter.CreateCounter<int>(InstrumentNames.MESSAGING_EXPIRED);

internal static readonly Counter<int> ConnectedClient = Instruments.Meter.CreateCounter<int>(InstrumentNames.GATEWAY_CONNECTED_CLIENTS);
internal static readonly UpDownCounter<int> ConnectedClient = Instruments.Meter.CreateUpDownCounter<int>(InstrumentNames.GATEWAY_CONNECTED_CLIENTS);
internal static readonly Counter<int> PingSendCounter = Instruments.Meter.CreateCounter<int>(InstrumentNames.MESSAGING_PINGS_SENT);
internal static readonly Counter<int> PingReceivedCounter = Instruments.Meter.CreateCounter<int>(InstrumentNames.MESSAGING_PINGS_RECEIVED);
internal static readonly Counter<int> PingReplyReceivedCounter = Instruments.Meter.CreateCounter<int>(InstrumentNames.MESSAGING_PINGS_REPLYRECEIVED);
Expand Down
4 changes: 2 additions & 2 deletions src/Orleans.Runtime/Catalog/ActivationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private bool IsStuckProcessingMessage

public TimeSpan CollectionAgeLimit => _shared.CollectionAgeLimit;

public TTarget GetTarget<TTarget>() where TTarget : class => (TTarget)GrainInstance;
public TTarget GetTarget<TTarget>() where TTarget : class => (TTarget)GrainInstance;

TComponent ITargetHolder.GetComponent<TComponent>()
{
Expand Down Expand Up @@ -1202,7 +1202,7 @@ async Task<bool> CallActivateAsync(Dictionary<string, object> requestContextData
{
CatalogInstruments.ActivationFailedToActivate.Add(1);

// Capture the exeption so that it can be propagated to rejection messages
// Capture the exception so that it can be propagated to rejection messages
var sourceException = (exception as OrleansLifecycleCanceledException)?.InnerException ?? exception;
_shared.Logger.LogError((int)ErrorCode.Catalog_ErrorCallingActivate, sourceException, "Error activating grain {Grain}", this);

Expand Down
45 changes: 32 additions & 13 deletions src/Orleans.Runtime/Catalog/ActivationDirectory.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,46 @@
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Threading;

namespace Orleans.Runtime
namespace Orleans.Runtime;

internal sealed class ActivationDirectory : IEnumerable<KeyValuePair<GrainId, IGrainContext>>
{
internal sealed class ActivationDirectory : IEnumerable<KeyValuePair<GrainId, IGrainContext>>
private int _activationsCount;

private readonly ConcurrentDictionary<GrainId, IGrainContext> _activations = new();

public ActivationDirectory()
{
private readonly ConcurrentDictionary<GrainId, IGrainContext> _activations = new();
CatalogInstruments.RegisterActivationCountObserve(() => Count);
}

public int Count => _activations.Count;
public int Count => _activationsCount;

public IGrainContext FindTarget(GrainId key)
public IGrainContext FindTarget(GrainId key)
{
_activations.TryGetValue(key, out var result);
return result;
}

public void RecordNewTarget(IGrainContext target)
{
if (_activations.TryAdd(target.GrainId, target))
{
_activations.TryGetValue(key, out var result);
return result;
Interlocked.Increment(ref _activationsCount);
}
}

public void RecordNewTarget(IGrainContext target) => _activations.TryAdd(target.GrainId, target);

public void RemoveTarget(IGrainContext target) => _activations.TryRemove(KeyValuePair.Create(target.GrainId, target));
public void RemoveTarget(IGrainContext target)
{
if (_activations.TryRemove(KeyValuePair.Create(target.GrainId, target)))
{
Interlocked.Decrement(ref _activationsCount);
}
}

public IEnumerator<KeyValuePair<GrainId, IGrainContext>> GetEnumerator() => _activations.GetEnumerator();
public IEnumerator<KeyValuePair<GrainId, IGrainContext>> GetEnumerator() => _activations.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
}
1 change: 1 addition & 0 deletions src/Orleans.Runtime/Catalog/ActivationWorkingSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public ActivationWorkingSet(
_logger = logger;
_scanPeriodTimer = asyncTimerFactory.Create(TimeSpan.FromMilliseconds(100), nameof(ActivationWorkingSet) + "." + nameof(MonitorWorkingSet));
_observers = observers.ToList();
CatalogInstruments.RegisterActivationWorkingSetObserve(() => Count);
}

public int Count => _activeCount;
Expand Down
1 change: 0 additions & 1 deletion src/Orleans.Runtime/Catalog/Catalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public Catalog(

GC.GetTotalMemory(true); // need to call once w/true to ensure false returns OK value

CatalogInstruments.RegisterActivationCountObserve(() => activations.Count);
MessagingProcessingInstruments.RegisterActivationDataAllObserve(() =>
{
long counter = 0;
Expand Down