forked from ACEmulator/ACE
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cumulative updates (ACEmulator#4180)
* Many lb group performance related updates * fixes * tweak partitioner * Implement LandblockGroupMinSpacingWhenDormant * More threaddebug * cleanup
- Loading branch information
Showing
13 changed files
with
278 additions
and
266 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
80 changes: 80 additions & 0 deletions
80
Source/ACE.Common/Performance/RollingAmountOverHitsTracker.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,80 @@ | ||
using System; | ||
|
||
namespace ACE.Common.Performance | ||
{ | ||
public class RollingAmountOverHitsTracker | ||
{ | ||
public readonly long HitsBeingTracked; | ||
|
||
private readonly double[] amounts; | ||
|
||
private int nextIndex = 0; | ||
|
||
private bool rolledOver; | ||
|
||
|
||
public double LastAmount { get; private set; } | ||
|
||
public long TotalAmounts | ||
{ | ||
get | ||
{ | ||
if (rolledOver) | ||
return HitsBeingTracked; | ||
|
||
return nextIndex; | ||
} | ||
} | ||
|
||
public double Sum { get; private set; } | ||
|
||
public double AverageAmount => TotalAmounts == 0 ? 0 : Sum / TotalAmounts; | ||
|
||
/// <summary> | ||
/// Use this sparingly as it iterates over the entire collection | ||
/// </summary> | ||
public double LargestAmount | ||
{ | ||
get | ||
{ | ||
if (TotalAmounts == 0) | ||
return 0; | ||
|
||
var largest = double.MinValue; | ||
|
||
for (int i = 0; i < TotalAmounts; i++) | ||
{ | ||
if (amounts[i] > largest) | ||
largest = amounts[i]; | ||
} | ||
|
||
return largest; | ||
} | ||
} | ||
|
||
public RollingAmountOverHitsTracker(long hitsToTrack) | ||
{ | ||
HitsBeingTracked = hitsToTrack; | ||
|
||
amounts = new double[hitsToTrack]; | ||
} | ||
|
||
|
||
public void RegisterAmount(double amount) | ||
{ | ||
LastAmount = amount; | ||
|
||
Sum -= amounts[nextIndex]; | ||
amounts[nextIndex] = amount; | ||
Sum += amounts[nextIndex]; | ||
|
||
nextIndex++; | ||
|
||
if (nextIndex == HitsBeingTracked) | ||
{ | ||
nextIndex = 0; | ||
rolledOver = true; | ||
} | ||
} | ||
} | ||
} |
69 changes: 69 additions & 0 deletions
69
Source/ACE.Common/Performance/RollingAmountOverTimeTracker.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,69 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace ACE.Common.Performance | ||
{ | ||
public class RollingAmountOverTimeTracker | ||
{ | ||
public readonly TimeSpan TimeBeingTracked; | ||
|
||
private readonly LinkedList<Tuple<DateTime, double>> amounts = new LinkedList<Tuple<DateTime, double>>(); | ||
|
||
|
||
public double LastAmount { get; private set; } | ||
|
||
public long TotalAmounts => amounts.Count; | ||
|
||
public double Sum { get; private set; } | ||
|
||
public double AverageAmount => TotalAmounts == 0 ? 0 : Sum / TotalAmounts; | ||
|
||
/// <summary> | ||
/// Use this sparingly as it iterates over the entire collection | ||
/// </summary> | ||
public double LargestAmount | ||
{ | ||
get | ||
{ | ||
if (TotalAmounts == 0) | ||
return 0; | ||
|
||
var largest = double.MinValue; | ||
|
||
foreach (var amount in amounts) | ||
{ | ||
if (amount.Item2 > largest) | ||
largest = amount.Item2; | ||
} | ||
|
||
return largest; | ||
} | ||
} | ||
|
||
public RollingAmountOverTimeTracker(TimeSpan timeToTrack) | ||
{ | ||
TimeBeingTracked = timeToTrack; | ||
} | ||
|
||
|
||
public void RegisterAmount(double amount) | ||
{ | ||
LastAmount = amount; | ||
|
||
var now = DateTime.UtcNow; | ||
|
||
var pruneBefore = now - TimeBeingTracked; | ||
|
||
while (amounts.Count > 0 && amounts.First.Value.Item1 < pruneBefore) | ||
{ | ||
Sum -= amounts.First.Value.Item2; | ||
|
||
amounts.RemoveFirst(); | ||
} | ||
|
||
Sum += amount; | ||
|
||
amounts.AddLast(new Tuple<DateTime, double>(now, amount)); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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.