Friday, 24 January 2014

Dynamics CRM Load and Web Performance Testing

Testing... the bit that comes at the end of every project! The one part which makes you realise how everything you have built and convinced yourself is running exactly how it should, may not be the case...

Recently after deploying a new customised CRM 2011 platform, the topic of load and performance testing came up. Not something that would normally need to be tested on a fully vetted of the shelf product, but still useful to show a working model of the infrastructure and application under load.

After some digging around I decided in this particular case, for an on premise deployment with custom entities, that custom tests would be most beneficial.

Requirements

In order to take advantage of the testing features offered by Visual Studio, a copy of the Ultimate version is required. Using a trial version you can simulate up to 250 users in a load test, any more than this and you will need the licensed product. In this case I have used Visual Studio 2013 Ultimate.

Actions

The following actions were taken to complete testing:

  • Create a Web Performance and Load Test project
  • Create a new Web Performance Test (CRM UI)
  • Create Unit Tests for data manipulation (CRM WCF)
  • Create a Load Test, incorporating the tests already created.

Web Performance and Load Testing


Firstly in VS you will need to create a new project:

File > New > Project > In the Test category, located under the Visual C# category, you should find Web Performance and Load Test Project:



Web Performance Test


In your newly created project you should see a Web Test already created for you, if not you can add this into your project by right clicking the project in the Solution Explorer on the right.

You can use this test if you want to simulate traffic to the CRM Web UI, e.g. A user opening up a browser and navigating to http://<CRM_Server>:<port>/<Organisation>.

To create the web test, you will see the "Add Recording" button at the top hand pane of this page in your project:


Once you have enabled the plugin for Internet Explorer, this will record the sites you visit via the browser and all web resources loaded from the server:



Unit Test


In order to simulate records being created and removed from the CRM application, I decided to create separate tests, this was achieved using the CRM WCF Endpoint. This is particularly useful to integrate with all the CRM metadata, meaning that you can work with custom entities as well as standard, supporting both late-bound and early-bound types.

Create a new Unit Test in your project by right clicking the project in the Solution Explorer on the right, selecting Add > Unit Test...

Below is an example test written to create and remove accounts in CRM, you may want to write more of your own to test custom entities:

using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.Xrm.Sdk;
using System.ServiceModel.Description;
using Microsoft.Xrm.Sdk.Client;
using Microsoft.Xrm.Sdk.Query;
using System.Configuration;

namespace CRMLoadTest
{
    [TestClass]
    public class AccountTest
    {
        private IOrganizationService orgService { get; set; }
        private ClientCredentials _ClientCreds { get; set; }

        private Guid resultId { get; set; }

        [TestInitialize]
        public void SetUp()
        {
            orgService = null;
            Uri uri = new Uri(ConfigurationManager.AppSettings.Get("orgWcfService"));
            IServiceConfiguration orgConfigInfo =
                ServiceConfigurationFactory.CreateConfiguration(uri);

            orgService = new OrganizationServiceProxy(orgConfigInfo, _ClientCreds);
        }

        [TestMethod]
        public void CreateAccount()
        {
            //arrange
            var account = new Entity("account");
            account.Attributes.Add("name", string.Format("Unit Test {0}", DateTime.Now));

            //act
            resultId = orgService.Create(account);

            //assert
            var createdAccount = orgService.Retrieve("account", resultId, new ColumnSet(new[] { "accountnumber" }));
            Assert.IsNotNull(createdAccount.GetAttributeValue("accountnumber"));
        }

        [TestCleanup]
        public void RemoveAccount()
        {
            orgService.Delete("account", resultId);
        }
    }
}


As you can see above on line 23, I am pulling the endpoint URL from an app.config file. This is to be able to easily change the server for the tests without manually editing each test. The App.config file I have created looks like the below [optional]:

 <?xml version="1.0" encoding="utf-8" ?>
  <configuration>
    <appSettings>
      <add key="orgWcfService" value="http://crm01/CRM/XRMServices/2011/Organization.svc"/>
    </appSettings>
  </configuration>

Remember you can create as many tests as you like to be added to your load test.


Load Test


Now you have created the above tests, we can add these together into a load test. The load test gives you the ability to simulate multiple users all running these tests at once.

The Web Performance Test coupled with the Unit Tests you have written would not only produce many users loading the CRM Web UI, but also produce many users all creating and deleting records as well.

To create a new test, right click your project as you did before in the Solution Explorer and select Add > Load Test... Using the wizard provided you can now set conditions for you load test, such as:

User Count

Setting the amount of users that will be simulated when running your tests.


Test Mix

Here you will add your tests and choose your distribution between them.


Counter Sets

A particularly useful feature to be able monitor the performance of the application servers while the load test is run.



Output

Once you have completed and ran the Load Test you will have a visual output of all counters monitored, as well as statistics of the tests performed:




Hopefully this post has been useful and inspired some ideas when it comes to load testing your infrastructure and applications.



5 comments:

  1. This comment has been removed by the author.

    ReplyDelete

  2. BizTalk: Performance tips for high volume WCF calls
    http://social.technet.microsoft.com/wiki/contents/articles/33642.biztalk-performance-tips-for-high-volume-wcf-calls.aspx

    any guide Performance tips for high volume WCF calls for CRM 2016 using XRMServices/2011/Organization.svc service ?

    Can I use it ? is it possible ?

    system.servicebehaviors -> throttling values
    system.net -> connectionManagement -> maxConnection
    processModel -> maxWorkerThreads=”500″
    maxIoThreads=”500″
    minWorkerThreads=”250″
    minIoThreads=”250″


    • Changed throttling values:
    • WCF: maxConcurrentCalls, maxConcurrentSessions, maxConcurrentInstances all to 1000
    • TCP binding: maxConnections=1000
    • Threadpool: Min worker threads = 1000, Min IO threads = 2000

    serviceThrottling maxConcurrentCalls="100"
    maxConcurrentInstances="100" maxConcurrentSessions="100"

    connectionManagement and address="*" maxconnection="100"


    processModel
    enable="true"
    timeout="Infinite"
    idleTimeout="Infinite"
    shutdownTimeout="00:00:05"
    requestLimit="Infinite"
    requestQueueLimit="5000"
    restartQueueLimit="10"
    memoryLimit="60"
    webGarden="false"
    cpuMask="0xffffffff"
    userName="machine"
    password="AutoGenerate"
    logLevel="Errors"
    clientConnectedCheck="00:00:05"
    comAuthenticationLevel="Connect"
    comImpersonationLevel="Impersonate"
    responseDeadlockInterval="00:03:00"
    responseRestartDeadlockInterval="00:03:00"
    autoConfig="false"
    maxWorkerThreads="100"
    maxIoThreads="100"
    minWorkerThreads="40"
    minIoThreads="30"
    serverErrorMessageFile=""
    pingFrequency="Infinite"
    pingTimeout="Infinite"
    maxAppDomains="2000"



    httpRuntime executionTimeout="90" maxRequestLength="4096"
    useFullyQualifiedRedirectUrl="false" minFreeThreads="8"
    minLocalRequestFreeThreads="4" appRequestQueueLimit="100"
    enableVersionHeader="true


    ReplyDelete
  3. I would like to do load testing on my Dynamic CRM 2016, how did you handle authentication as we have enabled claims base authentication.

    ReplyDelete
  4. What you have written in this post is exactly what I have experience when I first started my blog.I’m happy that I came across with your site this article is on point,thanks again and have a great day.Keep update more information.
    CRM Software In India
    CRM Software In Chennai
    CRM Software

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete

Comments, thoughts, questions...?