How to get more out of your Dynamics CRM Server

Gayan Perera, 23 September 2010

The CRM web service has a cruisy job really, it has single create, update, delete operations, most of the time your grunty server out the back will be idling.

Recently on a project we needed to simultaneously create 200+ records per transaction, unfortunately there is no bulk create.

The quickest way is to put the 8 idling cores into good use using the ThreadPool.QueueUserWorkItem method.

    {
 
        ThreadPool.QueueUserWorkItem((o) =>
        {
            object[] state = (object[])o;
            // execute crm web service calls here
 
        }, new object[] { context, contact });
 
    });

What to use take 6-8 seconds to create 200 records now completes within 2 seconds. As you can see from the screenshot below all the cores are in use.

A little gotcha is if you’re using CredentialCache.DefaultNetworkCredentials, it will give you a 401 unauthorized error; please make sure you impersonate the multiple threads correctly.

Refer to http://msdn.microsoft.com/en-us/library/ff647404.aspx and http://www.yeyan.cn/WebDesign/ExecutionContextImpersonationNet.aspx for more information about impersonation.