tags:

views:

474

answers:

3

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.

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?

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.

A: 

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.

Robert Harvey
No. This happens to several of the target computers (but not all of them). By the time I see the slow queries in the logs and try to manually query, the problem is fixed.
Josh Clark
What about the source computers (the ones making the calls)? Is the problem specific to any of them?
Robert Harvey
Yes and No :). The are multiple source computers having this issue, but not every server I try this on has this issue.
Josh Clark
You might try setting up your code to ping the machine prior to making the WMI call, and logging the ping time. It might shed some light on whether network communications is an issue.
Robert Harvey
A: 

You could try and set the WITHIN field to see if it forces the query to happen sooner. Could you post the query you are using? That might help debug any further issues

SwDevMan81
A: 

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.

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;

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.

Mark
Sadly, I think you are correct. I just need to work around the issue. The ReturnImmediately setting helped a little but not enough to solve the problem.
Josh Clark