Improving DataSet Serialization and Remoting Performance

转载 2006年05月21日 15:26:00


When you pass a System.Data.DataSet object between processes, .NET Framework Remoting is used to serialize, to transport, and to deserialize the DataSet class. If you pass a DataSet class back from a .NET Web Service, internally the Microsoft .NET Framework System.Xml.Serialization.XMLSerializer class is used to serialize the DataSet data back to the client. If you pass a DataSet back from a managed object that is hosted in COM+, the BinaryFormatter class is used by .NET Framework Remoting. Regardless of the remoting mechanism that is used by the .NET Framework, the DataSet class always converts the internal data to XML when serializing the data.

The DataSet class that is included with the Microsoft .NET Framework 1.0 and with the .NET Framework 1.1 works efficiently for serializing small amounts of data (hundreds of rows) in the DataSet over .NET Framework Remoting. The serialization mechanism is inefficient with a larger DataSet (thousands of rows) and incurs large transient (short lived) memory allocations. These memory allocations reduce application scalability.

Note A transient memory allocation is a short-lived memory allocation that occurs during the processing of some sections of code. Therefore, during the serialization, during the remoting, and during the deserialization of a DataSet class, various managed objects are allocated and deallocated internally by .NET Framework Remoting to process the remoting request. Allocating and deallocating larger and larger managed objects puts additional pressure on the .NET memory management system and reduces overall scalability. For example, an application that has many in-flight method invocations that generate large transient memory allocations can run out of memory before completing all the method calls.

You can greatly improve serialization and remoting performance for larger DataSets by using a correctly designed surrogate type or serialization wrapper classes. For more information about using a surrogate mechanism or a wrapper mechanism (or both) with the .NET Framework DataSet class, visit the following Microsoft Developer Network (MSDN) Web site: (
However, this article does not provide a complete sample of how to implement a DataSet surrogate type or a serialization wrapper class.

This article contains a sample serialization wrapper class that is optimized to more efficiently serialize and deserialize larger DataSets. The class significantly reduces transient memory allocations versus remoting a typical DataSet. Large reductions in the transient memory allocations also improve remoting end-to-end time and improve scalability when using a larger DataSet.

The sample provides a serialization wrapper class that is named DataSetSurrogate. The DataSetSurrogate class is used as a wrapper class for any DataSet that you want to remote. The server component passes the DataSet that you want to the DataSetSurrogate constructor and then passes the DataSetSurrogate class back to the client. On the client side, the DataSetSurrogate.ConvertToDataSet method is used to extract the DataSet from the DataSetSurrogate class.

The DataSetSurrogate class is marked Serializable and all the fields in the DataSetSurrogate class are also serializable classes. Therefore, when you remote the DataSetSurrogate object, the remoting infrastructure automatically serializes and deserializes the DataSetSurrogate object and all its fields. The key serialization advantage of the DataSetSurrogate class over the DataSet class is that the DataSetSurrogate class serializes the data in a binary format. Serializing by using a binary format is much more efficient both in memory and CPU than the existing DataSet XML serialization format.

Note To maximize the performance benefit of this serialization wrapper class, use the .NET Framework System.Runtime.Serialization.Formatters.Binary.BinaryFormatter class when remoting. Remoting by using the .NET Framework System.Runtime.Serialization.Formatters.Soap.SoapFormatter class is not as efficient when you use the DataSetSurrogate class.

The following file is available for download from the Microsoft Download Center:
DownloadDownload the SurrogateSample.exe package now. ( For additional information about how to download Microsoft Support files, click the following article number to view the article in the Microsoft Knowledge Base:
119591 ( How to Obtain Microsoft Support Files from Online Services
Microsoft scanned this file for viruses. Microsoft used the most current virus-detection software that was available on the date that the file was posted. The file is stored on security-enhanced servers that help to prevent any unauthorized changes to the file.

Access the Sample Files

Save the SurrogateSample.exe file to drive C on your computer. From there you can extract the folder structure. There is a readme file in each folder that contains additional instructions.

Likes Dislike Improving Performance in C++ with Compile Time Polymorphism


7 Tips for Improving MapReduce Performance

One service that Cloudera provides for our customers is help with tuning and optimizing MapReduce jo...

使用分区(Partitioning)提高Spark的运行性能——Improving Spark Performance With Partitioning

使用分区(Partitioning)提高Spark的运行性能——Improving Spark Performance With Partitioning 本文的译文请移步至https://www....

Improving Snort performance with Barnyard

zz from: ...

Improving the Lightning Performance

  • 2011年07月21日 21:17
  • 2.69MB
  • 下载

论文读书笔记-improving word representations via global context and multiple word prototypes

这篇论文提出了一种获取词向量的方法,该方法不仅考虑词的局部段落(local context)信息,也考虑了全局文本(global context)信息,这样得到的词向量不仅能表示语义信息,也能表示句法...
您举报文章: Improving DataSet Serialization and Remoting Performance