add gc interval
This commit is contained in:
parent
73895fbce4
commit
aa7041962a
@ -2,6 +2,7 @@
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using MesETL.App.Services;
|
using MesETL.App.Services;
|
||||||
using MesETL.App.Services.Loggers;
|
using MesETL.App.Services.Loggers;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
|
|
||||||
namespace MesETL.App.HostedServices;
|
namespace MesETL.App.HostedServices;
|
||||||
@ -15,24 +16,32 @@ public class TaskMonitorService
|
|||||||
private readonly ProcessContext _context;
|
private readonly ProcessContext _context;
|
||||||
private readonly DataRecordQueue _producerQueue;
|
private readonly DataRecordQueue _producerQueue;
|
||||||
private readonly RecordQueuePool _queuePool;
|
private readonly RecordQueuePool _queuePool;
|
||||||
|
private readonly IConfiguration _configuration;
|
||||||
|
|
||||||
private string _outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log/progress.txt");
|
private string _outputPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Log/progress.txt");
|
||||||
|
|
||||||
|
private readonly int _gcInterval;
|
||||||
|
|
||||||
public TaskMonitorService(ProcessContext context,
|
public TaskMonitorService(ProcessContext context,
|
||||||
[FromKeyedServices(Const.ConstVar.Producer)]
|
[FromKeyedServices(Const.ConstVar.Producer)]
|
||||||
DataRecordQueue producerQueue,
|
DataRecordQueue producerQueue,
|
||||||
RecordQueuePool queuePool,
|
RecordQueuePool queuePool,
|
||||||
IEnumerable<ITaskMonitorLogger> monitorLoggers)
|
IEnumerable<ITaskMonitorLogger> monitorLoggers,
|
||||||
|
IConfiguration configuration)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
_producerQueue = producerQueue;
|
_producerQueue = producerQueue;
|
||||||
_queuePool = queuePool;
|
_queuePool = queuePool;
|
||||||
_monitorLoggers = monitorLoggers;
|
_monitorLoggers = monitorLoggers;
|
||||||
|
_configuration = configuration;
|
||||||
|
|
||||||
|
_gcInterval = _configuration.GetValue<int>("GCIntervalMilliseconds)");
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task Monitor(CancellationToken stoppingToken)
|
public async Task Monitor(CancellationToken stoppingToken)
|
||||||
{
|
{
|
||||||
var sw = Stopwatch.StartNew();
|
var sw = Stopwatch.StartNew();
|
||||||
|
var lastGCTime = sw.ElapsedMilliseconds;
|
||||||
var lastTime = sw.ElapsedMilliseconds;
|
var lastTime = sw.ElapsedMilliseconds;
|
||||||
var lastInputCount = _context.InputCount;
|
var lastInputCount = _context.InputCount;
|
||||||
var lastTransformCount = _context.TransformCount;
|
var lastTransformCount = _context.TransformCount;
|
||||||
@ -74,6 +83,12 @@ public class TaskMonitorService
|
|||||||
var inputSpeed = (inputCount - lastInputCount) / elapseTime;
|
var inputSpeed = (inputCount - lastInputCount) / elapseTime;
|
||||||
var transformSpeed = (transformCount - lastTransformCount) / elapseTime;
|
var transformSpeed = (transformCount - lastTransformCount) / elapseTime;
|
||||||
var outputSpeed = (outputCount - lastOutputCount) / elapseTime;
|
var outputSpeed = (outputCount - lastOutputCount) / elapseTime;
|
||||||
|
|
||||||
|
if(_gcInterval > 0 && time - lastGCTime > _gcInterval)
|
||||||
|
{
|
||||||
|
GC.Collect();
|
||||||
|
lastGCTime = time;
|
||||||
|
}
|
||||||
|
|
||||||
// _logger.LogInformation(
|
// _logger.LogInformation(
|
||||||
// "Task monitor: running: {Running}, error: {Error}, completed: {Completed}, canceled: {Canceled}, outputSpeed: {Speed} records/s",
|
// "Task monitor: running: {Running}, error: {Error}, completed: {Completed}, canceled: {Canceled}, outputSpeed: {Speed} records/s",
|
||||||
@ -88,6 +103,7 @@ public class TaskMonitorService
|
|||||||
|
|
||||||
{"| Input Queue", _producerQueue.Count.ToString() },
|
{"| Input Queue", _producerQueue.Count.ToString() },
|
||||||
{"Output Queue", _queuePool.Queues.Values.Sum(queue => queue.Count).ToString()},
|
{"Output Queue", _queuePool.Queues.Values.Sum(queue => queue.Count).ToString()},
|
||||||
|
{"Memory", $"{GC.GetTotalMemory(false) / 1024 / 1024} MiB"},
|
||||||
});
|
});
|
||||||
|
|
||||||
var dict = _context.TableProgress
|
var dict = _context.TableProgress
|
||||||
@ -98,6 +114,8 @@ public class TaskMonitorService
|
|||||||
{
|
{
|
||||||
sb.AppendLine($"{kv.Key}: {kv.Value}");
|
sb.AppendLine($"{kv.Key}: {kv.Value}");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sb.AppendLine($"LongestCharCount: {_producerQueue.LongestFieldCharCount}");
|
||||||
await File.WriteAllTextAsync(_outputPath, sb.ToString(), CancellationToken.None);
|
await File.WriteAllTextAsync(_outputPath, sb.ToString(), CancellationToken.None);
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,6 +18,8 @@ public class DataRecordQueue : IDisposable
|
|||||||
public bool IsCompleted => _queue.IsCompleted;
|
public bool IsCompleted => _queue.IsCompleted;
|
||||||
public bool IsAddingCompleted => _queue.IsAddingCompleted;
|
public bool IsAddingCompleted => _queue.IsAddingCompleted;
|
||||||
|
|
||||||
|
public long LongestFieldCharCount { get; private set; }
|
||||||
|
|
||||||
public event Action? OnRecordWrite;
|
public event Action? OnRecordWrite;
|
||||||
public event Action? OnRecordRead;
|
public event Action? OnRecordRead;
|
||||||
|
|
||||||
@ -49,6 +51,7 @@ public class DataRecordQueue : IDisposable
|
|||||||
public async Task EnqueueAsync(DataRecord record)
|
public async Task EnqueueAsync(DataRecord record)
|
||||||
{
|
{
|
||||||
var charCount = record.FieldCharCount;
|
var charCount = record.FieldCharCount;
|
||||||
|
LongestFieldCharCount = Math.Max(LongestFieldCharCount, charCount);
|
||||||
if(_currentCharCount + charCount > _maxCharCount)
|
if(_currentCharCount + charCount > _maxCharCount)
|
||||||
await TaskExtensions.WaitUntil(() => _currentCharCount + charCount < _maxCharCount, 50);
|
await TaskExtensions.WaitUntil(() => _currentCharCount + charCount < _maxCharCount, 50);
|
||||||
_queue.Add(record);
|
_queue.Add(record);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
{
|
{
|
||||||
|
"GCIntervalMilliseconds": -1,
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Debug"
|
"Default": "Debug"
|
||||||
@ -8,7 +9,7 @@
|
|||||||
"InputDir": "D:\\Dump\\NewMockData", // Csv数据输入目录
|
"InputDir": "D:\\Dump\\NewMockData", // Csv数据输入目录
|
||||||
"UseMock": false, // 使用模拟数据进行测试
|
"UseMock": false, // 使用模拟数据进行测试
|
||||||
"MockCountMultiplier": 1, // 模拟数据量级的乘数
|
"MockCountMultiplier": 1, // 模拟数据量级的乘数
|
||||||
"TableIgnoreList": ["order_box_block"] // 忽略输入的表
|
"TableIgnoreList": [] // 忽略输入的表
|
||||||
},
|
},
|
||||||
"Transform":{
|
"Transform":{
|
||||||
"StrictMode": false, // 设为true时如果数据转换发生错误,立刻停止程序
|
"StrictMode": false, // 设为true时如果数据转换发生错误,立刻停止程序
|
||||||
|
Loading…
Reference in New Issue
Block a user