Stefan Goßner

Senior Escalation Engineer for SharePoint (WSS, SPS, MOSS, SP2010) and MCMS

Avoid performance problems caused by MCMS Publishing API

Avoid performance problems caused by MCMS Publishing API

  • Comments 8
  • Likes

Inproper use of the MCMS publishing API can cause significant performance problems in MCMS. A good summary of things to avoid and to do is listed in Chesters article.

Beside the hints in Chesters article here are some less good known facts you need to be aware of:

1) Do not use the HtmlPlaceholder.Text property

The implementation of the Text property of the HtmlPlaceholder object can cause serios performance problems due to the fact that the implementation of this property is done in a STA threaded COM object. This can cause serialization problems as only one page request can use this property at a given time. Other requests using the same property will be queued up which can cause serious performance degrades.

Rather than using the Text property implement the following method in a utility class and pass in the Html property of the HtmlPlaceholder object:

public static string StripHtmlTags(string source)
{
    string strRegExp = "<(.|\n)+?>";
    Regex r = new Regex( strRegExp, RegexOptions.IgnoreCase | RegexOptions.Compiled );
    string strNoTags = r.Replace( source, "" );    
    return System.Web.HttpUtility.HtmlDecode( strNoTags );
}

2) Do not access custom properties by name if you are unsure if a custom property with this name exists

The implemenation of the custom property collection can cause serious performance problems when items are accessed by name which do not exist. The reason is that an internal exception is raised when the custom property cannot be found and this internal exception causes a similar serialization problem as one listed above with the Text property.

Affected code would look like the following:

if (posting.CustomProperties["PropertyName"] != null
....

This code tries to access the Custom Property with name PropertyName and tests if it exists. Before "null" is returned the Custom Property Collection internally raises an exception which will then caues the serialization problem.

To ensure good performance you need to implement the following method in a Utility class:

public static CustomProperty GetCustomProperty(CustomPropertyCollection cpc, string Name)
{
    foreach (CustomProperty cp in cpc)
    {
        if (cp.Name == Name)
            return cp;
    }
    return null;
}

The if statement above then need to be recoded as follows:

if (Utility.GetCustomProperty(posting.CustomProperties, "PropertyName") != null
....

3) Do not access placeholder objects by name if you are unsure if a placeholder object with this name exists

This is actually the same issue as listed under #2 with the custom properties.

Affected code would look like the following:

if (posting.Placeholders["PlaceholderName"] != null
....

This code tries to access the Placeholder object with name PlaceholderName and tests if it exists. Before "null" is returned the Placeholder Collection internally raises an exception which will then caues the serialization problem.

To ensure good performance you need to implement the following method in a Utility class:

public static Placeholder GetPlaceholder(PlaceholderCollection pc, string Name)
{
    foreach (Placeholder p in pc)
    {
        if (p.Name == Name)
            return p;
    }
    return null;
}

The if statement above then need to be recoded as follows:

if (Utility.GetPlaceholder(posting.Placeholders, "PlaceholderName") != null
....

Be aware that the same problem will occur with all MCMS collections like PostingCollection, ChannelCollection, TemplateCollection, ...

If you are not sure that the item exists, iterate through the collection rather than accessing by name and checking for a null value.

Comments
  • What if someone uses a > or a < in the placeholder?

  • > and < as characters have to be stored as &lt; or &gt; otherwise the content is not valid html.

  • What about the PlaceholderCollection? Does it suffer from the same implementation as the CustomPropertyCollection?

  • Yes it would. But I have never seen code that accesses placeholders this way.

  • Would accessing the bound placeholder rawcontent of an HTML or XML placeholder cause the same performance issues as the text property of the HTML placeholder?

  • First of all: the problem with the Text property is solved with MCMS 2002 SP2.

    Second: you should avoid DataSource.RawContent.

    See here for details: http://blogs.technet.com/stefan_gossner/archive/2004/04/24/119546.aspx

    To answer your question: no this will not have a performance problem.

  • Thanks, were encountering a minor memory leak in our environment, we did implement accessing properties without knowing if it exists, could this be a possible cause to a memory leak? Were still using SP1a for MCMS

  • Support for SP1a has ended January this year. All server need to be on SP2 to be in a supported state.

    To answer your question: no this will not lead to a memory leak.

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
Raw Html Fix