Yossi Dahan [BizTalk]

Google
 

Monday, April 30, 2007

Loading custom pipeline component properties and performance

Needing to implement a pipeline component with properties slightly more complext than the odd simple type property I went back to Saravana Kumar's great whitepaper - Understanding Design-Time Properties for Custom Pipeline Components in BizTalk Server.

Before I go any further I should say I think this is a great whitepaper, as are most, is it's definitely worth reading.

I did, however, have one small reservation I thought is worth sharing -

Somewhere around page 21 Saravana shows how to save and load properties which are collections; in his example he uses Xml Serialisation and desrialisation to switch between the in-memory collection to the xml persistable form and back.

Here are the code snippets from the white paper -

public virtual void Load(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, int errlog)
{
object val = ReadPropertyBag(pb, "CorrelationPropertiesCollection");
if (val != null)
{
string corrPropertiesList = (string)val;

XmlTextReader xml = new XmlTextReader(new StringReader(corrPropertiesList));
XmlReaderSettings settings = new XmlReaderSettings();
settings.IgnoreProcessingInstructions = true;
XmlReader reader = XmlReader.Create(xml, settings);

XmlSerializer ser = new XmlSerializer(typeof(CorrelationPropertiesCollection));
CorrelationPropertiesCollection obj = (CorrelationPropertiesCollection)ser.Deserialize(reader);
CorrelationSettings = obj;
}
}


public virtual void Save(Microsoft.BizTalk.Component.Interop.IPropertyBag pb, bool fClearDirty, bool fSaveAllProperties)
{
StringBuilder sb = new StringBuilder();
StringWriter sw = new StringWriter(sb);

XmlWriterSettings setting = new XmlWriterSettings();
setting.OmitXmlDeclaration = true;
XmlWriter writer = XmlWriter.Create(sw, setting);

XmlSerializer ser = new XmlSerializer(typeof(CorrelationPropertiesCollection));
ser.Serialize(writer, CorrelationSettings);

object val = sb.ToString();
pb.Write("CorrelationPropertiesCollection", ref val);
}


The problem with this is that XmlSerialisation is quite an expensive operation, and, quite counter-intuitively (in my view), the Load method is being called in every execution of the component; so having this sort of logic in the load can really slow down the pipeline execution.

With all of that in mind, what I would say - if performance is not a critical issue, doing this is a great clean approach; if, on the other hand, low latency is important, serialisation should be avoided.

In our case we've decided to implement our own string parsing logic.
We didn't go as far as implementing ISerializable or anything like that, but simply added ToString and Parse methods to our collection that converted the collection to a delimited string and back. While this still involves some processing work on the load I suspect it is much quicker than serialisation

Labels: ,

3 Comments:

  • Saravana Kumar has written a reply to this post in his blog, which is well worth reading and so I'm adding the link here.

    I'll also take the opportunity to write a short reply to his important note -

    While I generally agree that in most scenarios using serialisation can be acceptable it is important, in my view, to understand the implications.

    It is true that the class generated to perform the serialisation, which, having to use reflection and be compiled, is the most expensive part of the process, is cached and re-used.

    However, the actual operation of reading the object and creating an xml (and vice versa) still has to be done each time.

    Xml is a verbose format, and as such is not the most efficient; if you only have a small object, and performance is crucial, I still think you should at least consider avoiding the use of classic serialisation.

    By Blogger Yossi Dahan, at 30/05/2007, 09:44  

  • The problem I have when try to use complex properties in pipeline component (such as a collection), is that when I use the BizTalk console to change the property value the Save method of the Property Bag isn't invoked and the following received message use the old settings.
    I've to change it in VisualStudio and redeploy in order to apply new values.

    By Anonymous Andrea Ramacciotti (aramacciotti@hotmail.com), at 26/05/2008, 15:03  

  • Unfortunately I am not able to test this at the moment, and I did not want to wait with the reply until next week - but is it not simply a case of needing to restart the relevant host to replace a cached version of the settings?

    By Blogger Yossi Dahan, at 26/05/2008, 18:13  

Post a Comment

<< Home