ASP.Net 应用程序有内存限制吗?
我有一个 ASP.Net MVC 应用程序,允许用户上传图像。 当我尝试上传一个非常大的文件 (400MB) 时,出现错误。
我认为我的图像处理代码(自制)效率非常低,所以我决定尝试使用第三方库来处理图像处理部分。
因为我使用的是 TDD,所以我想首先编写一个失败的测试。 但是,当我使用相同的大文件测试控制器操作时,它能够毫无问题地完成所有图像处理。
我收到的错误是“内存不足”。
我确信我的代码使用的内存可能比需要的多得多,但我只想知道为什么我的测试通过。
另一个区别是我使用的是 SWFUpload,它没有在测试中使用。 这可能是原因吗?
I have an ASP.Net MVC application that allows users to upload images. When I try to upload a really large file (400MB) I get an error.
I assumed that my image processing code (home brew) was very inefficient, so I decided I would try using a third party library to handle the image processing parts.
Because I'm using TDD, I wanted to first write a test that fails. But when I test the controller action with the same large file it is able to do all the image processing without any trouble.
The error I get is "Out of memory".
I'm sure my code is probably using a lot more memory than it needs to but I just want to know why my test passes.
The other difference is that I'm using SWFUpload which is not used with the test. Could this be the cause?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
可以在 web.config 或 machine.config 或两者中配置内存限制。
在 web.config 中,该部分为:
在 machine.config 中,该部分也可以是 httpRunTime 部分,类似于:
使用 processModel 部分也可以将 aspnet 进程限制为总内存的百分比,请参阅:
http://msdn.microsoft.com/en-us/library/7w2sway1.aspx
我遇到过与您所描述的由这些设置引起的问题类似的问题。
特别是 ProcessModel 内存限制属性。
There can be memory limits configured in either the web.config or machine.config, or both.
In web.config the section is:
In machine.config the section can also be the httpRunTime section, similar to:
The aspnet process can also be limited to a percentage of the total memory using the processModel section, see:
http://msdn.microsoft.com/en-us/library/7w2sway1.aspx
I've encountered similiar problems to the one you described cause by those settings.
In particular the ProcessModel memorylimit attribute.
上传大小确实没有硬性限制。 但是,如果您使用的是 32 位进程,则可能会受到 ASP.NET 辅助进程可寻址的内存量的限制。 一旦达到800mb左右,它就变得非常不稳定。
Bravax 提到的超时设置也是一个值得检查的地方。
为使用 TDD 干杯!
There is really no hard-limit for upload sizes. However, if you're on a 32-bit process, you may be limited by the amount of memory your asp.net worker process can address. Once it gets around 800mb, it becomes very unstable.
The timeout settings mentioned by Bravax are also a good place to check.
Cheers on using TDD!
来自 MSDN:
From MSDN:
异常究竟源自哪里?
据我所知,ASP.net/.Net 中的图像大小没有 400MB 大小的限制。 我正在编写一个项目,其中一些文件要大得多。 当然,可能有一些我不知道的更高限制,但这看起来很奇怪和任意。
您在 64 位机器上运行吗? 您的图像文件 - 未压缩(jpg 格式为 400MB 吗?) - 可以测试进程地址空间的 2GB 限制吗?
Where exactly does the exception originate from?
AFAIK there's no 400MB-caliber limit to image sizes in ASP.net/.Net. I'm writing a project where some files are much larger. There might be some higher limit I'm not aware of, of course, but it would seem odd and arbitrary.
Are you running on a 64 bit machine? Could your image file - uncompressed (is it 400MB in jpg?) - test the the 2GB limit of your process's address space?
您需要确保将数据从输入流传输到某种形式的文件流中,以便内存中不需要整个请求实体。
You need to be sure to pipe data off the input stream into a filestream of some form so that the whole request entity isn't needed in memory.