简体   繁体   English

大图像上的ImageResizer内存不足异常

[英]ImageResizer Out of Memory Exception on large image

I have inherited a site which is plagued with oversized and uncompressed images so I am automating the task of correcting it which is mostly working except for files over a certain size. 我继承了一个站点,该站点充满了过大且未压缩的图像,因此我正在自动执行纠正该任务的任务,除了一定大小的文件以外,该任务通常可以正常工作。 For instance, I have a JPG image which is 8176x6132 300dpi and 24 bit depth, the file size is 4.49mb. 例如,我有一个8176x6132 300dpi和24位深度的JPG图像,文件大小为4.49mb。

Here is my ImageJob 这是我的ImageJob

var instructions = new Instructions("width=1920;height=0;mode=max");
var resizedImg = new ImageJob(filePath, filePath, instructions).Build();

I have plenty of available resources on my machine yet get out of memory exceptions. 我的机器上有大量可用资源,但内存不足却无法使用。 As I test this right now I have 90% CPU free and 51% memory. 当我现在测试时,我有90%的CPU空闲和51%的内存。

My machine has: 我的机器有:

  • Intel® CoreTMi7 Quad Core Processor i7-4790 (3.6GHz) 8MB Cache 英特尔®酷睿TMi7四核处理器i7-4790(3.6GHz)8MB缓存
  • 16GB KINGSTON DUAL-DDR3 1600MHz 16GB金士顿DUAL-DDR3 1600MHz

Why would this fail? 为什么这会失败? As I run the ImageJob there is no increased usage of memory before it fails (as far as I can see). 当我运行ImageJob时,在内存出现故障之前(据我所知)并没有增加内存的使用。

I am using ImageResizer 3.4.3 with DiskCache plugin. 我正在将ImageResizer 3.4.3与DiskCache插件一起使用。

I should also note that I can open problem files in Photoshop, resize down to say 3000px along the long side, save and then run the same ImageJob which then completes without error. 我还要注意,我可以在Photoshop中打开问题文件,将其长边调整为3000px,保存然后运行相同的ImageJob,然后完成该操作而不会出现错误。

Diagnostics page output and exception stack trace 诊断页面输出和异常堆栈跟踪

First, run the process in 64-bit mode instead of 32. It will have a better chance at locating the required 150mb, 62mb, and 12mb blocks of contiguous memory that way. 首先,以64位模式而不是32位模式运行该进程。这样可以更好地找到所需的150mb,62mb和12mb连续内存块。 It's possible another 200mb might be required if you were triggering a fallback code path, or if the image was a CMYK jpeg (common) or had issues. 如果触发后备代码路径,或者图像是CMYK jpeg(常见)或有问题,则可能需要另外200mb。

Second, since you're not using the URL API, make sure that you've limited the number of concurrent images you want to process. 其次,由于您未使用URL API,因此请确保已限制要处理的并发图像的数量。 In ImageResizer v3, do them 1 or 2 at a time. 在ImageResizer v3中,一次执行1或2。

Third, upgrade to v4 and use the FastScaling plugin. 第三,升级到v4并使用FastScaling插件。 You'll get actual concurrency , and large blocks of RAM will be held for smaller amounts of time, meaning your throughput can easily go up 10x on files this large. 您将获得实际的并发性 ,并且将在较小的时间内保留较大的RAM块,这意味着您可以很轻松地将如此大的文件的吞吐量提高10倍。

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

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