[英]Microsoft.Xrm.Tooling.Connector High Memory Allocation
I am currently going through the process of upgrading our product CRM SDK and the main change I have encountered is that instead of connecting to the Xrm service and creating my IOrganizationService using the tried and trusted method of: 我目前正在完成升级产品CRM SDK的过程,我遇到的主要变化是使用以下尝试和信任的方法连接到Xrm服务并创建我的IOrganizationService:
var connection = CrmConnection.Parse(connectionString);
var service = new OrganizationService(connection);
I am now having to utilise the CrmServiceClient from the Tooling namespace: 我现在不得不使用Tooling命名空间中的CrmServiceClient:
CrmServiceClient conn = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(connectionString).OrganizationServiceProxy;
Now this is all fine except from one major issue...memory. 现在这一切都很好,除了一个主要问题......记忆。
Using the older Xrm.Client method you were able to specify the Service Configuration Instance Mode (which defaulted to ServiceConfigurationInstanceMode.PerName). 使用较旧的Xrm.Client方法,您可以指定服务配置实例模式(默认为ServiceConfigurationInstanceMode.PerName)。 What this meant is that the service was reused if the same application called the create multiple times.
这意味着如果同一个应用程序多次调用create,则会重用该服务。 This kept the memory footprint low.
这使内存占用率降低。 The below image show the amount of allocated memory after calling to create a service instance 100 times
下图显示了在调用创建服务实例100次后分配的内存量
However, using the newer method you cannot set this instance mode anywhere and it seems that a brand new connection is created every time whether you want it or not. 但是,使用较新的方法无法在任何地方设置此实例模式,似乎每次都会创建一个全新的连接,无论您是否需要它。 Here are the results of the same test:
以下是同一测试的结果:
As you can see, with every new connection, more and more memory is allocated. 如您所见,每次新连接都会分配越来越多的内存。 I can;t see anywhere that i can tell it to reuse the service.
我无法看到我可以告诉它重用该服务的任何地方。
So what I'm basically asking is, am I going about this in the wrong way? 所以我基本上要问的是,我是以错误的方式解决这个问题吗? Should I be creating and caching everything myself?
我应该自己创建和缓存一切吗? Are there hidden classes/methods that I am missing?
我缺少隐藏的课程/方法吗? Any help would be greatly appreciated.
任何帮助将不胜感激。
The latest SDK (8.2.0.1) caches and resuses the connection as long as the connectionstring does not inclue RequireNewInstance=true
. 只要连接
RequireNewInstance=true
不RequireNewInstance=true
,最新的SDK (8.2.0.1)就会缓存并重新使用连接。
One thing worth noting is even if you new up another CrmServiceClient
with a unique connection string (pointing to a different CRM organization), but the connection string does not include RequireNewInstance=true
, the CrmServiceClient
will reuse the previous cached connection. 值得注意的是,即使您使用唯一的连接字符串(指向不同的CRM组织)新建另一个
CrmServiceClient
,但连接字符串不包含RequireNewInstance=true
, CrmServiceClient
也将重用以前的缓存连接。
So 所以
var connectionString = $@"Url=https://ORG1.crm.dynamics.com;AuthType=Office365;UserName=USER@DOMAIN.com;Password=PASSWORD";
var connectionString2 = $@"Url=https://ORG2.crm.dynamics.com;AuthType=Office365;UserName=USER@DOMAIN.com;Password=PASSWORD";
var crmSvcClient = new CrmServiceClient(connectionString);
((WhoAmIResponse)crmSvcClient.Execute(new WhoAmIRequest())).OrganizationId.Dump();
crmSvcClient.ConnectedOrgFriendlyName.Dump();
var crmSvcClient2 = new CrmServiceClient(connectionString2);
((WhoAmIResponse)crmSvcClient2.Execute(new WhoAmIRequest())).OrganizationId.Dump();
crmSvcClient2.ConnectedOrgFriendlyName.Dump();
Prints out the guid and ORG1 friendly name both times. 两次打印guid和ORG1友好名称。 If you pass
RequireNewInstance=true
in connectionstring2
then you will see ORG2 printed out. 如果您在
connectionstring2
传递RequireNewInstance=true
,那么您将看到ORG2打印出来。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.