1
votes

I am having an issue with a WMI query. I use a WMI query to search and resume an instance in BizTalk. When there are not that many instances (so when the data isn't that much) the query performs pretty good. But when the data is large (about 3000 instances) the query takes about 6 - 10 seconds to execute, and this isn't tolerable.

Code is as following:

string query = "SELECT * FROM MSBTS_ServiceInstance WHERE InstanceID = \"" + OrchestrationId + "\"";
    ManagementObjectSearcher searcher = new ManagementObjectSearcher(new ManagementScope(@"root\MicrosoftBizTalkServer"), new WqlObjectQuery(query), null);
    int count = searcher.Get().Count;
    if (count > 0)
    {
        string[] strArray = new string[count];
        string[] strArray2 = new string[count];
        string[] strArray3 = new string[count];
        string str2 = string.Empty;
        string str3 = string.Empty;
        int index = 0;
        foreach (ManagementObject obj2 in searcher.Get())
        {
            if (str2 == string.Empty)
            {
                str2 = obj2["HostName"].ToString();
            }
            strArray2[index] = obj2["ServiceClassId"].ToString();
            strArray3[index] = obj2["ServiceTypeId"].ToString();
            strArray[index] = obj2["InstanceID"].ToString();
            str3 = str3 + string.Format("  {0}\n", obj2["InstanceID"].ToString());
            index++;
        }
        new ManagementObject(string.Format("root\\MicrosoftBizTalkServer:MSBTS_HostQueue.HostName=\"{0}\"", str2)).InvokeMethod("ResumeServiceInstancesByID", new object[] { strArray2, strArray3, strArray, 1 });

It's the first query (Select * from MSBS_ServiceInstance..) that takes to long when te data is getting bigger.

Any ideas how I can improve this? The platform is Windows Server 2008 Enterprise..

Thx!

2
Out of curiosity, why are you getting so many suspended instances? It seems strange to me to write a script to restart them when you might focus on what is causing them to become suspended in the first place.aceinthehole

2 Answers

2
votes

It looks like you are getting all service instances for your orchestration, not just the suspended ones.

Try adding the following to your query's where clause, so that only suspended and suspended-not-resumable service instances are returned:

and (ServiceStatus = 4 or ServiceStatus = 16)
0
votes

Thank you for the replies. The reason I got that many suspended instances sometimes is by design. Whenever a message isn't in sequence, the orchestration gets suspended until the previous message went through. I found another way to resume the instances using the BizTalkOperations class that is installed with BizTalk:

BizTalkOperations operations = new BizTalkOperations(dataSource, initialCatalog);

foreach (Guid id in instanceIds)
{
     operations.ResumeInstance(id);
}

This code is much more performant then the WMI code (and less code ^^) :)

Thanks