ASP.Net 应用程序有内存限制吗?

发布于 2024-07-13 12:23:50 字数 335 浏览 6 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

李不 2024-07-20 12:23:50

可以在 web.config 或 machine.config 或两者中配置内存限制。

在 web.config 中,该部分为:

<httpRuntime 
executionTimeout="3600" 
maxRequestLength="102400"
/>

在 machine.config 中,该部分也可以是 httpRunTime 部分,类似于:

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

使用 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:

<httpRuntime 
executionTimeout="3600" 
maxRequestLength="102400"
/>

In machine.config the section can also be the httpRunTime section, similar to:

<httpRuntime 
executionTimeout="90" 
maxRequestLength="4096"
useFullyQualifiedRedirectUrl="false" 
minFreeThreads="8" 
minLocalRequestFreeThreads="4"
appRequestQueueLimit="100"
/>

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.

晚雾 2024-07-20 12:23:50

上传大小确实没有硬性限制。 但是,如果您使用的是 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!

昔日梦未散 2024-07-20 12:23:50

来自 MSDN

防止拒绝服务攻击的一种方法是使用 FileUpload 控件限制可以上传的文件的大小。 您应该设置适合您希望上传的文件类型的大小限制。 默认大小限制为 4096 KB(KB)或 4 MB(MB)。 您可以通过设置 httpRuntime 元素的 maxRequestLength 属性来允许上传更大的文件。 要增加整个应用程序允许的最大文件大小,请在 Web.config 文件中设置 maxRequestLength 属性。 要增加指定页面允许的最大文件大小,请在 Web.config 中的 location 元素内设置 maxRequestLength 属性。 有关示例,请参阅位置元素(ASP.NET 设置架构)。

上传大文件时,用户可能还会收到以下错误消息:

aspnet_wp.exe(PID:1520)被回收,因为内存消耗超过 460 MB(可用 RAM 的 60%)。

如果您的用户遇到此错误消息,请增加应用程序 Web.config 文件的 processModel 元素中的 memoryLimit 属性的值。 memoryLimit 属性指定工作进程可以使用的最大内存量。 如果工作进程超过了 MemoryLimit 量,则会创建一个新进程来替换它,并将当前所有请求重新分配给新进程。

From MSDN:

One way to guard against denial of service attacks is to limit the size of the files that can be uploaded by using the FileUpload control. You should set a size limit that is appropriate for the types of files that you expect to be uploaded. The default size limit is 4096 kilobytes (KB), or 4 megabytes (MB). You can allow larger files to be uploaded by setting the maxRequestLength attribute of the httpRuntime element. To increase the maximum allowable file size for the entire application, set the maxRequestLength attribute in the Web.config file. To increase the maximum allowable file size for a specified page, set the maxRequestLength attribute inside the location element in Web.config. For an example, see location Element (ASP.NET Settings Schema).

When uploading large files, a user might also receive the following error message:

aspnet_wp.exe (PID: 1520) was recycled because memory consumption exceeded 460 MB (60 percent of available RAM).

If your users encounter this error message, increase the value of the memoryLimit attribute in the processModel element of the Web.config file for the application. The memoryLimit attribute specifies the maximum amount of memory that a worker process can use. If the worker process exceeds the memoryLimit amount, a new process is created to replace it, and all current requests are reassigned to the new process.

⒈起吃苦の倖褔 2024-07-20 12:23:50

异常究竟源自哪里?

据我所知,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?

谁对谁错谁最难过 2024-07-20 12:23:50

您需要确保将数据从输入流传输到某种形式的文件流中,以便内存中不需要整个请求实体。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文