Thursday, July 29, 2010

What does Sitecore v6.3 Really Means?

So it used to be called the TwinPeaks release if you follow the Sitecore Roadmap but exactly what does it bring to the table?  There are some blogs already out regarding the release.  Alex Shyba showed how easy it is to cluster the CMS client (in fact he did 6 virtual servers in less than hour – follow him on Twitter to get more updates).  Oh yes, that’s what v6.3 really allows you to do (plus some other stuff that you should read on the release notes).  But as a business person, you might ask, so what?

Well, we know that enterprises (that’s the keyword) always need performance as one of the top requirements to be fast and efficient.  The Sitecore delivery engine (i.e. content delivery – CD servers) had always been keen to being clustered and allows you to load-balance them to achieve a pretty good performance.  And that’s important because Sitecore itself may use up to 30% of CPU utilization (that’s what I’ve heard a while back in v5).  So making sure that the site visitors are experiencing beautiful user interactions while delivering them promptly can be a tough achievement if you don’t load-balance your delivery servers.  Almost all implementations nowadays have this requirement and should now be something that you should be aware of.

Sitecore v6.3 brings a new level performance except it’s not on the delivery side of things but more on the authoring side.  With v6.3, IT can now load-balance the CMS client allowing for better responsiveness.  It introduces the Event Queue which Adam Conn of Sitecore blogged about (it even has a nice video). Essentially, it is like a recipe whereby if you want to replicate your mom’s cooking again and again, you follow the recipe.  In a way, v6.3 CMS client servers look at the queue to see what else need to be done and thus become “in synch” with the other servers. 

As a business person, should I care about this?  I say yes because now there’s more freedom on how Sitecore is deployed geographically.  For international companies, this makes maintaining Web site more effective.  Also, this becomes an ammunition to having a more globalized management of Web sites.  Sitecore had been an eye-candy for managing globalized content because of translations, languages, publishing capabilities; but, there’s always that feeling that it’s really hard to distribute authorship because of geographical distances.  With v6.3, this fear or concern is minimized because performance (and reliability) becomes less of an issue. 

I’m hoping that corporations will now feel comfortable bringing in your international sites into one platform, that is Sitecore.  The only thing that I think that you need to be cautious is how those other systems going to integrate with your Web site and allow them to be “load-balanceable” as well.  I’ll leave you with this but one hint is to consider Sitecore not just a CMS but also as a foundational technical platform for other capabilities.

Sorting Sitecore Items in .NET

Have you ever asked yourself what’s the fastest (or easiest) way to sort a list of item that you retrieve using SelectItems or something similar?  It’s been answered before and there’s even been sample code provided before.  Here are some of the ones I’ve seen:

  • using IComparer
  • brute-force approach
  • using the “sortorder” provided by Sitecore

I think the last two is self-explanatory but the first one is something that I’ve seen before on SDN and works really well.  You can see a sample code on:

http://sdn.sitecore.net/Articles/API/Get%20Items%20Children%20Sorted.aspx

This solution is a definite .NET way of doing it.  I would actually say old-school but effective.  It uses the Sort method and passing it a custom IComparer. Just a simple Title sort would at least be 3-5 lines of code. 

Although with the new C# 2.0 syntax, you can reduce the # of lines by using anonymous methods such as:

numbers.Sort((x,y) => Int32.Parse(x).CompareTo(Int32.Parse(y)));

Now comes C# 3.0’s support for LINQ, you can now use that technique to do a one-line code…yes ONE LINE!!!

The code is:

var sortedList = (from entry in unsortedItems orderby entry.Fields[“Title”].Value ascending select entry);

where unsortedItems is an array of Items (i.e. Item[]) or an ItemList or any type of collection for that matter.

So how does it work?  If you’ve done LINQ (or even SQL statements) before, this should be familiar but if not, it’s quite easy.  The code above grabs an Item from the unsortedItems into a variable called entry.  Using the entry’s Fields property and the proper field name, I sort it using either “ascending” or “descending” keyword.  The “select entry” essentially completes the statement to store that same entry into the resulting variable "sortedList”.

I’ve used this technique with other field types as well and works very well.  Of course, you may need to revert back to using IComparer if you have more complex comparison rules.

CAUTION

FYI for algorithm folks, there has been mention that the LINQ’s OrderBy sort is O(n*log(n)) compared to IEnumerable’s O(n*n) which according to some is about 5 times slower with a large sample.  Here’s a link you can get a more detailed analysis of OrderBy and Sort.