ATUL SHARMA
ATUL SHARMA

Reputation: 55

CrmServiceClient - Performance Issues

We are using CrmServiceClient as a singleton instance for all the methods being used. Other configurations are

RequireNewInstance = True; AuthType = OAuth

Normally it works as expected but in load testing, it is getting stuck at Monitor.Enter() of RetrieveMutliple()

Dynatrace logs show, it is taking 99.9% of the time there only and this is how it is breaching the SLA. In the On-Prem setup, it was working fine (AuthType was IFD for On-Prem).

Is there any specific setting we need to do for D365?

Upvotes: 1

Views: 427

Answers (2)

Sean McNellis
Sean McNellis

Reputation: 71

If you want to use RequireNewInstance=True and to have multiple 'threads' or instances of CrmServiceClient to connect.

  1. Use DisableCrossThreadSafeties = true - that will ensure CrmServiceClient isn't trying to only use a single connection back to Dataverse - this also means you need to handle your own thread safety with CrmServiceClient.

  2. instantiate a singleton CrmServiceClient (ie: _CrmService) to create a single connection to use at startup or on the first operation. Then, for every execution, make sure to call CrmServiceClient.Clone() to get a unique instance:

using(var service=_CrmService.Clone()){ 
    service.Execute(OrganizationRequest); 
} 

This approach will give each operation it's own instance/connection back to the service, the Using will ensure disposal of each of those connections/clients.

Upvotes: 1

Henk van Boeijen
Henk van Boeijen

Reputation: 7918

RequireNewInstance should be set to False, unless you have a specific reason to set it otherwise, e.g. you are using a single CrmServiceClient instance to access multiple endpoints.

The lock on Monitor.Enter() indicates multiple threads are getting queued waiting for a free connection object. You could speed up your application by introducing a pool of CrmServiceClient objects. This should work in a way similar to ADO.NET connection pooling. Remember a CrmServiceClient object can only handle one HTTP request at a time.

Upvotes: 1

Related Questions