tags:

views:

60

answers:

1

Hi,

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  A: 

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.

Ben Robinson
Ben, thanks for the reply. I can confirm i am not doing any compression on the fly. All i m doing is reading a zip file of around 300MB from the disk and downloading it from client
Amit