mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
fix(cqrs): 收敛 benchmark review 修复
- 修复 RequestStartupBenchmarks 的 baseline 分组、初始化阶段对齐与 MediatR 重复注册问题 - 新增共享 dispatcher cache helper,并统一 benchmark 宿主的 MediatR logging/license 过滤配置 - 更新 cqrs-rewrite 跟踪与 trace,记录 PR #326 锚点、验证去重和 startup benchmark 的残留运行风险
This commit is contained in:
parent
449eeb9606
commit
2ac02c1a6f
@ -14,9 +14,10 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.15.6" />
|
||||
<PackageReference Include="BenchmarkDotNet" Version="0.15.8" />
|
||||
<PackageReference Include="MediatR" Version="13.1.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.7" />
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
// Copyright (c) 2025-2026 GeWuYou
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace GFramework.Cqrs.Benchmarks.Messaging;
|
||||
|
||||
/// <summary>
|
||||
/// 提供 benchmark 共享的 dispatcher 静态缓存清理入口。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// `GFramework.Cqrs` runtime 会把反射绑定与 generated invoker 元数据缓存在静态字段中。
|
||||
/// benchmark 需要在同一进程内重复比较 cold-start、reflection 与 generated 路径时,
|
||||
/// 显式清空这些缓存,避免前一组 benchmark 污染后续结果。
|
||||
/// </remarks>
|
||||
internal static class BenchmarkDispatcherCacheHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 清空 dispatcher 上与 benchmark 对照相关的全部静态缓存。
|
||||
/// </summary>
|
||||
public static void ClearDispatcherCaches()
|
||||
{
|
||||
ClearDispatcherCache("NotificationDispatchBindings");
|
||||
ClearDispatcherCache("RequestDispatchBindings");
|
||||
ClearDispatcherCache("StreamDispatchBindings");
|
||||
ClearDispatcherCache("GeneratedRequestInvokers");
|
||||
ClearDispatcherCache("GeneratedStreamInvokers");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过反射定位并清空 dispatcher 的指定缓存字段。
|
||||
/// </summary>
|
||||
/// <param name="fieldName">要清理的静态缓存字段名。</param>
|
||||
/// <exception cref="InvalidOperationException">指定缓存字段不存在、返回空值或未暴露清理方法。</exception>
|
||||
internal static void ClearDispatcherCache(string fieldName)
|
||||
{
|
||||
var field = typeof(GFramework.Cqrs.CqrsRuntimeFactory).Assembly
|
||||
.GetType("GFramework.Cqrs.Internal.CqrsDispatcher", throwOnError: true)!
|
||||
.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Static)
|
||||
?? throw new InvalidOperationException($"Missing dispatcher cache field {fieldName}.");
|
||||
var cache = field.GetValue(null)
|
||||
?? throw new InvalidOperationException($"Dispatcher cache field {fieldName} returned null.");
|
||||
var clearMethod = cache.GetType().GetMethod("Clear", BindingFlags.Public | BindingFlags.Instance)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Dispatcher cache field {fieldName} does not expose a Clear method.");
|
||||
_ = clearMethod.Invoke(cache, null);
|
||||
}
|
||||
}
|
||||
@ -65,6 +65,11 @@ public class NotificationBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(NotificationBenchmarks)));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.INotificationHandler<BenchmarkNotification>, BenchmarkNotificationHandler>();
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(NotificationBenchmarks).Assembly));
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
@ -68,6 +68,11 @@ public class RequestBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(RequestBenchmarks)));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.IRequestHandler<BenchmarkRequest, BenchmarkResponse>, BenchmarkRequestHandler>();
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(RequestBenchmarks).Assembly));
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
@ -9,7 +9,6 @@ using BenchmarkDotNet.Jobs;
|
||||
using BenchmarkDotNet.Order;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GFramework.Core.Abstractions.Logging;
|
||||
@ -67,7 +66,7 @@ public class RequestInvokerBenchmarks
|
||||
MinLevel = LogLevel.Fatal
|
||||
};
|
||||
Fixture.Setup("RequestInvoker", handlerCount: 1, pipelineCount: 0);
|
||||
ClearDispatcherCaches();
|
||||
BenchmarkDispatcherCacheHelper.ClearDispatcherCaches();
|
||||
|
||||
_baselineHandler = new ReflectionBenchmarkRequestHandler();
|
||||
_reflectionRequest = new ReflectionBenchmarkRequest(Guid.NewGuid());
|
||||
@ -87,6 +86,11 @@ public class RequestInvokerBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(RequestInvokerBenchmarks) + ".Generated"));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.IRequestHandler<MediatRBenchmarkRequest, MediatRBenchmarkResponse>, MediatRBenchmarkRequestHandler>();
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(RequestInvokerBenchmarks).Assembly));
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
@ -100,7 +104,7 @@ public class RequestInvokerBenchmarks
|
||||
public void Cleanup()
|
||||
{
|
||||
_serviceProvider.Dispose();
|
||||
ClearDispatcherCaches();
|
||||
BenchmarkDispatcherCacheHelper.ClearDispatcherCaches();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -139,36 +143,6 @@ public class RequestInvokerBenchmarks
|
||||
return _mediatr.Send(_mediatrRequest, CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空 dispatcher 静态缓存,避免上一轮基准残留的 generated metadata 影响当前对照。
|
||||
/// </summary>
|
||||
private static void ClearDispatcherCaches()
|
||||
{
|
||||
ClearDispatcherCache("NotificationDispatchBindings");
|
||||
ClearDispatcherCache("RequestDispatchBindings");
|
||||
ClearDispatcherCache("StreamDispatchBindings");
|
||||
ClearDispatcherCache("GeneratedRequestInvokers");
|
||||
ClearDispatcherCache("GeneratedStreamInvokers");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过反射定位并清空 dispatcher 的指定缓存字段。
|
||||
/// </summary>
|
||||
/// <param name="fieldName">要清理的静态缓存字段名。</param>
|
||||
private static void ClearDispatcherCache(string fieldName)
|
||||
{
|
||||
var field = typeof(GFramework.Cqrs.CqrsRuntimeFactory).Assembly
|
||||
.GetType("GFramework.Cqrs.Internal.CqrsDispatcher", throwOnError: true)!
|
||||
.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Static)
|
||||
?? throw new InvalidOperationException($"Missing dispatcher cache field {fieldName}.");
|
||||
var cache = field.GetValue(null)
|
||||
?? throw new InvalidOperationException($"Dispatcher cache field {fieldName} returned null.");
|
||||
var clearMethod = cache.GetType().GetMethod("Clear", BindingFlags.Public | BindingFlags.Instance)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Dispatcher cache field {fieldName} does not expose a Clear method.");
|
||||
_ = clearMethod.Invoke(cache, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reflection runtime request。
|
||||
/// </summary>
|
||||
|
||||
@ -75,6 +75,11 @@ public class RequestPipelineBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(RequestPipelineBenchmarks)));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.IRequestHandler<BenchmarkRequest, BenchmarkResponse>, BenchmarkRequestHandler>();
|
||||
RegisterMediatRPipelineBehaviors(services, PipelineCount);
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(RequestPipelineBenchmarks).Assembly));
|
||||
|
||||
@ -8,7 +8,6 @@ using BenchmarkDotNet.Diagnosers;
|
||||
using BenchmarkDotNet.Jobs;
|
||||
using BenchmarkDotNet.Order;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GFramework.Core.Abstractions.Logging;
|
||||
@ -17,6 +16,7 @@ using GFramework.Core.Logging;
|
||||
using GFramework.Cqrs.Abstractions.Cqrs;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using ILogger = GFramework.Core.Abstractions.Logging.ILogger;
|
||||
|
||||
namespace GFramework.Cqrs.Benchmarks.Messaging;
|
||||
|
||||
@ -31,6 +31,7 @@ public class RequestStartupBenchmarks
|
||||
|
||||
private ServiceProvider _serviceProvider = null!;
|
||||
private IMediator _mediatr = null!;
|
||||
private ICqrsRuntime _runtime = null!;
|
||||
|
||||
/// <summary>
|
||||
/// 配置 request startup benchmark 的公共输出格式。
|
||||
@ -41,8 +42,9 @@ public class RequestStartupBenchmarks
|
||||
{
|
||||
AddJob(Job.Default);
|
||||
AddColumnProvider(DefaultColumnProviders.Instance);
|
||||
AddColumn(new CustomColumn("Scenario", static (_, _) => "RequestStartup"));
|
||||
AddColumn(new CustomColumn("Scenario", static (_, _) => "RequestStartup"), TargetMethodColumn.Method, CategoriesColumn.Default);
|
||||
AddDiagnoser(MemoryDiagnoser.Default);
|
||||
AddLogicalGroupRules(BenchmarkLogicalGroupRule.ByCategory);
|
||||
WithOrderer(new DefaultOrderer(SummaryOrderPolicy.FastestToSlowest, MethodOrderPolicy.Declared));
|
||||
}
|
||||
}
|
||||
@ -57,10 +59,11 @@ public class RequestStartupBenchmarks
|
||||
|
||||
_serviceProvider = CreateMediatRServiceProvider();
|
||||
_mediatr = _serviceProvider.GetRequiredService<IMediator>();
|
||||
_runtime = CreateGFrameworkRuntime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放 MediatR 对照组使用的 DI 宿主。
|
||||
/// 释放 startup benchmark 复用的宿主对象。
|
||||
/// </summary>
|
||||
[GlobalCleanup]
|
||||
public void Cleanup()
|
||||
@ -69,23 +72,23 @@ public class RequestStartupBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 解析 MediatR mediator,作为 startup 句柄解析成本的 baseline。
|
||||
/// 返回已构建宿主中的 MediatR mediator,作为 initialization 组的句柄解析 baseline。
|
||||
/// </summary>
|
||||
[Benchmark(Baseline = true)]
|
||||
[BenchmarkCategory("Initialization")]
|
||||
public IMediator Initialization_MediatR()
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<IMediator>();
|
||||
return _mediatr;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 GFramework.CQRS runtime,作为同层级 startup 句柄创建成本的对照。
|
||||
/// 返回已构建宿主中的 GFramework.CQRS runtime,确保与 MediatR baseline 处于相同初始化阶段。
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("Initialization")]
|
||||
public ICqrsRuntime Initialization_GFrameworkCqrs()
|
||||
{
|
||||
return CreateGFrameworkRuntime();
|
||||
return _runtime;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -101,20 +104,36 @@ public class RequestStartupBenchmarks
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在清空 dispatcher 静态缓存后,于新宿主上首次发送 request,量化 GFramework.CQRS 的 first-hit 成本。
|
||||
/// 在新 runtime 上首次发送 request,量化 GFramework.CQRS 的 first-hit 成本。
|
||||
/// </summary>
|
||||
[Benchmark]
|
||||
[BenchmarkCategory("ColdStart")]
|
||||
public ValueTask<BenchmarkResponse> ColdStart_GFrameworkCqrs()
|
||||
{
|
||||
ClearDispatcherCaches();
|
||||
var runtime = CreateGFrameworkRuntime();
|
||||
var runtime = CreateColdStartRuntime();
|
||||
return runtime.SendAsync(BenchmarkContext.Instance, Request, CancellationToken.None);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 为 cold-start benchmark 构建全新的 runtime,并在构建前显式清空 dispatcher 静态缓存。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 这里把缓存清理与 runtime 构建绑定在同一阶段,避免把额外的反射缓存清理成本混入 benchmark 方法主体,
|
||||
/// 只保留“新宿主 + 首次分发”的对照。
|
||||
/// </summary>
|
||||
private static ICqrsRuntime CreateColdStartRuntime()
|
||||
{
|
||||
BenchmarkDispatcherCacheHelper.ClearDispatcherCaches();
|
||||
return CreateGFrameworkRuntime();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建只承载当前 benchmark request 的最小 GFramework.CQRS runtime。
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 该 benchmark 故意保持与 MediatR 对照组同样的“单 handler 最小宿主”模型,
|
||||
/// 因此这里继续使用单点手工注册,而不引入依赖完整 CQRS 注册协调器的程序集扫描路径。
|
||||
/// </remarks>
|
||||
private static ICqrsRuntime CreateGFrameworkRuntime()
|
||||
{
|
||||
var container = new MicrosoftDiContainer();
|
||||
@ -128,7 +147,11 @@ public class RequestStartupBenchmarks
|
||||
private static ServiceProvider CreateMediatRServiceProvider()
|
||||
{
|
||||
var services = new ServiceCollection();
|
||||
services.AddSingleton<MediatR.IRequestHandler<BenchmarkRequest, BenchmarkResponse>, BenchmarkRequestHandler>();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(RequestStartupBenchmarks).Assembly));
|
||||
return services.BuildServiceProvider();
|
||||
}
|
||||
@ -145,36 +168,6 @@ public class RequestStartupBenchmarks
|
||||
return LoggerFactoryResolver.Provider.CreateLogger(categoryName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空 dispatcher 静态缓存,避免同一进程中的前一轮分发污染 cold-start 结果。
|
||||
/// </summary>
|
||||
private static void ClearDispatcherCaches()
|
||||
{
|
||||
ClearDispatcherCache("NotificationDispatchBindings");
|
||||
ClearDispatcherCache("RequestDispatchBindings");
|
||||
ClearDispatcherCache("StreamDispatchBindings");
|
||||
ClearDispatcherCache("GeneratedRequestInvokers");
|
||||
ClearDispatcherCache("GeneratedStreamInvokers");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过反射定位并清空 dispatcher 的指定缓存字段。
|
||||
/// </summary>
|
||||
/// <param name="fieldName">要清理的静态缓存字段名。</param>
|
||||
private static void ClearDispatcherCache(string fieldName)
|
||||
{
|
||||
var field = typeof(GFramework.Cqrs.CqrsRuntimeFactory).Assembly
|
||||
.GetType("GFramework.Cqrs.Internal.CqrsDispatcher", throwOnError: true)!
|
||||
.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Static)
|
||||
?? throw new InvalidOperationException($"Missing dispatcher cache field {fieldName}.");
|
||||
var cache = field.GetValue(null)
|
||||
?? throw new InvalidOperationException($"Dispatcher cache field {fieldName} returned null.");
|
||||
var clearMethod = cache.GetType().GetMethod("Clear", BindingFlags.Public | BindingFlags.Instance)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Dispatcher cache field {fieldName} does not expose a Clear method.");
|
||||
_ = clearMethod.Invoke(cache, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Benchmark request。
|
||||
/// </summary>
|
||||
|
||||
@ -9,7 +9,6 @@ using BenchmarkDotNet.Jobs;
|
||||
using BenchmarkDotNet.Order;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using GFramework.Core.Abstractions.Logging;
|
||||
@ -67,7 +66,7 @@ public class StreamInvokerBenchmarks
|
||||
MinLevel = LogLevel.Fatal
|
||||
};
|
||||
Fixture.Setup("StreamInvoker", handlerCount: 1, pipelineCount: 0);
|
||||
ClearDispatcherCaches();
|
||||
BenchmarkDispatcherCacheHelper.ClearDispatcherCaches();
|
||||
|
||||
_baselineHandler = new ReflectionBenchmarkStreamHandler();
|
||||
_reflectionRequest = new ReflectionBenchmarkStreamRequest(Guid.NewGuid(), 3);
|
||||
@ -87,6 +86,11 @@ public class StreamInvokerBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(StreamInvokerBenchmarks) + ".Generated"));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.IStreamRequestHandler<MediatRBenchmarkStreamRequest, MediatRBenchmarkResponse>, MediatRBenchmarkStreamHandler>();
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(StreamInvokerBenchmarks).Assembly));
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
@ -100,7 +104,7 @@ public class StreamInvokerBenchmarks
|
||||
public void Cleanup()
|
||||
{
|
||||
_serviceProvider.Dispose();
|
||||
ClearDispatcherCaches();
|
||||
BenchmarkDispatcherCacheHelper.ClearDispatcherCaches();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -153,36 +157,6 @@ public class StreamInvokerBenchmarks
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空 dispatcher 静态缓存,避免上一轮基准残留的 generated metadata 影响当前对照。
|
||||
/// </summary>
|
||||
private static void ClearDispatcherCaches()
|
||||
{
|
||||
ClearDispatcherCache("NotificationDispatchBindings");
|
||||
ClearDispatcherCache("RequestDispatchBindings");
|
||||
ClearDispatcherCache("StreamDispatchBindings");
|
||||
ClearDispatcherCache("GeneratedRequestInvokers");
|
||||
ClearDispatcherCache("GeneratedStreamInvokers");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过反射定位并清空 dispatcher 的指定缓存字段。
|
||||
/// </summary>
|
||||
/// <param name="fieldName">要清理的静态缓存字段名。</param>
|
||||
private static void ClearDispatcherCache(string fieldName)
|
||||
{
|
||||
var field = typeof(GFramework.Cqrs.CqrsRuntimeFactory).Assembly
|
||||
.GetType("GFramework.Cqrs.Internal.CqrsDispatcher", throwOnError: true)!
|
||||
.GetField(fieldName, BindingFlags.NonPublic | BindingFlags.Static)
|
||||
?? throw new InvalidOperationException($"Missing dispatcher cache field {fieldName}.");
|
||||
var cache = field.GetValue(null)
|
||||
?? throw new InvalidOperationException($"Dispatcher cache field {fieldName} returned null.");
|
||||
var clearMethod = cache.GetType().GetMethod("Clear", BindingFlags.Public | BindingFlags.Instance)
|
||||
?? throw new InvalidOperationException(
|
||||
$"Dispatcher cache field {fieldName} does not expose a Clear method.");
|
||||
_ = clearMethod.Invoke(cache, null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reflection runtime stream request。
|
||||
/// </summary>
|
||||
|
||||
@ -69,6 +69,11 @@ public class StreamingBenchmarks
|
||||
LoggerFactoryResolver.Provider.CreateLogger(nameof(StreamingBenchmarks)));
|
||||
|
||||
var services = new ServiceCollection();
|
||||
services.AddLogging(static builder =>
|
||||
Microsoft.Extensions.Logging.FilterLoggingBuilderExtensions.AddFilter(
|
||||
builder,
|
||||
"LuckyPennySoftware.MediatR.License",
|
||||
Microsoft.Extensions.Logging.LogLevel.None));
|
||||
services.AddSingleton<MediatR.IStreamRequestHandler<BenchmarkStreamRequest, BenchmarkResponse>, BenchmarkStreamHandler>();
|
||||
services.AddMediatR(static options => options.RegisterServicesFromAssembly(typeof(StreamingBenchmarks).Assembly));
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
@ -9,7 +9,7 @@ CQRS 迁移与收敛。
|
||||
|
||||
- 恢复点编号:`CQRS-REWRITE-RP-089`
|
||||
- 当前阶段:`Phase 8`
|
||||
- 当前 PR 锚点:`PR #323`
|
||||
- 当前 PR 锚点:`PR #326`
|
||||
- 当前结论:
|
||||
- `GFramework.Cqrs` 已完成对外部 `Mediator` 的生产级替代,当前主线已从“是否可替代”转向“仓库内部收口与能力深化顺序”
|
||||
- `dispatch/invoker` 生成前移已扩展到 request / stream 路径,`RP-077` 已补齐 request invoker provider gate 与 stream gate 对称的 descriptor / descriptor entry runtime 合同回归
|
||||
@ -25,18 +25,20 @@ CQRS 迁移与收敛。
|
||||
- `RP-087` 已补齐 request startup benchmark,把 initialization 与 cold-start 维度正式纳入 `GFramework.Cqrs.Benchmarks`
|
||||
- 当前 `RP-088` 已补齐 request invoker reflection / generated-provider 对照,开始直接量化 dispatcher 预热 generated descriptor 的收益
|
||||
- 当前 `RP-089` 已补齐 stream invoker reflection / generated-provider 对照,使 generated descriptor 预热收益从 request 扩展到 stream 路径
|
||||
- `ai-plan` active 入口现以 `PR #323` 和 `RP-082` 为唯一权威恢复锚点;`PR #307`、其他更早 PR 与阶段细节均以下方归档或说明为准
|
||||
- `ai-plan` active 入口现以 `PR #326` 和 `RP-089` 为唯一权威恢复锚点;`PR #323`、`PR #307` 与其他更早阶段细节均以下方归档或说明为准
|
||||
|
||||
## 当前活跃事实
|
||||
|
||||
- 当前分支对应 `PR #323`,状态为 `OPEN`
|
||||
- 当前分支对应 `PR #326`,状态为 `OPEN`
|
||||
- latest-head review 仍以 `ai-plan` 恢复文档收敛为主要待闭环项;代码与测试侧的本地有效问题已收敛
|
||||
- `RequestStartupBenchmarks` 已修复 baseline 分组冲突、MediatR 13 logging/license 构造失败与重复注册问题,但 `ColdStart_GFrameworkCqrs` 仍存在 `No CQRS request handler registered` 的运行级残留
|
||||
- 远端 `CTRF` 最新汇总为 `2274/2274` passed
|
||||
- `MegaLinter` 当前只暴露 `dotnet-format` 的 `Restore operation failed` 环境噪音,尚未提供本地仍成立的文件级格式诊断
|
||||
|
||||
## 当前风险
|
||||
|
||||
- 顶层 `GFramework.sln` / `GFramework.csproj` 在 WSL 下仍可能受 Windows NuGet fallback 配置影响,完整 solution 级验证成本高于模块级验证
|
||||
- `RequestStartupBenchmarks` 的 GFramework cold-start 路径在清空 dispatcher 缓存后仍未恢复 request handler 绑定,当前无法产出完整 startup 对照数据
|
||||
- 仓库内部仍保留旧 `Command` / `Query` API、`LegacyICqrsRuntime` alias 与部分历史命名语义,后续若不继续分批收口,容易混淆“对外替代已完成”与“内部收口未完成”
|
||||
- 若继续扩大 generated invoker 覆盖面,需要持续区分“可静态表达的合同”与 `PreciseReflectedRegistrationSpec` 等仍需保守回退的场景
|
||||
|
||||
@ -44,7 +46,7 @@ CQRS 迁移与收敛。
|
||||
|
||||
- `python3 .agents/skills/gframework-pr-review/scripts/fetch_current_pr_review.py --format json --json-output <temporary-json-output>`
|
||||
- 结果:通过
|
||||
- 备注:确认当前分支对应 `PR #323`,本轮剩余 open AI feedback 主要集中在 `ai-plan` PR 锚点收敛
|
||||
- 备注:确认当前分支对应 `PR #326`,本轮剩余 open AI feedback 主要集中在 benchmark 对照语义与 `ai-plan` 结构收敛
|
||||
- `git diff --check`
|
||||
- 结果:通过
|
||||
- `python3 scripts/license-header.py --check`
|
||||
@ -56,27 +58,13 @@ CQRS 迁移与收敛。
|
||||
- 结果:通过,`2/2` passed
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- 备注:包含新增 `StreamingBenchmarks` 后再次复核通过
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- 备注:包含新增 `RequestPipelineBenchmarks` 后再次复核通过
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- 备注:包含新增 `RequestStartupBenchmarks` 后再次复核通过
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- 备注:包含新增 `RequestInvokerBenchmarks` 与 handwritten generated registry/provider 后再次复核通过
|
||||
- `dotnet build GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release`
|
||||
- 结果:通过,`0 warning / 0 error`
|
||||
- 备注:包含新增 `StreamInvokerBenchmarks` 与 handwritten generated stream registry/provider 后再次复核通过
|
||||
- `GIT_DIR=<worktree-git-dir> GIT_WORK_TREE=<worktree-root> python3 scripts/license-header.py --check`
|
||||
- 结果:通过
|
||||
- `git diff --check`
|
||||
- 结果:通过
|
||||
- 备注:先后覆盖 `StreamingBenchmarks`、`RequestPipelineBenchmarks`、`RequestStartupBenchmarks`、`RequestInvokerBenchmarks` 与 `StreamInvokerBenchmarks` 的引入后复核
|
||||
- `dotnet run --project GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release -- --filter "*RequestStartupBenchmarks*" --job short --warmupCount 1 --iterationCount 1 --launchCount 1`
|
||||
- 结果:部分通过
|
||||
- 备注:`Initialization_MediatR` 与 `ColdStart_MediatR` 已可实际运行;`ColdStart_GFrameworkCqrs` 仍因 `No CQRS request handler registered` 无法产出完整对照
|
||||
- `GIT_DIR=<worktree-git-dir> GIT_WORK_TREE=<worktree-root> python3 scripts/license-header.py --check`
|
||||
- 结果:通过
|
||||
- 备注:当前 WSL worktree 需要显式绑定 `GIT_DIR` / `GIT_WORK_TREE` 后运行,避免脚本内部 plain `git ls-files` 误判仓库上下文
|
||||
- `git diff --check`
|
||||
- 结果:通过
|
||||
- `dotnet test GFramework.SourceGenerators.Tests/GFramework.SourceGenerators.Tests.csproj -c Release --filter "FullyQualifiedName~CqrsHandlerRegistryGeneratorTests.Does_Not_Emit_Stream_Invoker_Provider_Metadata_When_Runtime_Lacks_Stream_Provider_Interface|FullyQualifiedName~CqrsHandlerRegistryGeneratorTests.Does_Not_Emit_Stream_Invoker_Provider_Metadata_When_Runtime_Lacks_Stream_Descriptor_Enumerator|FullyQualifiedName~CqrsHandlerRegistryGeneratorTests.Does_Not_Emit_Stream_Invoker_Provider_Metadata_When_Runtime_Lacks_Stream_Descriptor_Type|FullyQualifiedName~CqrsHandlerRegistryGeneratorTests.Does_Not_Emit_Stream_Invoker_Provider_Metadata_When_Runtime_Lacks_Stream_Descriptor_Entry_Type|FullyQualifiedName~CqrsHandlerRegistryGeneratorTests.Emits_Stream_Invoker_Provider_Metadata_When_Runtime_Contract_Is_Available"`
|
||||
@ -126,9 +114,9 @@ CQRS 迁移与收敛。
|
||||
|
||||
## 下一推荐步骤
|
||||
|
||||
1. 继续处理 `PR #323` 的剩余 review 收尾,优先保持 `ai-plan` active 入口与 trace 的单一锚点一致
|
||||
2. 若继续推进“吸收 Mediator 设计哲学”的切片,优先扩展 benchmark 场景矩阵到 registration / service lifetime、notification publish strategy 或更贴近 `Mediator` concrete runtime 的对照
|
||||
3. 在进入下一批 runtime / generator 收敛前,保持最小 Release build、targeted test 或 benchmark project build 作为权威验证
|
||||
1. 继续处理 `PR #326` 的剩余 review 收尾,优先保持 benchmark 对照语义与 `ai-plan` active 入口一致
|
||||
2. 优先定位 `RequestStartupBenchmarks.ColdStart_GFrameworkCqrs` 在清空 dispatcher 缓存后的 request handler 绑定缺口,再决定是调整最小宿主注册方式还是补充专用 benchmark fixture
|
||||
3. 若继续推进“吸收 Mediator 设计哲学”的切片,优先扩展 benchmark 场景矩阵到 registration / service lifetime、notification publish strategy 或更贴近 `Mediator` concrete runtime 的对照
|
||||
|
||||
## 活跃文档
|
||||
|
||||
|
||||
@ -454,6 +454,7 @@
|
||||
|
||||
1. 完成本轮 benchmark 项目 Release build、license header 检查与 diff 校验后,更新 active tracking 的权威验证列表
|
||||
2. 若 branch diff 仍明显低于 `30` 文件阈值,可继续评估 notification publish strategy 或更贴近 `Mediator` concrete runtime 的单批对照
|
||||
3. 若要继续贴近 `Mediator` 的 comparison benchmark 设计哲学,评估是否把 `Mediator` concrete runtime 本身接入 benchmark 项目,而不是长期只保留 `MediatR`
|
||||
|
||||
### 验证(RP-089)
|
||||
|
||||
@ -463,4 +464,5 @@
|
||||
- 结果:通过
|
||||
- `git diff --check`
|
||||
- 结果:通过
|
||||
2. 若要继续贴近 `Mediator` 的 comparison benchmark 设计哲学,评估是否把 `Mediator` concrete runtime 本身接入 benchmark 项目,而不是长期只保留 `MediatR`
|
||||
- `dotnet run --project GFramework.Cqrs.Benchmarks/GFramework.Cqrs.Benchmarks.csproj -c Release -- --filter "*RequestStartupBenchmarks*" --job short --warmupCount 1 --iterationCount 1 --launchCount 1`
|
||||
- 结果:部分通过;`MediatR` startup benchmark 已恢复真实测量,`ColdStart_GFrameworkCqrs` 仍因 `No CQRS request handler registered` 失败
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user