- 添加模拟数据生成器; - GC时添加碎片整理; - 优化日志输出,添加更多DEBUG监控项目; - 修复输出时分库配置逻辑的严重错误; - 优化了少许内存性能,减少Lambda闭包分配;
49 lines
1.7 KiB
C#
49 lines
1.7 KiB
C#
using MesETL.App.Const;
|
|
using MesETL.App.HostedServices.Abstractions;
|
|
using MesETL.App.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Options;
|
|
|
|
namespace Mesdb.DataGenerator;
|
|
|
|
public class MockInputService : IInputService
|
|
{
|
|
private readonly DataRecordQueue _producerQueue;
|
|
private readonly ProcessContext _context;
|
|
private readonly IOptions<MockInputOptions> _options;
|
|
private readonly ILogger _logger;
|
|
|
|
public MockInputService([FromKeyedServices(ConstVar.Producer)]DataRecordQueue producerQueue, ProcessContext context, IOptions<MockInputOptions> options,
|
|
ILogger<MockInputService> logger)
|
|
{
|
|
_producerQueue = producerQueue;
|
|
_context = context;
|
|
_options = options;
|
|
_logger = logger;
|
|
}
|
|
|
|
public async Task ExecuteAsync(CancellationToken cancellationToken)
|
|
{
|
|
_logger.LogInformation("***** 开始模拟输入数据 *****");
|
|
foreach (var (table, options) in _options.Value.Rules)
|
|
{
|
|
_logger.LogInformation("模拟表 '{TableName}' 输入,数量: {Amount}", table, options.Amount);
|
|
|
|
for (int i = 0; i < options.Amount; i++)
|
|
{
|
|
var ctx = new TableMockContext()
|
|
{
|
|
Index = i,
|
|
};
|
|
var record = options.Generate(ctx);
|
|
await _producerQueue.EnqueueAsync(record);
|
|
_context.AddInput(1);
|
|
_context.AddTableInput(table, 1);
|
|
}
|
|
_logger.LogInformation("表 '{TableName}' 输入完成", table);
|
|
}
|
|
_context.CompleteInput();
|
|
_logger.LogInformation("***** 模拟数据输入完成 *****");
|
|
}
|
|
} |