从插件中调用ExecuteMultipleRequest是否有益? [英] Is It Beneficial To Call ExecuteMultipleRequest From Within A Plugin?

查看:134
本文介绍了从插件中调用ExecuteMultipleRequest是否有益?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 ExecuteMultipleRequest 是执行批处理时的巨大性能提升器从CRM外部进行更新。我不知道从CRM插件中调用它是否有益。

I know the ExecuteMultipleRequest is a huge performance booster when performing batch updates from outside of CRM. What I don't know is if it is beneficial to call it from within a CRM plugin.

我目前的理解是,使用ExecuteMultipleRequest的主要性能提高在于实际的SOAP消息传递成本。因此(为了更新5000条记录),而不是发送5000条单独的Soap消息(每条消息都必须进行序列化,身份验证,传输等),而所有这些消息都必须发送到服务器,您只能发送一条包含5000条记录的消息。但是,当从插件调用时,您已经在服务器上,因此无需进行SOAP调用,因此使用它没有好处。

My current understanding is that the main performance gain from using the ExecuteMultipleRequest is in the actual SOAP messaging costs. So (for updating 5000 records) rather than sending 5000 separate Soap messages (each having to be serialized, authenticated, transferred, etc), that all have to be sent to the server, you can send just one message with 5000 records. But when called from a plugin, you're already on the server, so no SOAP calls will have to be made, and therefor there isn't a benefit to using it.

我还有其他潜在的好处吗?

Is there some other potential benefit that I'm not seeing?

推荐答案

所以我做了我应该做的事情,并创建了一个插件对此进行测试。这是在我的本地VM(运行前)上的CRM 2013上运行的,因此结果可能会有所不同,但是我看到普通的旧Create每100个实体少花290毫秒

So I did what I should have done before, and just created a plugin to test this. This is running on CRM 2013 on my local VM (Pre-Operation), so results can vary, but I'm seeing plain old Create taking about 290ms less per 100 entities

我首先创建了这个插件

public class ExecuteMultipleTester : PluginBase
{
    protected override void ExecuteInternal(Common.Plugin.LocalPluginContext pluginContext)
    {
        var watch = new Stopwatch();
        var service = pluginContext.OrganizationService;

        watch.Start();
        var request = new ExecuteMultipleRequest
        {
            Settings = new ExecuteMultipleSettings
            {
                ContinueOnError = false,
                ReturnResponses = false,
            },
            Requests = new OrganizationRequestCollection()
        };

        for (var i = 0; i < 100; i++)
        {
            request.Requests.Add(new CreateRequest
            {
                Target = new new_Year
                {
                    new_Year = i + "- B",
                    new_YearIntValue = i,
                }
            });
        }
        service.Execute(request);
        watch.Stop();

        var multipleCreate = watch.ElapsedMilliseconds;

        watch.Restart();
        for(var i = 0; i < 100; i++)
        {
            service.Create(new new_Year
            {
                new_Year = i + "- A",
                new_YearIntValue = i,
            });
        }
        watch.Stop();

        throw new InvalidPluginExecutionException(String.Format("ExecuteMultipleRequest Time was: {0}ms, Standard was: {1}ms", multipleCreate, watch.ElapsedMilliseconds));
    }
}

注册了插件并运行了10个测试。结果是(ASCII表,是的!):

Registered the plugin and ran 10 tests. Here are the results (ASCII tables, oh yah!):

+------------------+---------------+-------+
| Execute Multiple | Sevice.Create | Diff  |
+------------------+---------------+-------+
| 777              | 408           | 369   |
| 493              | 327           | 166   |
| 614              | 346           | 268   |
| 548              | 331           | 217   |
| 577              | 312           | 265   |
| 675              | 313           | 362   |
| 574              | 318           | 256   |
| 553              | 326           | 227   |
| 810              | 318           | 492   |
| 595              | 311           | 284   |
+------------------+---------------+-------+
|                    Average Diff: | 290.6 |
+------------------+---------------+-------+

因此,从这些结果中,无需从插件内执行ExecuteMultipleRequest。您已经在服务器上,必须执行更多代码才能执行相同的操作。

So from these results, there is no need to execute an ExecuteMultipleRequest from within a plugin. You're already on the server, having to execute more code to perform the same operation.

我再次运行了此测试,以创建1000条记录,并在一个成熟的环境中,使用了单独的SQL,Services和Web框。结果非常相似(由于花费了更长的时间,因此仅进行了5次测试)

I ran this test again for the creation of a 1000 records, and in a full fledged environment with separate boxes for SQL, Services, and Web. Very similar results (only ran 5 tests since it was taking a lot longer)

+------------------+----------+--------+
| Execute Multiple | Standard |  Diff  |
+------------------+----------+--------+
|            18922 | 15057    | 3865   |
|            18668 | 14946    | 3722   |
|            18162 | 14773    | 3389   |
|            19059 | 14925    | 4134   |
|            18334 | 15306    | 3028   |
+------------------+----------+--------+
|                  | Average  | 3627.6 |
+------------------+----------+--------+

有趣的是,时间大约是25倍,而记录多了10倍,但差异仅是12倍。 (试图进行更新而不是删除,但是我一直在遇到超时错误,即使每个错误都只是一次。。。一定是在创建某种无限循环,只是不确定是什么...)

Interesting thing was the time was around 25 times longer for 10 times more records, but the differences was only 12 times more. ( Attempted to do updates rather than deletes, but I kept on getting timeout errors, even at just one for each... Must have been creating some sort of infinite loop, just not sure what... )

对于1000个创建,其速度慢了将近4秒。我不会在插件中使用它。

For a 1000 creates, its almost 4 seconds slower. I wouldn't use it in my plugins...

这篇关于从插件中调用ExecuteMultipleRequest是否有益?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆