zoukankan      html  css  js  c++  java
  • Dynamics CRM2016 查询数据的三种方式的性能对比

        之前写过一个博客,对非声明验证方式下连接组织服务的两种方式的性能进行了对比,但当时只是对比了实例化组织服务的时间,并没有对查询数据的时间进行对比,那有朋友也在我的博客中留言了反映了查询的时间问题,一直没时间做具体的测试,值此web api出现的时机,一并测下

        下方是我的测试demo,分别列出了获取组织服务需要的时间及查询所花时间,demo中是以查询一条用户记录的所有属性为例

         三种分别是1、CrmConnection

                           2、普通的方式(姑且这么叫吧,因为这是最常用的)

                           3、web api

     static void Main(string[] args)
            {
                string result = "";
                #region CrmConnection效率
                DateTime dt1 = DateTime.Now;
                OrganizationService org = new OrganizationService(new CrmConnection("crm"));
                DateTime dt8 = DateTime.Now;
                result = result + "CrmConnection实例服务时间 " + (dt8 - dt1).Milliseconds.ToString() + "
    ";
                Entity test = org.Retrieve("systemuser", new Guid("B3EB9804-6CD8-E511-9413-D04319595BED"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                DateTime dt2 = DateTime.Now;
                result = result + "CrmConnection查询时间 " + (dt2 - dt8).Milliseconds.ToString() + "
    ";
                #endregion
    
                #region 普通方式获取OrganizationService
                DateTime dt3 = DateTime.Now;
                ClientCredentials clientCredentials = new ClientCredentials();
                clientCredentials.Windows.ClientCredential = new System.Net.NetworkCredential("administrator", "001", "skysoft");
                IOrganizationService organizationServiceProxy = new OrganizationServiceProxy(new Uri("http://crmhost/XRMServices/2011/Organization.svc"), null, clientCredentials, null);
                DateTime dt4 = DateTime.Now;
                result = result + "普通方式获取组织服务时间 " + (dt4 - dt3).Milliseconds.ToString() + "
    ";
                Entity test1 = organizationServiceProxy.Retrieve("systemuser", new Guid("B3EB9804-6CD8-E511-9413-D04319595BED"), new Microsoft.Xrm.Sdk.Query.ColumnSet(true));
                DateTime dt5 = DateTime.Now;
                result = result + "普通方式查询数据时间 " + (dt5 - dt4).Milliseconds.ToString() + "
    ";
                result = result + "普通方式查询数据总时间 " + (dt5 - dt3).Milliseconds.ToString() + "
    ";
    
                #endregion
    
                #region web api方式
                DateTime dt6 = DateTime.Now;
                HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://crmhost/api/data/v8.0/systemusers(B3EB9804-6CD8-E511-9413-D04319595BED)");
                req.Credentials = new NetworkCredential("administrator", "", "skysoft");
                req.Method = "Get";
                using (HttpWebResponse res = (HttpWebResponse)req.GetResponse())
                {
                    StreamReader read = new StreamReader(res.GetResponseStream());
                    string result1 = read.ReadToEnd();
                }
                DateTime dt7 = DateTime.Now;
                result = result + "web api查询时间 " + (dt7 - dt6).Milliseconds.ToString() + "
    ";
    
                #endregion
                Console.WriteLine(result);
                Console.ReadLine();
           }


        下图是测试结果,可以看出第1种方式获取组织服务确实比第二种快很多,但在查询具体数据时就会落后很多,所以综合下来半斤八两吧,没有明显的差距,但看第三种也就是web api,完虐前两种,孰优孰劣一目了然。






  • 相关阅读:
    Laravel 通知
    LARAVEL 6 + VUE + SEMANTIC UI
    Laravel 从入门到精通教程【预备篇、基础篇】
    Laravel Vue.js 聊天室
    GIT代码管理: git remote add 【转载】
    Laravel Vuejs 实战:开发知乎 (45-47)用户设置
    Laravel Vuejs 实战:开发知乎 (42-44)用户头像
    如何在运行时更改JMeter的负载
    Jmeter Grafana Influxdb 环境搭建
    实时结果
  • 原文地址:https://www.cnblogs.com/cl1024cl/p/6205816.html
Copyright © 2011-2022 走看看