- 添加模拟数据生成器; - GC时添加碎片整理; - 优化日志输出,添加更多DEBUG监控项目; - 修复输出时分库配置逻辑的严重错误; - 优化了少许内存性能,减少Lambda闭包分配;
78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System.Collections.Concurrent;
|
|
|
|
namespace MesETL.App.Services;
|
|
|
|
/// <summary>
|
|
/// 处理上下文类,标识处理进度
|
|
/// </summary>
|
|
public class ProcessContext
|
|
{
|
|
private bool _hasException;
|
|
private long _inputCount;
|
|
private long _transformCount;
|
|
private long _outputCount;
|
|
private readonly ConcurrentDictionary<string, (long input, long output)> _tableProgress = new();
|
|
public bool HasException => _hasException;
|
|
public bool IsInputCompleted { get; private set; }
|
|
public bool IsTransformCompleted { get; private set; }
|
|
public bool IsOutputCompleted { get; private set; }
|
|
|
|
public long InputCount
|
|
{
|
|
get => _inputCount;
|
|
set => Interlocked.Exchange(ref _inputCount, value);
|
|
}
|
|
|
|
public long TransformCount
|
|
{
|
|
get => _transformCount;
|
|
set => Interlocked.Exchange(ref _transformCount, value);
|
|
}
|
|
|
|
public long OutputCount
|
|
{
|
|
get => _outputCount;
|
|
set => Interlocked.Exchange(ref _outputCount, value);
|
|
}
|
|
|
|
public long MaxMemoryUsage { get; set; }
|
|
|
|
|
|
// TableName -> Count
|
|
public IReadOnlyDictionary<string, (long input, long output)> TableProgress => _tableProgress;
|
|
|
|
public void CompleteInput() => IsInputCompleted = true;
|
|
|
|
public void CompleteTransform() => IsTransformCompleted = true;
|
|
public void CompleteOutput() => IsOutputCompleted = true;
|
|
public bool AddException(Exception e) => _hasException = true;
|
|
|
|
public void AddInput() => Interlocked.Increment(ref _inputCount);
|
|
|
|
public void AddInput(int count) => Interlocked.Add(ref _inputCount, count);
|
|
|
|
public void AddTransform() => Interlocked.Increment(ref _transformCount);
|
|
public void AddTransform(int count) => Interlocked.Add(ref _transformCount, count);
|
|
|
|
public void AddOutput() => Interlocked.Increment(ref _outputCount);
|
|
public void AddOutput(int count) => Interlocked.Add(ref _outputCount, count);
|
|
|
|
public void AddTableInput(string table, int count)
|
|
{
|
|
if (!_tableProgress.TryAdd(table, (input: count, output: 0)))
|
|
{
|
|
var tuple = _tableProgress[table];
|
|
tuple.input += count;
|
|
_tableProgress[table] = tuple;
|
|
}
|
|
}
|
|
|
|
public void AddTableOutput(string table, int count)
|
|
{
|
|
_tableProgress.AddOrUpdate(table, (input:0, output:count), (k, tuple) =>
|
|
{
|
|
tuple.output += count;
|
|
return tuple;
|
|
});
|
|
}
|
|
} |