Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 9 additions & 4 deletions src/DurableTask.Netherite.AzureFunctions/NetheriteProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public NetheriteProvider(

public override string EventSourceName => "DurableTask-Netherite";

NetheriteMetricsProvider metricsProvider;

/// <inheritdoc/>
public async override Task<string> RetrieveSerializedEntityState(EntityId entityId, JsonSerializerSettings serializerSettings)
{
Expand Down Expand Up @@ -130,7 +132,6 @@ public override bool TryGetScaleMonitor(
}
}

#if !NETSTANDARD
public override bool TryGetTargetScaler(
string functionId,
string functionName,
Expand All @@ -139,13 +140,17 @@ public override bool TryGetTargetScaler(
out ITargetScaler targetScaler)
{
ILoadPublisherService loadPublisher = this.Service.GetLoadPublisher();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be inside the conditional below, I think.

NetheriteMetricsProvider metricsProvider = this.Service.GetNetheriteMetricsProvider(loadPublisher, this.Settings.EventHubsConnection);

targetScaler = new NetheriteTargetScaler(functionId, metricsProvider, this);
// Target Scaler is created per function id. And they share the same NetheriteMetricsProvider.
if ( this.metricsProvider == null)
{
this.metricsProvider = this.Service.GetNetheriteMetricsProvider(loadPublisher, this.Settings.EventHubsConnection);
}

targetScaler = new NetheriteTargetScaler(functionId, this.metricsProvider, this);

return true;
}
#endif

public class NetheriteScaleMetrics : ScaleMetrics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public bool TryGetScalingMonitor(out ScalingMonitor monitor)
internal ILoadPublisherService GetLoadPublisher()
{
return string.IsNullOrEmpty(this.Settings.LoadInformationAzureTableName) ?
new AzureBlobLoadPublisher(this.Settings.BlobStorageConnection, this.Settings.HubName)
new AzureBlobLoadPublisher(this.Settings.BlobStorageConnection, this.Settings.HubName, this.Settings.TaskhubParametersFilePath)
Comment thread
nytian marked this conversation as resolved.
: new AzureTableLoadPublisher(this.Settings.TableStorageConnection, this.Settings.LoadInformationAzureTableName, this.Settings.HubName);
}

Expand Down
26 changes: 19 additions & 7 deletions src/DurableTask.Netherite/Scaling/NetheriteMetricsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class NetheriteMetricsProvider
readonly ILoadPublisherService loadPublisher;
readonly ConnectionInfo eventHubsConnection;

DateTime lastMetricsQueryTime = DateTime.MinValue;
Metrics metrics = default;

public NetheriteMetricsProvider(
ILoadPublisherService loadPublisher,
ConnectionInfo eventHubsConnection)
Expand All @@ -26,15 +29,24 @@ public NetheriteMetricsProvider(
public virtual async Task<Metrics> GetMetricsAsync()
{
DateTime now = DateTime.UtcNow;
var loadInformation = await this.loadPublisher.QueryAsync(CancellationToken.None).ConfigureAwait(false);
var busy = await this.TaskHubIsIdleAsync(loadInformation).ConfigureAwait(false);

return new Metrics()
// Collect the metrics every 5 seconds to avoid excessive poling.
// If calling this method more frequently, return the cached metrics.
if ( now >= this.lastMetricsQueryTime.AddSeconds(5))
{
LoadInformation = loadInformation,
Busy = busy,
Timestamp = now,
};
var loadInformation = await this.loadPublisher.QueryAsync(CancellationToken.None).ConfigureAwait(false);
var busy = await this.TaskHubIsIdleAsync(loadInformation).ConfigureAwait(false);

this.lastMetricsQueryTime = now;
this.metrics = new Metrics()
{
LoadInformation = loadInformation,
Busy = busy,
Timestamp = now,
};
}

return this.metrics;
}

/// <summary>
Expand Down