Implement BackgroundGCPeriod

Tough decision to make, but I promised going for full performance, so there is that.
This commit is contained in:
JustArchi
2017-08-14 05:31:01 +02:00
parent 7fe0b4499b
commit c13fd10bd8
5 changed files with 13 additions and 10 deletions

View File

@@ -18,6 +18,8 @@
<RepositoryUrl>https://github.com/JustArchi/ArchiSteamFarm.git</RepositoryUrl>
<PackageIconUrl>https://github.com/JustArchi/ArchiSteamFarm/raw/master/resources/ASF.ico</PackageIconUrl>
<RepositoryType>Git</RepositoryType>
<ServerGarbageCollection>true</ServerGarbageCollection>
<ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">

View File

@@ -49,6 +49,9 @@ namespace ArchiSteamFarm {
[JsonProperty(Required = Required.DisallowNull)]
internal readonly bool AutoUpdates = true;
[JsonProperty(Required = Required.DisallowNull)]
internal readonly byte BackgroundGCPeriod;
[SuppressMessage("ReSharper", "CollectionNeverUpdated.Global")]
[JsonProperty(Required = Required.DisallowNull)]
internal readonly HashSet<uint> Blacklist = new HashSet<uint>();

View File

@@ -28,18 +28,16 @@ using System.Threading;
namespace ArchiSteamFarm {
internal static class Hacks {
private const byte GarbageCollectorDelay = 1;
private static Timer GarbageCollectionTimer;
private static Timer GarbageCompactionTimer;
internal static void Init() {
internal static void EnableBackgroundGC(byte period) {
if (GarbageCollectionTimer == null) {
GarbageCollectionTimer = new Timer(
e => GC.Collect(),
null,
TimeSpan.FromSeconds(GarbageCollectorDelay), // Delay
TimeSpan.FromSeconds(GarbageCollectorDelay) // Period
TimeSpan.FromSeconds(period), // Delay
TimeSpan.FromSeconds(period) // Period
);
}
@@ -47,8 +45,8 @@ namespace ArchiSteamFarm {
GarbageCompactionTimer = new Timer(
e => GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce,
null,
TimeSpan.FromMinutes(GarbageCollectorDelay), // Delay
TimeSpan.FromMinutes(GarbageCollectorDelay) // Period
TimeSpan.FromMinutes(period), // Delay
TimeSpan.FromMinutes(period) // Period
);
}
}

View File

@@ -31,7 +31,6 @@ using System.IO;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime;
using System.Threading.Tasks;
using ArchiSteamFarm.Localization;
using NLog;
@@ -238,8 +237,8 @@ namespace ArchiSteamFarm {
return;
}
if (GCSettings.IsServerGC) {
Hacks.Init();
if (GlobalConfig.BackgroundGCPeriod > 0) {
Hacks.EnableBackgroundGC(GlobalConfig.BackgroundGCPeriod);
}
if (!string.IsNullOrEmpty(GlobalConfig.CurrentCulture)) {

View File

@@ -1,6 +1,7 @@
{
"AutoRestart": true,
"AutoUpdates": true,
"BackgroundGCPeriod": 0,
"Blacklist": [],
"ConnectionTimeout": 60,
"CurrentCulture": null,