为什么 WMI 查询有时如此缓慢? [英] Why are WMI Queries so slow sometimes?

查看:23
本文介绍了为什么 WMI 查询有时如此缓慢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 .Net 中使用 System.Management 命名空间对远程服务器执行各种 WMI 查询.在我的日志中,我可以看到有时查询需要 30 或 40 秒才能完成,而其他时候查询可以在不到一秒的时间内完成.

I am using System.Management namespace in a .Net to execute various WMI queries against a remote server. In my logs I can see that sometimes the queries take 30 or 40 seconds to complete while other times the queries complete in less than a second.

当我看到这些缓慢的查询时,我尝试使用 wbemtest 连接到框,但它总是快速连接并执行查询.

When I see these slow queries, I try to connect to the box using wbemtest, but it always connects and executes the query quickly.

有什么想法、指示、建议吗?

Any ideas, pointers, suggestions?

在反射器中查看 System.Management.ManagementScope 时,我确实注意到它似乎泄漏了 IWbemServices 指针.看起来这是一个 COM 接口,需要对其调用 Release (Marshal.ReleaseComObject()).我不确定这是否相关.在整个过程中,我确实连接到了许多不同的服务器.

I did notice when looking at System.Management.ManagementScope in reflector that it seems to leak a IWbemServices pointer. It looks like this is a COM Interface that needs to have Release called on it (Marshal.ReleaseComObject()). I'm not sure if that is related or not. I do connect to lots of different servers during the life of the process.

推荐答案

我有一个相同类型的应用程序,它在所有不同类型的设备上执行多个 WMI 查询,并且我遇到了相同的行为.使用 wbemtest 有时更快,但不一定.我还发现同一台机器上的一些查询与同一台机器上的其他查询的行为不同,这仅仅是因为不同的类是查询.

I have the same kind of application that does multiple WMI queries on all different kinds of devices and I experience the same behavior. Using wbemtest is sometimes faster but not necessarily. I also find some queries on the same machine behave differently then other queries on the same machine simply because a different class is queries.

有一个属于 EnumerationOptions 类的 ReturnImmediately 属性,如果您批量获取它们而不是通过网络枚举它们,它可能会帮助您更快地获得结果.

There is a ReturnImmediately property belonging to the EnumerationOptions class which might help you get the results faster if you get them in one batch instead of enumerating them over the network.

EnumerationOptions options = new EnumerationOptions();
options.ReturnImmediately = false;

你可以试试看是否有帮助.我知道这不是您想听到的,但我个人的意见是您无能为力.您需要编写代码来解决该问题.真正的答案深藏在 DCOM、WMI 协议和 WMI 存储库中.

You can try that and see if it helps. I know this is not what you want to hear but my personal opinion is that there is not much you can do. You need to write code to work arround the issue. The real answer lies somewhere deep burried in the bowls of DCOM, the WMI protocol and the WMI repository.

这篇关于为什么 WMI 查询有时如此缓慢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆