Welcome to TechNet Blogs Sign in | Join | Help

Avoid performance problems caused by MCMS Publishing API

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.

Published Monday, July 25, 2005 1:24 PM by Stefan_Gossner
Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Tuesday, August 16, 2005 7:26 AM by Jim

# re: Avoid performance problems caused by MCMS Publishing API

What if someone uses a > or a < in the placeholder?
Tuesday, August 16, 2005 1:41 PM by Stefan_Gossner

# re: Avoid performance problems caused by MCMS Publishing API

> and < as characters have to be stored as &lt; or &gt; otherwise the content is not valid html.
Wednesday, October 12, 2005 10:13 AM by Tobias

# re: Avoid performance problems caused by MCMS Publishing API

What about the PlaceholderCollection? Does it suffer from the same implementation as the CustomPropertyCollection?
Wednesday, October 12, 2005 10:36 AM by Stefan_Gossner

# re: Avoid performance problems caused by MCMS Publishing API

Yes it would. But I have never seen code that accesses placeholders this way.
Tuesday, August 21, 2007 9:01 PM by Nicholas del Rosario

# re: Avoid performance problems caused by MCMS Publishing API

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?

Wednesday, August 22, 2007 1:46 AM by Stefan_Gossner

# re: Avoid performance problems caused by MCMS Publishing API

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.

Wednesday, August 22, 2007 5:11 AM by Nicholas del Rosario

# re: Avoid performance problems caused by MCMS Publishing API

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

Wednesday, August 22, 2007 12:30 PM by Stefan_Gossner

# re: Avoid performance problems caused by MCMS Publishing API

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.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker