开发者

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

I have a wcf service that is used to download开发者_如何学JAVA 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();


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜