使用WCF服务流式传输300 MB文件时,CPU使用率高达75% [英] CPU usage goes upto 75% while stream a 300 MB file using WCF service

查看:77
本文介绍了使用WCF服务流式传输300 MB文件时,CPU使用率高达75%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有用于下载文件的wcf服务.它的工作正常(最后),但我可以看到下载后的CPU使用率约为75%.

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%.

请告知

客户代码

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();

推荐答案

在这一行:

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

您要获取无限制的数据,将其即时压缩吗?如果是这样,那可能是您的问题.压缩数据可能会占用大量CPU.作为诊断性测试,请尝试仅将原始数据发送到Bowser,然后查看CPU使用率是否下降.如果您正在快速压缩并发送未压缩的数据会减少CPU负载,那么您有2个现实的选择.

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. 确保您具有足够的服务器基础结构来做到这一点.

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

使文件脱机,以便它们可以排队,这样多个人同时访问服务不会杀死服务器.然后,您可以将zip文件保存在临时文件夹中,并在处理完后将链接或类似内容通过电子邮件发送给用户.

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.

这篇关于使用WCF服务流式传输300 MB文件时,CPU使用率高达75%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆