Skip to content

Commit 9b8e17c

Browse files
committed
[增加] 增加空闲Actor回收的时间配置
1 parent 9cc765e commit 9b8e17c

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

GameFrameX.Core/Actors/ActorManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,11 @@ public static Task CheckIdle()
242242

243243
async Task Func()
244244
{
245-
if (actor.AutoRecycle && (TimeHelper.GetUtcNow() - ActiveTimeDic[actor.Id]).TotalMinutes > 15)
245+
if (actor.AutoRecycle && (TimeHelper.GetUtcNow() - ActiveTimeDic[actor.Id]).TotalMinutes > GlobalSettings.CurrentSetting.ActorRecycleTime)
246246
{
247247
async Task<bool> Work()
248248
{
249-
if (ActiveTimeDic.TryGetValue(actor.Id, out var activeTime) && (TimeHelper.GetUtcNow() - ActiveTimeDic[actor.Id]).TotalMinutes > 15)
249+
if (ActiveTimeDic.TryGetValue(actor.Id, out var activeTime) && (TimeHelper.GetUtcNow() - ActiveTimeDic[actor.Id]).TotalMinutes > GlobalSettings.CurrentSetting.ActorRecycleTime)
250250
{
251251
// 防止定时回存失败时State被直接移除
252252
if (actor.ReadyToDeActive)

GameFrameX.StartUp/Options/LauncherOptions.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,12 @@ public sealed class LauncherOptions
202202
[Option(nameof(ActorQueueTimeOut), Default = 30_000, HelpText = "Actor 执行任务队列超时时间(毫秒),默认值为30秒")]
203203
public int ActorQueueTimeOut { get; set; } = 30_000;
204204

205+
/// <summary>
206+
/// Actor 空闲多久回收,单位分钟,默认值为15分钟,最小值为1分钟,小于1则强制设置为5分钟
207+
/// </summary>
208+
[Option(nameof(ActorRecycleTime), Default = 15, HelpText = "Actor 空闲多久回收,单位分钟,默认值为15分钟,最小值为1分钟,小于1则强制设置为5分钟")]
209+
public int ActorRecycleTime { get; set; } = 15;
210+
205211
/// <summary>
206212
/// 内部IP
207213
/// </summary>

GameFrameX.Utility/Setting/AppSetting.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,11 @@ public string ToFormatString()
223223
/// </summary>
224224
public int ActorTimeOut { get; set; } = 30_000;
225225

226+
/// <summary>
227+
/// Actor 空闲多久回收,单位分钟,默认值为15分钟
228+
/// </summary>
229+
public int ActorRecycleTime { get; set; } = 15;
230+
226231
/// <summary>
227232
/// Actor 执行任务队列超时时间(毫秒),默认值为30秒
228233
/// </summary>

GameFrameX.Utility/Setting/GlobalSettings.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public static void SetCurrentSetting(AppSetting setting)
107107
setting.NetWorkSendTimeOutSeconds = 5;
108108
}
109109

110+
if (setting.ActorRecycleTime < 1)
111+
{
112+
LogHelper.WarnConsole("ActorRecycleTime小于1分钟,使用默认值为:5 分钟");
113+
setting.ActorRecycleTime = 5;
114+
}
115+
110116
// 创建ID生成器配置,WorkerId设为0
111117
var options = new IdGeneratorOptions(setting.WorkerId);
112118
// 初始化雪花算法ID生成器

0 commit comments

Comments
 (0)