0

我们在 MVC3 项目中使用 Unity 作为 IoC 容器。我们刚刚安装了 dynatrace,它显示在 FileSystemWatcher.StartRaisingEvents 方法中花费的时间过多,特别是在 ReadDirectoryChangesW 中。这似乎导致了糟糕的表现。

为什么 Unity 会监控文件系统?

Here's the call stack:

ChildActionExtensions.RenderAction
  HttpServerUtility.Execute
    HttpHandlerUtil+ServerExecuteHttpHandler.Wrap
      UnityControllerFactory.CreateController
        XmlConfigurator.ConfigureAndWatch
          FileSystemWatcher.StartRaisingEvents
            UnsafeNativeMethods.ReadDirectoryChangesW

这是 UnityControllerFactoryCode

        try
        {
            if (requestContext.RouteData.DataTokens.ContainsKey("area") && !string.IsNullOrWhiteSpace(requestContext.RouteData.DataTokens["area"].ToString()))
            {
                controllerName = string.Format("{0}/{1}", requestContext.RouteData.DataTokens["area"], controllerName);
            }

            controllerName = controllerName.ToLower();

            return _container.Resolve<IController>(controllerName);
        }
        catch (Exception ex)
        {
            if (ex is ResolutionFailedException)
            {
                IMyLogger logger = _container.Resolve<IMyLogger>();
                logger.Error(LogEventIdType.General, ex, "Is the '{0}' controller defined in the Unity Container via RegisterType (in lowercase) in UnityIocBootstrapConfigure?", new object[] {controllerName});
                throw;
            }             
        }

记录器记录到 Windows 事件日志。

4

2 回答 2

1

Unity 本身不会做这样的事情。事实上,堆栈跟踪根本不在 Unity 代码中,它在控制器工厂中。

写这个的人添加了文件系统观察器。这很愚蠢,因为 ASP。NET 已经监视 web.config 并在它发生更改时重新启动 appdomain。

于 2012-12-11T07:18:08.120 回答
1

Your trace is pointing to XmlConfigurator, which is log4net. log4net stores its configuration in a separate file from the web.config, so it starts a File System Watcher to check if the file has changed to reconfigure itself.

It would seem that the culprit of your performance problems then is log4net, not Unity.

于 2012-12-11T23:53:05.317 回答