CPU usage goes upto 75% while stream a 300 MB file using WCF service

允我心安 提交于 2020-01-25 10:00:22

问题


I have a wcf service that is used to download files. Its working alright (finally), but i can see that when it downloads the CPU usage goes around 75%.

Please advise

Client Code

FileTransferServiceClient obj = new FileTransferServiceClient();
Byte[] buffer = new Byte[16 * 1024];
CoverScanZipRequest req = new CoverScanZipRequest(
    new string[] { "1", "2" });

CoverScanZipResponse res = new CoverScanZipResponse();
res = obj.CoverScanZip(req);

int byteRead = res.CoverScanZipResult.Read(buffer, 0, buffer.Length);
Response.Buffer = false;
Response.ContentType = "application/zip";
Response.AddHeader("Content-disposition", 
    "attachment; filename=CoverScans.zip");

Stream outStream = Response.OutputStream;
while (byteRead > 0)
{
    outStream.Write(buffer, 0, byteRead);
    byteRead = res.CoverScanZipResult.Read(buffer, 0, buffer.Length);
}
res.CoverScanZipResult.Close();
outStream.Close();

回答1:


In this line:

byteRead = res.CoverScanZipResult.Read(buffer, 0, buffer.Length);

Are you taking uncomressed data, zipping it on the fly. If so that is likely your problem. Compressing data can be quite CPU intensive. As a disagnostic test, try simply sending the raw data to the bowser and see if the CPU useage goes down. If you are zipping on the fly and sending the data uncompressed reduces the CPU load you have 2 realistic options.

  1. Make sure you have enough server infrastructure to do this.

  2. Zip your files off line so they can be queued that way multiple people accessing the service at the same time will not kill the server. You can then save the zip file in a temp folder and email the user a link or similar when it has been processed.



来源:https://stackoverflow.com/questions/3608133/cpu-usage-goes-upto-75-while-stream-a-300-mb-file-using-wcf-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!