In Silverlight forum saw a sticker that would be useful if you were to improve WCF performance. Obviously, there seems to be nothing more to concern about distributed applications than to improve the responsiveness of clients. Then I looked up the relevant information and did some exercises. Of course, I also saw the PDF of Tripoli about improving Web service performance.
1.datasetsurrogate acceleration WebService: About DataSetSurrogate I checked MSDN to show the namespace Microsoft.Synchronization.Data this class, but. Net The framework 3.5sp1 this namespace does not already have this class. MS in. NET 1.1 out of this datasetsurrogate class, seems to have been abandoned. However, the MS site can still download the DataSetSurrogate code, You need to compile the build DLL yourself.
2. When using Web service, it is often customary to return a dataset. However, there is a Remotingformat property for the dataset that can be set to Serializationformat.xml and serializationformat.binary the difference between the 2 is the depth of the serialization, and my understanding is that XML format morning redundancy, binary format transmission efficiency, but will make the volume of data larger, which affects performance, but converted to binary can encrypt the data transmission. Therefore, it is very important to use the transmission advantages of binary itself. Here are the test results
Read 2w data from the database when this test is not named, and take the following measures:
Getcompressbytes: Read data to DataSet, with binary serialization, using gzip compression, return
Getdatasetbytes: Reads data to DataSet, serializes in binary (not setting Remotingformat property value), returns
Getdatasetbytes: Reading data to DataSet, returning
From the above, it seems that the result is not what it says, my explanation is because the test time is from the call getcompressbytes start to the end, the middle time includes binary serialization, as well as the process of compression, and I am concerned only with the process of transmission, compression should be said to be a time-consuming process.
3.SharpZipLib
Gzip compression is a compression algorithm under the. Net System.IO namespace. But I'm more concerned about SharpZipLib's open source compression framework, which supports ZIP,GZIP,TAR,BZIP2. Needless to say below look at SharpZipLib and gzip compression rates and the duration of the process:
Getcompressbytes:compress legth:751893,time:00:00:02:1001201 (. NET self-with gzip) compression rate 22%
sharpziplib:compressbytes:583020 uncompress bytes:3339243 time:00:00:00:6660381 (using the highest compression rate) 17%
Obviously the size of the 2w data in the same dataset translates to binary format, the compression rate gap is not too large, but the transmission time is almost 3 times times. Obviously the above results only for text types, the PDF file compression is not obvious, for the Rar,zip file can hardly be compressed, because no matter which compression method in the final knot is based on Huffman algorithm. (This is not very strict, of course.) Here are a few pieces of code
[WebMethod Description = 3. Use a binary sequence with the DataSet object, and then return with compress (IIS with compression)
Public byte[] Getcompres Sbytes ()
{
DataSet ds = Gettestdata ();
byte[] buffer = Gettestdata (fileName);
/*----*/
BinaryFormatter fmater = new BinaryFormatter ();
MemoryStream ms = new MemoryStream ();
Fmater. Serialize (MS, DS);
/*----*/
byte[] buffer = Ms. ToArray ();
return dataformatter.getbinaryformatdatacompress (buffer);
}
public static byte[] Getbinaryformatdatacompress (byte[] binarydataresult)
{
Return COMPR ESS (Binarydataresult);
}
///<summary>
///compressed data
///</summary>
///<param name= "Data" ></ Param>
///<returns></returns>
public static byte[] Compress (byte[] data)
{
Byte[] bdata;
MemorystreaM ms = new MemoryStream ();
GZipStream stream = new GZipStream (MS, Compressionmode.compress, true);
Stream. Write (data, 0, data. Length);
Stream. Close ();
Stream. Dispose ();
//The stream stream must be closed to return MS Stream data, otherwise the data will be incomplete
//and the method stream should be decompressed. Read (buffer, 0, buffer.) Length) returns 0
Bdata = Ms. ToArray ();
Ms. Close ();
Ms. Dispose ();
return bdata;
}