简体   繁体   English

ASP.NET图像处理性能瓶颈

[英]ASP.NET image processing performance bottleneck

I am developing web service on ASP.NET. 我正在ASP.NET上开发Web服务。 One of key features is uploading some photos (max - 18) to server and after that this photos are being processed. 主要功能之一是将一些照片(最多18张)上传到服务器,然后再处理这些照片。 I have performance bottleneck with image resizing. 我在调整图像大小时遇到​​性能瓶颈。 When i am uploading maximum count of photos to server then CPU usage approaches 100%, therefore all pages on server not responding until image processing not finished. 当我将最大数量的照片上传到服务器时,CPU使用率接近100%,因此服务器上的所有页面都没有响应,直到图像处理未完成。 I am use MS Azure (App plan - S2) to host my service. 我正在使用MS Azure(应用计划-S2)托管我的服务。

So, how to organize image resizing to prevent full CPU load? 那么,如何组织图像调整大小以防止CPU满负荷运行?

You can resize images on client side with JS. 您可以使用JS在客户端调整图像大小。 This is a good example: Resizing an image in an HTML5 canvas 这是一个很好的例子: 调整HTML5画布中图像的大小

I would definitely recommend that you host upload handler on a separate app pool. 绝对建议您在单独的应用程序池中托管上传处理程序。 You can create a staging slot for your Azure S2 hosting plan and handle uploading there. 您可以为您的Azure S2托管计划创建一个临时插槽,并在那里处理上载。 You should of course need to set the upload handler to your new host. 您当然应该将上传处理程序设置为新主机。 This way your upload process will not consume your web apps resources. 这样,您的上传过程将不会消耗您的Web应用程序资源。

High traffic (uploads) will cause Out of Memory exceptions regarding your upload size and available memory on the server. 高流量(上传)将导致有关上传大小和服务器上可用内存Out of Memory异常。 Remember that the compressed image files allocates much more memory than the file itself (more than 10x sometimes) when you reference them in your app. 请记住,在应用程序中引用压缩图像文件时,它们比文件本身分配的内存要多得多(有时超过10倍 )。 If you foresee that you'll face high volumes of traffic, you should upload files directly to a blob storage like Azure Blob Storage (or Amazon S3 etc.) from client browser. 如果您预计将面临大量流量,则应该从客户端浏览器直接将文件上传到Azure Blob存储(或Amazon S3等)之类的Blob存储。 This way you won't need to worry about the allocated memory of ongoing uploads. 这样,您就不必担心正在进行的上传所分配的内存。 After upload complete you need to call another endpoint that process the images as you need. 上传完成后,您需要调用另一个根据需要处理图像的终结点。

Amazons Sample: link 亚马逊样品: 链接

在此处输入图片说明

There are also some advanced topics about this issue. 关于此问题,还有一些高级主题。 Check here and here 在这里这里检查

You can also use well proven tools for your serverside image processing. 您还可以使用久经考验的工具来进行服务器端图像处理。 These can perform up to 40x faster than .NET's builtin GDI+. 它们的性能比.NET的内置GDI +快40倍。 Check ImageResizer . 检查ImageResizer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM