-
Notifications
You must be signed in to change notification settings - Fork 2k
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
More Transaction Metrics #4781
Merged
benjaminpetit
merged 2 commits into
dotnet:master
from
jason-bragg:TransactionThrotteling
Aug 2, 2018
Merged
More Transaction Metrics #4781
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
src/Orleans.Transactions/Abstractions/ITransactionAgentStatistics.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,18 @@ | ||
| ||
namespace Orleans.Transactions.Abstractions | ||
{ | ||
public interface ITransactionAgentStatistics | ||
{ | ||
void TrackTransactionStarted(); | ||
long TransactionsStarted { get; } | ||
|
||
void TrackTransactionSucceeded(); | ||
long TransactionsSucceeded { get; } | ||
|
||
void TrackTransactionFailed(); | ||
long TransactionsFailed { get; } | ||
|
||
void TrackTransactionThrottled(); | ||
long TransactionsThrottled { get; } | ||
} | ||
} |
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
51 changes: 51 additions & 0 deletions
51
src/Orleans.Transactions/DistributedTM/TransactionAgentStatistics.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,51 @@ | ||
using System.Threading; | ||
using Orleans.Transactions.Abstractions; | ||
|
||
namespace Orleans.Transactions | ||
{ | ||
public class TransactionAgentStatistics : ITransactionAgentStatistics | ||
{ | ||
private long transactionsStarted; | ||
public long TransactionsStarted => transactionsStarted; | ||
|
||
private long transactionsSucceeded; | ||
public long TransactionsSucceeded => transactionsSucceeded; | ||
|
||
private long transactionsFailed; | ||
public long TransactionsFailed => transactionsFailed; | ||
|
||
private long transactionsThrottled; | ||
public long TransactionsThrottled => transactionsThrottled; | ||
|
||
public void TrackTransactionStarted() | ||
{ | ||
Interlocked.Increment(ref this.transactionsStarted); | ||
} | ||
|
||
public void TrackTransactionSucceeded() | ||
{ | ||
Interlocked.Increment(ref this.transactionsSucceeded); | ||
} | ||
|
||
public void TrackTransactionFailed() | ||
{ | ||
Interlocked.Increment(ref this.transactionsFailed); | ||
} | ||
|
||
public void TrackTransactionThrottled() | ||
{ | ||
Interlocked.Increment(ref this.transactionsThrottled); | ||
} | ||
|
||
public static ITransactionAgentStatistics Copy(ITransactionAgentStatistics initialStatistics) | ||
{ | ||
return new TransactionAgentStatistics | ||
{ | ||
transactionsStarted = initialStatistics.TransactionsStarted, | ||
transactionsSucceeded = initialStatistics.TransactionsSucceeded, | ||
transactionsFailed = initialStatistics.TransactionsFailed, | ||
transactionsThrottled = initialStatistics.TransactionsThrottled | ||
}; | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/Orleans.Transactions/DistributedTM/TransactionAgentStatisticsReporter.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,88 @@ | ||
using System; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using Microsoft.Extensions.Options; | ||
using Orleans.Configuration; | ||
using Orleans.Runtime; | ||
using Orleans.Transactions.Abstractions; | ||
|
||
namespace Orleans.Transactions | ||
{ | ||
public class TransactionAgentStatisticsReporter : ILifecycleParticipant<ISiloLifecycle> | ||
{ | ||
private const string TransactionsStartedTotalMetric = "TransactionAgent.TransactionsStarted.Total"; | ||
private const string TransactionsStartedPerSecondMetric = "TransactionAgent.TransactionsStarted.PerSecond"; | ||
|
||
private const string SuccessfulTransactionsTotalMetric = "TransactionAgent.SuccessfulTransactions.Total"; | ||
private const string SuccessfulTransactionsPerSecondMetric = "TransactionAgent.SuccessfulTransactions.PerSecond"; | ||
|
||
private const string FailedTransactionsTotalMetric = "TransactionAgent.FailedTransactions.Total"; | ||
private const string FailedTransactionsPerSecondMetric = "TransactionAgent.FailedTransactions.PerSecond"; | ||
|
||
private const string ThrottledTransactionsTotalMetric = "TransactionAgent.ThrottledTransactions.Total"; | ||
private const string ThrottledTransactionsPerSecondMetric = "TransactionAgent.ThrottledTransactions.PerSecond"; | ||
|
||
private readonly ITransactionAgentStatistics statistics; | ||
private readonly ITelemetryProducer telemetryProducer; | ||
private readonly StatisticsOptions statisticsOptions; | ||
|
||
private ITransactionAgentStatistics lastReported; | ||
private DateTime lastReportTime; | ||
private IDisposable timer; | ||
|
||
public TransactionAgentStatisticsReporter(ITransactionAgentStatistics statistics, ITelemetryProducer telemetryProducer, IOptions<StatisticsOptions> options) | ||
{ | ||
this.statistics = statistics ?? throw new ArgumentNullException(nameof(statistics)); | ||
this.telemetryProducer = telemetryProducer ?? throw new ArgumentNullException(nameof(statistics)); | ||
this.statisticsOptions = options.Value; | ||
this.lastReported = TransactionAgentStatistics.Copy(statistics); | ||
this.lastReportTime = DateTime.UtcNow; | ||
} | ||
|
||
public void Participate(ISiloLifecycle lifecycle) | ||
{ | ||
lifecycle.Subscribe<TransactionAgentStatisticsReporter>(ServiceLifecycleStage.Active, OnStart, OnStop); | ||
} | ||
|
||
private Task OnStart(CancellationToken tc) | ||
{ | ||
this.timer = new Timer(ReportMetrics, null, this.statisticsOptions.PerfCountersWriteInterval, this.statisticsOptions.PerfCountersWriteInterval); | ||
return Task.CompletedTask; | ||
} | ||
|
||
private Task OnStop(CancellationToken tc) | ||
{ | ||
this.timer?.Dispose(); | ||
this.timer = null; | ||
return Task.CompletedTask; | ||
} | ||
|
||
|
||
private void ReportMetrics(object ignore) | ||
{ | ||
ITransactionAgentStatistics currentReported = TransactionAgentStatistics.Copy(statistics); | ||
var now = DateTime.UtcNow; | ||
TimeSpan reportPeriod = now - this.lastReportTime; | ||
|
||
this.telemetryProducer.TrackMetric(TransactionsStartedTotalMetric, currentReported.TransactionsStarted); | ||
this.telemetryProducer.TrackMetric(TransactionsStartedPerSecondMetric, PerSecond(this.lastReported.TransactionsStarted, currentReported.TransactionsStarted, reportPeriod)); | ||
|
||
this.telemetryProducer.TrackMetric(SuccessfulTransactionsTotalMetric, currentReported.TransactionsSucceeded); | ||
this.telemetryProducer.TrackMetric(SuccessfulTransactionsPerSecondMetric, PerSecond(this.lastReported.TransactionsSucceeded, currentReported.TransactionsSucceeded, reportPeriod)); | ||
|
||
this.telemetryProducer.TrackMetric(FailedTransactionsTotalMetric, currentReported.TransactionsFailed); | ||
this.telemetryProducer.TrackMetric(FailedTransactionsPerSecondMetric, PerSecond(this.lastReported.TransactionsFailed, currentReported.TransactionsFailed, reportPeriod)); | ||
|
||
this.telemetryProducer.TrackMetric(ThrottledTransactionsTotalMetric, currentReported.TransactionsThrottled); | ||
this.telemetryProducer.TrackMetric(ThrottledTransactionsPerSecondMetric, PerSecond(this.lastReported.TransactionsThrottled, currentReported.TransactionsThrottled, reportPeriod)); | ||
|
||
this.lastReportTime = now; | ||
this.lastReported = currentReported; | ||
} | ||
|
||
private long PerSecond(long start, long end, TimeSpan time) | ||
{ | ||
return ((end - start) * 1000) / Math.Max(1,(long)time.TotalMilliseconds); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where do you track ITransactionAgentStatistic.Throttled ? did I miss anything. I thought it will be tracked here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's tracked in the transaction agent, where the IsOverloaded is called. The agent is responsible for updating it's statistics.