<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Pearl Tech &#187; VirtualStream</title>
	<atom:link href="http://blog.pearltechnology.com/tag/virtualstream/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.pearltechnology.com</link>
	<description></description>
	<lastBuildDate>Tue, 25 May 2010 14:37:15 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>BizTalk Pipeline Out Of Memory</title>
		<link>http://blog.pearltechnology.com/biztalk-pipeline-out-of-memory/#utm_source=feed&amp;utm_medium=feed&amp;utm_campaign=feed</link>
		<comments>http://blog.pearltechnology.com/biztalk-pipeline-out-of-memory/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 17:52:57 +0000</pubDate>
		<dc:creator>AaronH</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[BizTalk]]></category>
		<category><![CDATA[Pipeline Components]]></category>
		<category><![CDATA[VirtualStream]]></category>

		<guid isPermaLink="false">http://blog.pearltechnology.com/?p=256</guid>
		<description><![CDATA[I&#8217;ve developed many custom components for BizTalk in the past several years, but I have never had to work with very large input files (&#62;100MB), primarily I&#8217;ve simply created output files. In a recent need to gather several years worth of historical data, it became apparent that memory constraints were going to be pushed to [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve developed many custom components for BizTalk in the past several years, but I have never had to work with very large input files (&gt;100MB), primarily I&#8217;ve simply created output files. In a recent need to gather several years worth of historical data, it became apparent that memory constraints were going to be pushed to their peak. After battling the frequent &#8220;System.OutOfMemoryException&#8221; it was time to hunt for the solution.</p>
<p>The <a href="http://social.msdn.microsoft.com/Forums/en-US/biztalkgeneral/thread/8248a5be-3c8c-471f-b2e0-d1872689fee4">resolution</a> to the BizTalk memory problem relied in the source structure (<a href="http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx">MemoryStream</a>) we were using for storing our stream for the <a href="http://msdn.microsoft.com/en-us/library/microsoft.biztalk.message.interop.ibasemessage_members(BTS.10).aspx">IBaseMessage</a>.</p>
<pre name="code" language="csharp">MemoryStream revisedStream = new MemoryStream();</pre>
<p>The discussion helpfully points out that we should be using the <a href="http://technet.microsoft.com/en-us/library/microsoft.biztalk.streaming.virtualstream(BTS.10).aspx">VirtualStream</a> with a few <a href="http://blogs.neudesic.com/blogs/enterprise_integration/archive/2006/12/27/1366.aspx">caveats</a>. The trick to get the VirtualStream object is to include the source from the BizTalk server samples (<em>&lt;BizTalk Install Path&gt;\SDK\Samples\Pipelines\SchemaResolverComponent\SchemaResolverFlatFileDasm</em>) or use the <em>Microsoft.BizTalk.Streaming.dll</em> as it exists in the GAC (<em>&lt;Windows Path&gt;\assembly\GAC_MSIL\Microsoft.BizTalk.Streaming\3.0.1.0__31bf3856ad364e35\</em>). I chose the later approach, which required adding a reference to<em> Microsoft.BizTalk.Streaming.dll</em> to my custom pipeline solution. I first copied the assembly from the <a href="http://bloggingabout.net/blogs/wellink/archive/2006/07/12/12947.aspx">GAC</a> to the &lt;biztalk install path&gt; for future solutions where I may need to reuse the same assembly source. After adding the reference via Visual Studio, it was simply a matter of changing the MemoryStream reference to VirtualStream.</p>
<pre name="code" language="csharp">VirtualStream revisedStream = new VirtualStream();</pre>
<p>Be sure you rewind the stream before assigning the bodyparts data.</p>
<pre name="code" language="csharp">// Rewind the stream so it is ready for use by the messaging engine
revisedStream.Seek(0, SeekOrigin.Begin);</pre>
<p>So why does this solution work? Behind the scenes, VirtualStream is wrapping excessive data (<em>user defined, but defaults to &gt;4MB</em>) to temporary disk using a <a href="http://msdn.microsoft.com/en-us/library/system.io.bufferedstream.aspx">BufferedStream</a>. This is why we can avoid the &#8220;System.OutOfMemoryException&#8221; &#8211; since the VirtualStream will offload the large data stream to disk I/O instead of purely storing our IBaseMessage in RAM (<em>via MemoryStream</em>). Yes, there&#8217;s certainly overhead depending on where your temporary directory resides, but in most cases this will be the solution you&#8217;re looking for. MSDN docs has other <a href="http://msdn.microsoft.com/en-us/library/ee377071(BTS.10).aspx">BizTalk specific streams</a> if you want to dive deeper.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.pearltechnology.com/biztalk-pipeline-out-of-memory/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
