對於在webservice上必須(無法避免的情況下)要傳輸大量資料的dataset時,對dataset壓縮是最好的方法,這樣可以減少大量在網路傳輸過程中所占用的時間。
下面對我掌握的的dataset壓縮方法做乙個測試,希望高人有斧正之處,也希望需要的人有借鑑之處。
注:經過壓縮dataset的webservice就缺少了通用性,請權衡使用之。
測試原始碼(僅壓縮部分)和結果如下:
條件:壓縮前的dataset的大小為16891323位元組(大約16.12m)。
環境:.net formatwork 1.1
系統: windows xp sp1
硬體:p4(2.4g) + 256ddr
方案1:datasetsurrogate + binaryformatter
public function datasettobyte(byval dataset as dataset) as byte()
dim dss as new datasetsurrogate(dataset)
dim ms as new io.memorystream
dim bf as new binaryformatter
bf.serialize(ms, dss)
dim reval() as byte = ms.toarray()
ms.close()
dss = nothing
ms = nothing
bf = nothing
return reval
end function
方案2:datasetsurrogate + binaryformatter + sharpziplib
public function datasettobyte(byval dataset as dataset) as byte()
dim ms as new io.memorystream
dim zos as new zipoutputstream(ms)
zos.putnextentry(new zipentry(dataset.datasetname))
dim bf as new binaryformatter
dim dss as datasetsurrogate = new datasetsurrogate(dataset)
bf.serialize(zos, dss)
zos.closeentry()
zos.close()
dim reval as byte() = ms.toarray
ms.close()
ms = nothing
zos = nothing
bf = nothing
dss = nothing
return reval
end function
方案3:zlib
public function datasettobyte(byval dataset as dataset) as byte()
dim ms as new system.io.memorystream
dataset.writexml(ms, xmlwritemode.writeschema)
dim reval() as byte = ms.toarray
ms.close()
ms = nothing
dim zlib as new vbzlib.compress
zlib.compressbyte(reval)
zlib = nothing
return reval
end function
結果(壓縮後):
方案1:4420881位元組(被壓縮掉大約73.83%),耗時:23200ms
方案2: 696881位元組(被壓縮掉大約95.87%),耗時:26621ms
方案3: 422990位元組(被壓縮掉大約97.50%),耗時: 680ms
看來,無論壓縮率還是耗時都是方案3最優,但是使用了第三方元件。前兩個方案對cpu資源佔用率的也讓人無法接受。
WCF傳輸Dataset大資料量 壓縮
由於wcf不能傳輸datatable 不能序列化 所以更多專案中都會使用dataset作為查詢集合的首選返回型別,但是由於dataset會生成很多的狀態資訊等,所以dataset體積也會變大,有幾種改變dataset大小的方法。1 將dataset的remotingformat屬性設定為binary...
大資料量演算法
給40億個不重複的unsigned int的整數,沒排過序的,然後再給乙個數,如何快速判斷這個數是否在那40億個數當中 位圖思想解法 include stdio.h include stdlib.h include memory.h define max num 4294967295 int mai...
大資料量處理
看看這個,異曲同工,永遠不超時 該程式是針對非常龐大的資料庫開發的,沒有用迴圈 用途 對過萬條資料的資料庫字段內容批量替換 資料庫連線 dim beeyee dbname,connstr,conn,intsn1 dim content,num,intsn,intidno,strcodea,strco...