Monday, 15 December 2014

OrganizationServiceContext performance in MS Dynamic CRM 2013

The OrganizationServiceContext has a SaveChanges method that essentially does what it says on tin, namely the changes on the objects back to the database.

I've never used this method, preferring to use the regular Update method  on the IOrganizationService instead, but last week I had a moment of doubt, what if it is faster, what if it's multi-threaded, so I decided to run some tests to see whether there was any performance difference, spoiler alert: There wasn't
The tests consisted of the update of a three fields on the account entity for 2000 accounts and were run from an idle CRM server to minimize the influence of network traffic.

Results shown below are for the average of the three runs I did, except for the parallel version, using Parallel.ForEach, where it shows the single run I did.

OrganizationServiceContext IOrganizationService IOrganizationService (Parallel)
126.7 s 130.1 s 49.6 s

My fears were unfounded and the SaveChanges method, while slightly faster in these tests, does not seem to be appreciatively faster.

The difference is less than 3% and the slowest run using the OrganizationServiceContext was basically the same as the fastest with IOrganizationService : ~129 s


Saturday, 13 December 2014

Housework

Over the past three and half months my lovely girlfriend has been suffering from terrible eczema, so she's basically not been helping much with the household chores, which is why I've been looking at how long I've spend doing housework everyday.

I have been measured how long I spent doing work and what sort of work it was. The measurements almost certainly an underestimate as I've probably missed little tasks here and there, e.g. cleaning up a spill or any such ad hoc task.

I've broken down the tasks in three categories: Cooking, Cleaning and Miscellaneous.

The first two are self explanatory, although it's worth mentioning that when it comes to cooking I have only counted the preparation time, except for when the cooking time was so short that it would not really allow me to do anything else, in practice this only has significant a bearing in Sundays figures as we normally have pancakes, french toast or eggs Benedict for breakfast.

Miscellaneous is anything that is not cooking or cleaning, e.g. tidying up, putting the washing away, etc..

We live in a, small?, two bedroom apartment (about 60 m2) and have no children or pets, don't eat out much (twice a month since the data keeping started) and mostly cook from scratch, so without further ado, these are the figures:

Total:


As a percentage:




Friday, 21 November 2014

TIL - Solving Out of Memory exceptions in .NET

So yesterday I was playing about with a high memory VM in Azure and I wrote a little app to swallow the server's RAM whole.
Only thing is that it stopped running and didn't swallow the server's RAM whole.

So I changed the build to x64, but no dice.

After a bit of googling, it turn out that by default there is a limit that needs to be defeated, the 2 GB limit and it can be defeated by adding the following to the config file.
<configuration>
 <runtime>
  <gcAllowVeryLargeObjects enabled="true" />
 </runtime>
</configuration>

Thursday, 20 November 2014

Introduction to the Cloud with Microsoft Azure - Part 2

Following from the previous post, I will continue explaining the features that Azure offers for VMs.

The first feature I want to discuss is the Dashboard, which allows you to have a view of what your VM is doing.



A very nice feature of Azure VMs is alerting, in essence, you can get notified once a certain threshold has been exceed. In the example below will set an alert to email the administrator if CPU exceeds 80% for more than 5 minutes.

Click on Monitor and Select the Metric that you want and alert for and then Click add Rule




The next feature I want to cover is the firewall. When a new machine is provisioned the firewall will only be opened for PowerShell and Remote Desktop/SSH

You can see this by navigating to Virtual Machines -> <YourVM> -> Dashboard -> Endpoints


Let's add a new rule. Just Click Add and follow the screens below:



It is possible to specify ACLs for firewall rules, so below I've added a rule for my IP address, note that this only apply to the  particular rule selected when you clicked manage ACL:


Finally, one of my favourite features. Configuring the VM itself. It is possible to change the sizing of the VM here, but this will effectively take offline for a few minutes:


I haven't covered availability sets and a few other features, which I guess will have to wait until part 3.

Wednesday, 12 November 2014

Introduction to the Cloud with Microsoft Azure - Part 1

My new company has been kind enough to provide me with an MSDN subscription, which comes with some Azure credits so I thought that I would try to make use of it.

I thought I would start with the easiest part and describe Virtual Machines in the cloud.

The first thing to bear in mind is that this is not a substitute for regular hosting providers, if you are going to be using your server 24/7, you would be worse off in the cloud. Take this small example:

At the time of writing, you can get a dedicated 16 CPUs, 64 GB of RAM, 1.2 TB of HDD and unmetered connection for £150 per month (123 hosting)

A comparable machine in Azure, A7 (8 CPUs, 56 GB of RAM, not sure how much HDD), will set you back £416 per month and that doesn't count data transfers or disk operations.

So, Why would anybody use Azure or any other cloud solution?

It's pay as you go, which means that you can have say, a test environment, and only use it when there is a release, this might mean that your usage is one out of every four weeks depending on your release scheduled and because you can turn it off while not in use, you might only pay for say 5 days or 2.5 days if you turn it off at the end of the day, so now the comparison looks more like:

Traditional Hosting: £150
Azure: £33.60 + Bandwidth + Disk Operations

A much better proposition.

At any rate, enough with the economics of the cloud.

Logging to the Azure Portal and navigate to Virtual Machines, where you'll find something like this:



Click on New -> Quick Create -> Create Virtual Machine

I've gone for gold and selected the most powerful machine.


You can also browse the gallery, if you don't like the OS options available or you want a pre-built machine. Say you want a Biztalk2013 image






Finally, when you've tired of all the playing about you can just delete it:

Navigate to Cloud Services -> Select the one you want to delete -> Click Delete -> Select Delete the cloud service and its deployments.


You can manage your VMs from Virtual Machines on the menu and I will go on more detail about it on my next post.

Tuesday, 11 November 2014

I broke Ms Dynamics CRM 2013 today

So I have a custom workflow activity that has an output of a custom reference, something like this:

[Output("ClientRecord")]
[ReferenceTarget("new_clientrecord")]
public OutArgument<EntityReference> ClientRecord { get; set; }
And like idiot I did this:

ClientRecord.Set(executionContext, ClientRecordEntity);
where ClientRecordEntity is an Entity and not an EntityReference.
Running the Dialog that contained this workflow activity, resulted in a very, very long wait and after that, 503 for absolutely everybody using the dev environment.
A proud day, today
I broke CRM.

Saturday, 8 November 2014

Visualization of Azure VM Pricing

I did a presentation on the merits of using Microsoft's Azure for a our development and test environments and here are a few of the plots I produced.

Pricing correct as of today (2014_11_08), see this for up to date pricing.

I tried to plot everything in one graph, but it didn't really work all that well.

Red indicates Standard A instance, Blue Basic A Instance and Green Standard D Instance.

Exhibit A:

 Exhibit B:


Alright then, let's try to split them up.

By Number of Cores first (Red indicates Standard A instance, Blue Basic A Instance and Green Standard D Instance):


By Memory (RAM) size (Red indicates Standard A instance, Blue Basic A Instance and Green Standard D Instance):


Tuesday, 4 November 2014

Install and configure MariaDB.

This is a fairly easy objective:

Run the following command to install MariaDB:
sudo yum -y install mariadb mariadb-server
 To start and enable it so that it starts again post reboot:
systemctl start mariadb.service
systemctl enable mariadb.service
Finally, run this script (and follow the steps therein) to finalize the installation:
mysql_secure_installation 
I'm not entirely, if anything else is required by this objective to be honest and I'm a bit rusty with Linux, which is why I started with something easy.

Tuesday, 28 October 2014

Limit Regarding Lookup in MS Dynamics CRM 2013

So Today we had an interesting requirement: We had a custom entity, called Paper, for which we wanted to limit the entities that could be selected for the regarding lookup.

I can't come up with a supported way of doing this so this is the unsupported way:

In essence, this will limit the Regarding to new_keyissue and new_goal.

You'll need to fire it on the onChange event like this, NEW.Paper.limitRegardingLookup.

if (typeof (NEW) == "undefined")
{ NEW = {}; }
NEW.Paper = {
    limitRegardingLookup: function () {
        
        var KeyIssueOTC = GetEntityTypeCode("new_keyissue");
        var goalOTC = GetEntityTypeCode("new_goal");
  
        var ObjectTypeCodeList = KeyIssueOTC + ", " + goalOTC;
        var LookupTypeNames = "new_keyissue:"+ KeyIssueOTC + ":Key Issues,new_goal:" + goalOTC + ":Goal";
        
 Xrm.Page.getControl("regardingobjectid").setFocus(true);
  
        document.getElementById("regardingobjectid_i").setAttribute("lookuptypes", ObjectTypeCodeList);
        document.getElementById("regardingobjectid_i").setAttribute("lookuptypenames", LookupTypeNames);
        document.getElementById("regardingobjectid_i").setAttribute("defaulttype", KeyIssueOTC);

    }
};

function GetEntityTypeCode(entityName) {
    try {
        var lookupService = new RemoteCommand("LookupService", "RetrieveTypeCode");
        lookupService.SetParameter("entityName", entityName);
        var result = lookupService.Execute();
        if (result.Success && typeof result.ReturnValue == "number") {
            return result.ReturnValue;
        }
        else {
            return null;
        }
    }
    catch (ex) {
        throw ex;
    }
}

Sunday, 26 October 2014

Enable .NET Framework 3.5 in Windows 2012 Azure Virtual Machine (VM) - Error Code 0x800F0906

Yesterday I tried to install Ms SQL Server in a Azure VM that was running Windows 2012 R2, but it would complain about not being able to enable it.

So I tried from Server Manager and I got the following error:


Since this is a Azure VM, I don't think I should be downloading the Windows ISO, so ... well, it turns out that this is a known issue for which there is a fix, so all you need to do is apply the latest Windows updates and then it will install fine.

Control Panel -> Windows Updates


11 updates, WTF MS?


The one we care about.

The question I have is why in the name of all that is holy, isn't the fix already applied when the VM is provisioned? I get that MS can't just release a new image for every fix but preventing the install of SQL Server seems to be a big enough issue to warrant a new image, even if there are SQL Server VMs, but they are more expensive and .... at any rate, hope it saves people time.

I guess it's a matter of time, hopefully.