前篇文章介紹完如何用protobuf-net取代WCF原本的XML及NMF序列化,來看看它在資料減量上的表現。

NetTcpBinding

首先登場的是NetTcpBinding改用protobuf-net後的封包分析,黃底部分為WCF Server回傳結果的封包:

資紏統計如下(第二欄來自先前測試NetTcpBinding的數據,第三欄為NetTcpBinding改用protobuf-net後的結果)

64-256筆結果時,資料量減少約28%。

BasicHttpBinding(啟用IIS動態壓縮)

資紏統計如下(第二欄來自先前測試BasicHttpBinding的數據,第三欄為BasicHttpBinding加protobuf-net,IIS啟用「動態內容壓縮」)

資料筆數增加時,protobuf-net的表現愈好,256筆時可減少約65%的資料量。但我注意到一點,128跟256筆時,BasicHttpBinding+protobuf-net的資料量比NetTcpBinding+protobuf-net還低(1469<1959、2423<4047)。探究原因,我們案例的測試資料且規則性,下圖為NetTcpBinding+protobuf-net的封包內容,其中可見大量Item0、Item1… 字串內容,類似重複資料也會出現在BasicHttpBinding+protobuf-net,由於IIS啟用動態壓縮,當內容重複性愈高,壓縮比愈高,是BasicHttpBinding+protobuf-net勝出的原因,若資料重複性低,資料量將會上升。

BasicHttpBinding(不壓縮)

資紏統計如下(第二欄來自先前測試BasicHttpBinding的數據,第三欄為BasicHttpBinding加protobuf-net,IIS關閉「動態內容壓縮」)

128-256筆時,改用protobuf-net資料量可減少約74%。

結論

針對BasicHttpBinding或NetTcpBinding,改用protobuf-net序列化可減少65%到28%的資料量。


Comments

Be the first to post a comment

Post a comment