简体   繁体   English

为什么WMI查询有时会这么慢?

[英]Why are WMI Queries so slow sometimes?

I am using System.Management namespace in a .Net to execute various WMI queries against a remote server. 我在.Net中使用System.Management命名空间来对远程服务器执行各种WMI查询。 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. 在我的日志中,我可以看到有时查询需要30或40秒才能完成,而有时查询在不到一秒的时间内完成。

When I see these slow queries, I try to connect to the box using wbemtest, but it always connects and executes the query quickly. 当我看到这些慢查询时,我尝试使用wbemtest连接到该框,但它总是连接并快速执行查询。

Any ideas, pointers, suggestions? 任何想法,指针,建议?

I did notice when looking at System.Management.ManagementScope in reflector that it seems to leak a IWbemServices pointer. 当我在反射器中查看System.Management.ManagementScope时,我注意到它似乎泄漏了IWbemServices指针。 It looks like this is a COM Interface that needs to have Release called on it (Marshal.ReleaseComObject()). 看起来这是一个需要在其上调用Release的COM接口(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. 我在流程的生命周期中连接到许多不同的服务器。

You could try and set the WITHIN field to see if it forces the query to happen sooner. 您可以尝试设置WITHIN字段以查看它是否会更快地强制查询。 Could you post the query you are using? 你可以发布你正在使用的查询吗? That might help debug any further issues 这可能有助于调试任何其他问题

I have the same kind of application that does multiple WMI queries on all different kinds of devices and I experience the same behavior. 我有相同类型的应用程序在所有不同类型的设备上执行多个WMI查询,我遇到相同的行为。 Using wbemtest is sometimes faster but not necessarily. 使用wbemtest有时会更快但不一定。 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. 我还发现在同一台机器上的某些查询与同一台机器上的其他查询的行为方式不同,因为不同的类是查询。

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类的ReturnImmediately属性,如果您在一个批处理中获取结果而不是通过网络枚举它们,它可以帮助您更快地获得结果。

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

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. 真正的答案在于深埋在DCOM,WMI协议和WMI存储库中。

Is the problem specific to one box? 这个问题特定于一个盒子吗? I once had this same problem with a remoting scenario. 我曾经在远程方案中遇到过同样的问题。 I fixed it by rebuilding the TCP/IP stack on the box making the remoting call. 我通过在进行远程调用的盒子上重建TCP / IP堆栈来修复它。

Look into the WBEM_FLAG_RETURN_IMMEDIATE & WBEM_FLAG_FORWARD_ONLY flags for your language. 查看您的语言的WBEM_FLAG_RETURN_IMMEDIATE和WBEM_FLAG_FORWARD_ONLY标志。 When using Scriptomatic (great little VBScript GUI from MS for making WMI calls) this option is automatically added as part of the options. 使用Scriptomatic(来自MS的优秀小VBScript GUI进行WMI调用)时,此选项会自动添加为选项的一部分。 The 48 means WBEM_FLAG_RETURN_IMMEDIATE | 48表示WBEM_FLAG_RETURN_IMMEDIATE | WBEM_FLAG_FORWARD_ONLY. WBEM_FLAG_FORWARD_ONLY。 VBScript example: VBScript示例:

objWMIService.ExecQuery ("Select * from Win32_NetworkConnection",,48)

https://msdn.microsoft.com/en-us/library/aa390880(v=vs.85).aspx https://msdn.microsoft.com/en-us/library/aa390880(v=vs.85).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM