定时手动GC

This commit is contained in:
ChenYi 2025-11-07 11:48:22 +08:00
parent edcf86edea
commit 7df62d5ee1
6 changed files with 59 additions and 30 deletions

View File

@ -6,10 +6,10 @@ namespace JiShe.IoT.Extensions.Hangfire
{
public static void CreateRecurringJob(this ApplicationInitializationContext context)
{
RecurringJob.AddOrUpdate<TestJob>("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions()
{
TimeZone = TimeZoneInfo.Local
});
//RecurringJob.AddOrUpdate<GCCollectJob>("测试Job", e => e.ExecuteAsync(), CronType.Minute(1), new RecurringJobOptions()
//{
// TimeZone = TimeZoneInfo.Local
//});
}
}
}

View File

@ -4,19 +4,19 @@
"CorsOrigins": "https://*.IoT.com,http://localhost:4200,http://localhost:3100,http://localhost:80,http://10.10.90.3:4200"
},
"ConnectionStrings": {
"Default": "Data Source=47.110.53.196;Port=13306;Database=JiSheIoTProDB;uid=root;pwd=JiShe!aqG#5kGgh&0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true;TreatTinyAsBoolean=false;SslMode=None;Pooling=true;"
"Default": "Data Source=192.168.111.174;Port=13306;Database=JiSheIoTProDB;uid=root;pwd=JiShe!aqG#5kGgh&0;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true;TreatTinyAsBoolean=false;SslMode=None;Pooling=true;"
},
"Hangfire": {
"Redis": {
"Host": "47.110.53.196:30712,password=1q3J@BGf!yhTaD46nS#",
"Host": "192.168.111.174:30712,password=1q3J@BGf!yhTaD46nS#",
"DB": "2"
}
},
"Redis": {
"Configuration": "47.110.53.196:30712,password=1q3J@BGf!yhTaD46nS#,defaultdatabase=5"
"Configuration": "192.168.111.174:30712,password=1q3J@BGf!yhTaD46nS#,defaultdatabase=5"
},
"Kafka": {
"BootstrapServers": "47.110.62.104:9094,47.110.53.196:9094,47.110.60.222:9094",
"BootstrapServers": "47.110.62.104:9094,192.168.111.174:9094,47.110.60.222:9094",
"EnableFilter": true,
"EnableAuthorization": false,
"SaslUserName": "lixiao",
@ -26,8 +26,8 @@
"TaskThreadCount": -1
},
"Pulsar": {
"ServiceUrl": "pulsar://47.110.53.196:9093",
"WebUrl": "http://47.110.53.196:9094",
"ServiceUrl": "pulsar://192.168.111.174:26974",
"WebUrl": "http://192.168.111.174:9094",
"UserName": "admin",
"TenantName": "1YMVZZkAkRArjxSD8457",
"Namespace": "OneNET",
@ -56,10 +56,10 @@
"IoTDBOptions": {
"UserName": "root",
"Password": "Lixiao@1980",
//"TreeModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
//"TableModelClusterList": [ "47.110.53.196:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
"TreeModelClusterList": [ "47.110.53.196:30710" ],
"TableModelClusterList": [ "47.110.53.196:30710" ],
//"TreeModelClusterList": [ "192.168.111.174:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
//"TableModelClusterList": [ "192.168.111.174:6667", "47.110.60.222:6667", "47.110.62.104:6667" ],
"TreeModelClusterList": [ "192.168.111.174:30710" ],
"TableModelClusterList": [ "192.168.111.174:30710" ],
"PoolSize": 32,
"DataBaseName": "jisheiotdata",
"OpenDebugMode": false,
@ -95,7 +95,7 @@
}
},
"FreeRedisOptions": {
"ConnectionString": "47.110.53.196:30712,password=1q3J@BGf!yhTaD46nS#,abortConnect=false,connectTimeout=30000,allowAdmin=true,maxPoolSize=500,defaultdatabase=14",
"ConnectionString": "192.168.111.174:30712,password=1q3J@BGf!yhTaD46nS#,abortConnect=false,connectTimeout=30000,allowAdmin=true,maxPoolSize=500,defaultdatabase=14",
"UseDistributedCache": true
},
"FreeSqlProviderOptions": {

View File

@ -1,5 +1,5 @@
using JiShe.IoT.CommonServices;
using JiShe.IoT.Jobs.ToRedis;
using JiShe.IoT.Jobs;
using JiShe.ServicePro.CTWingManagement;
using JiShe.ServicePro.DeviceManagement;
using JiShe.ServicePro.DynamicMenuManagement;
@ -46,12 +46,12 @@ namespace JiShe.IoT
public override void PostConfigureServices(ServiceConfigurationContext context)
{
// 定时任务
//ConfigureBackgroundJob(context);
ConfigureBackgroundJob(context);
}
private static void ConfigureBackgroundJob(ServiceConfigurationContext context)
{
context.Services.AddHostedService<CacheDeviceDataToRedisJob>();
context.Services.AddHostedService<GCCollectJob>();
}
public override void OnApplicationInitialization(ApplicationInitializationContext context)

View File

@ -7,7 +7,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.IoT.Jobs.ToRedis
namespace JiShe.IoT.Jobs
{
/// <summary>
/// 缓存设备数据到redis

View File

@ -0,0 +1,40 @@
using JiShe.ServicePro.Core;
using JiShe.ServicePro.DeviceManagement.DeviceInfos;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace JiShe.IoT.Jobs
{
/// <summary>
/// GCCollect 定时手动回收
/// </summary>
public class GCCollectJob : SystemBackGroundWorkService
{
private readonly ILogger<GCCollectJob> _logger;
public GCCollectJob(ILogger<GCCollectJob> logger) : base(logger)
{
_logger = logger;
}
/// <summary>
/// 定时执行
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
protected override Task DoWorkAsync(CancellationToken cancellationToken)
{
CommonHelper.GCCollectHandler();
_logger.LogWarning("执行手动GC.Collect()");
return Task.CompletedTask;
}
protected override TimeSpan GetInterval()
{
return TimeSpan.FromMinutes(5);
}
}
}

View File

@ -1,11 +0,0 @@
namespace JiShe.IoT.Jobs
{
public class TestJob : IRecurringJob
{
public Task ExecuteAsync()
{
Console.WriteLine($"job 测试- {DateTime.Now}");
return Task.CompletedTask;
}
}
}