c# - 当我在 ServiceFabric 群集上使用 EventFlow 监听 ETW 事件时出现“系统资源不足”

标签 c# asp.net-core azure-service-fabric etw event-flow

我有一个使用在 Service Fabric 上运行的 EventFlow 的 ETW 监听器。

这是我的配置文件(eventFlowConfig.json):

{
  "inputs": [
    {
      "type": "ETW",
      "sessionNamePrefix": "MyListenerService",
      "cleanupOldSessions": true,
      "reuseExistingSession": true,
      "providers": [
        {
          "providerName": "Provider0"
        }
      ]
    }
  ],
  "filters": [],
  "outputs": [
    {
      "type": "CustomOutput"
    }
  ],
  "schemaVersion": "2018-04-04",

  "extensions": [
    {
      "category": "outputFactory",
      "type": "CustomOutput",
      "qualifiedTypeName": "MyNamespace.EventFlow.Outputs.CustomOutputFactory, MyAssembly"
    }
  ]
}

这是我的切入点:

private static void Main()
{
    try
    {
        string configurationFileName = "eventFlowConfig.json";

        using (var diagnosticsPipeline = ServiceFabricDiagnosticPipelineFactory.CreatePipeline("MyService", configurationFileName))
        {
            ServiceRuntime.RegisterServiceAsync("MyServiceType",
                context => new Service(context)).GetAwaiter().GetResult();

            ServiceEventSource.Current.ServiceTypeRegistered(Process.GetCurrentProcess().Id, typeof(Service).Name);
            // Prevents this host process from terminating so services keeps running. 
            Thread.Sleep(Timeout.Infinite);
        }
    }
    catch (Exception e)
    {
        ServiceEventSource.Current.ServiceHostInitializationFailed(e.ToString());
        throw;
    }
}

当我在调试时在我的本地集群中多次启动/停止我的服务时,我得到了这个异常:

System.Runtime.InteropServices.COMException: 'Insufficient system resources exist to complete the requested service. (Exception from HRESULT: 0x800705AA)'

在重新启动计算机之前,我无法重新启动服务。问题是我在本地以外的其他环境中遇到了同样的异常。

我试过这个:TraceEventSession usage in ServiceFabric application raises insufficient resource error : 我的服务是无状态的,每个节点只有一个实例。

此配置是否足以释放/重用 ETW session ?

"sessionNamePrefix": "MyListenerService",
"cleanupOldSessions": true,
"reuseExistingSession": true,

有没有人遇到过这个问题?

编辑 在 @Diego Mendes 的回答之后,我得到了这个执行 logman -ets

...
EventFlow-EtwInput-a8aefb3c-594f-4ac7-b9d8-6da1791fb122 Trace                         Running
EventFlow-EtwInput-fe5f58e6-d1a7-4198-95b2-d343584cf46b Trace                         Running
EventFlow-EtwInput-33f67287-5563-4835-b3a1-5527e4fc5e5e Trace                         Running
EventFlow-EtwInput-959eef04-a5ae-47eb-9b7e-057a9fd3fb28 Trace                         Running
EventFlow-EtwInput-0095f186-d657-4974-a613-213d7eb49def Trace                         Running
EventFlow-EtwInput-8fbc52f5-2de6-4826-bce2-36d8abf0c264 Trace                         Running
EventFlow-EtwInput-8e654b40-c299-48f4-818e-5ebe3c2341a4 Trace                         Running
EventFlow-EtwInput-7ec63ec9-428b-4658-b059-698b5ae66986 Trace                         Running

EventFlow 忽略了我的 sessionNamePrefix 并用 EventFlow-EtwInput 覆盖?可能是 EventFlow 的错误?

我将尝试使用 EventFlow-EtwInput 作为我的 sessionNamePrefix

最佳答案

正如您所指出的,这是因为您多次启动和停止服务。每次启动服务时,都会创建一个新 session ,当您在 Debug模式下执行此操作时,调试器会在关闭事件 session 之前终止进程。

来自马特回答你链接:

Windows has a limit of 64 ETW sessions that can be running concurrently. Consider using a single stateless app running on every node to create a single session.

您可以通过运行以下命令检查它何时再次发生,是否有任何 session 保持打开状态:

logman -ets

它将列出所有事件 session ,您的可能显示为如下内容:

MyListenerService-A402EE30-53B7-48E4-B602-76B101C0AB97

如果您有多个事件 session ,是因为它没有正确关闭,也没有重用旧 session 。

在配置中,当你设置:

cleanupOldSessions: If set to TRUE, existing ETW trace sessions matching the sessionNamePrefix will be closed. This helps to collect leftover session instances, as there is a limit on their number.

reuseExistingSession: If turned on, then an existing trace session matching the sessionNamePrefix will be re-used. If cleanupOldSessions is also turned on, then it will leave one session open for re-use.

根据您的设置,您同时使用了 ON,我会尝试调整这些值以查看是否可以解决问题。

关于c# - 当我在 ServiceFabric 群集上使用 EventFlow 监听 ETW 事件时出现“系统资源不足”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51377117/

相关文章:

c# - 在 C# 中使用 SQL 获取数据库的驱动器号

c# - 找不到 Xamarin Android 资源文件

c# - 有没有办法强制 NHTMLUNIT 忽略页面 JavaScript 错误并继续执行脚本?

javascript - (ASP.NET Core)如何更新 View 上的 View 组件

azure - 更新 Azure Service Fabric 中的环境变量

c# - 来自 get 和 set 的 StackOverflow 异常

c# - 如何将 SameSite cookie 属性设置为显式 None ASP NET Core

azure - Azure API 应用程序和 Azure Service Fabric 之间有什么区别?

asp.net-web-api - 构建新的 Azure Fabric 服务时未找到 list 文件

c# - 枚举值在 razor 页面 ASP.NET Core 3.1 上不显示 EnumMember 值