Optimize MS CRM webservice

Currently I'm working on an import program. I have to import thousands and thousands of records. Usually the crm system is quite fast, but with these huge loads, I'm getting quite anoyed by the performance of the MS CRM webservice. It even causes error messages like "The underlying connection was closed: Unable to connect to the remote server.".

Now there are some performance tweaks available. I wanted to write a post about it, but just before I found an article written by Aaron Elder. This is a must-read for people writing code to import bulk data. However, this page has been removed, but the same information is available at Bill's blog: Blog Move: Speed Racer - Call CRM at speeds that would impress even Trixie

7 comments:

Gaploid said...

Yep, i`ve got the same problem=) but it`s strange sometimes i get it sometimes not. I`ll wait your post about it.

Ronald Lemmen said...

Hi Gaploid,

I won't be blogging about it, because Aaron Elder already did so. The link to his post is:
http://www.invokesystems.com/cs/blogs/mscrm/archive/2006/06/01/28.aspx

Gaploid said...

hmm, so the Aaron Elder post about perfomance. But you mention a problem: "The underlying connection was closed: Unable to connect to the remote server".or do You think this article can solve it?

Ronald Lemmen said...

Aaron is speaking in his post about an Unsafe connection. This is by using the attribute UnsafeAuthenticatedConnectionSharing on the webserver. He's describing the positive things (38% faster), but also the catches (make sure only one user uses this on the same time). Using this attribute solves the issue.

Anonymous said...

Hi Roland. I was wondering how your import applications has finally developed, since I am now working on such an import myself.

I am loading about 300,000 records (each loading contacts and two custom entities, with linking between). Now, I get this weird problem, I was wondering if you stumbled upon it yourself.

Using the UnsafeAuthenticatedConnectionSharing proretry did help speed up the process tremendously (and also solved an a socket exception that got thrown for no reason I could come up with), but I'm still left with a weird thing: after loading about 8,000 entities, each time, the service gets stuck! for no reason I found as well.

Once it gets stuck, the only way to continue with the import is to restart the application and resume from the location from the line were it got stuck earlier in the file.

If you stumbled upon this, any information will be useful. Thanks, Or.

Ronald Lemmen said...

Hi,

Importing 8000 records shouldn't be a problem. I just finished an import of about 15000 contacts.

Are you creating one instance of the webservice or for each record one? Try setting the timeout for the webservice to "-1".

Hope this helps,

Ronald

Chad Rexin said...

Hi Gaploid and Ronald,

The Underlying connection was closed: Unable to connect to the remote server" is a problem due to running out of ephemeral TCP ports. You can minimize or eliminiate this problem by setting the following registry keys on the Microsoft CRM Server(s). This is typically seen in scenarios with Microsoft CRM when the server is under high user load or more typically when it is under high load from a Bulk import or a Microsoft CRM SDK application that is importing thousands of records into the application. Note that these are both REGDWORD Keys and the values should be set as decimal values.

HKLM\Software\CurrentControlSet\Services\TCPIP\Parameters

Create a new REGDWORD value named MaxUserPort with a value of 65534.

Also create a new REGDWORD value named TcpTimedWaitDelay with a value of 30. What this means is that we now have a total of 65534 TCP ports available and that they will recycle for use again after 30 seconds. This compares to the default of 5000 ports and a TcpTimedWaitDelay default of 240 (4 min).

Note that for both of these registry values to take effect you must reboot the server. Also note that this is valid for Windows Server 2000, Windows Server 2003, and can also be set on Vista and XP Clients. Windows Server 2003 SP2 appears to set these values automatically for you based on what I have seen in test environments. You can see more details about this at the following KB articles and web sites:

http://support.microsoft.com/kb/196271
http://www.microsoft.com/technet/network/deploy/depovg/tcpip2k.mspx

Hope this helps with your future deployments and use of Microsoft CRM.

Chad Rexin