ASP.NET(MVC)的OutputCache和并发请求 [英] ASP.NET (MVC) Outputcache and concurrent requests

查看:250
本文介绍了ASP.NET(MVC)的OutputCache和并发请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说,theoratically,我在我的网站中的网页/控制器的行动,做一些很沉重的东西。这大约需要10秒钟才能完成它的操作。

Let's say that, theoratically, I have a page / controller action in my website that does some very heavy stuff. It takes about 10 seconds to complete it's operation.

现在,我使用.NET的的OutputCache机制缓存它15分钟(对于〔实施例中,我使用 [的OutputCache(持续时间= 900)] )会发生什么,如果后15分钟后,缓存过期,100个用户这10秒它需要做繁重的处理过程中再次请求页面?

Now, I use .NET's outputcache mechanism to cache it for 15 minutes (for examle, I use [OutputCache(Duration = 900)]) What happens if, after 15 minutes, the cache is expired and 100 users request the page again within those 10 seconds that it takes to do the heavy processing?


  1. 重的东西做只有第一次,且有一定的锁定机制,使其他99用户将获得缓存结果

  2. 重的东西是做100次(与服务器是残缺的,因为它可能需要多达100 * 10秒)

易问题也许吧,但我不是100%肯定。我希望这是第一位的,虽然: - )

Easy question maybe, but I'm not 100% sure. I hope it is number one, though :-)

谢谢!

推荐答案

嗯,这取决于你如何配置了IIS。如果您有少于100个工作线程(比方说,50),那么重的东西做50次,削弱你的服务器,然后将剩余50将请求从缓存中提供服务。

Well, it depends upon how you have IIS configured. If you have less than 100 worker threads (let's say, 50), then the "heavy stuff" is done 50 times, crippling your server, and then the remaining 50 requests will be served from cache.

但是,没有,没有对缓存的作用的结果没有锁机制;这将适得其反,在大多数情况下。

But no, there is no "locking mechanism" on a cached action result; that would be counterproductive, for the most part.

修改:我相信这是真实的,但尼克的测试中说,否则,我没有时间,现在来测试。你自己试试吧!答案的其余部分是不依赖于上面,虽然,我认为这是更重要的。

Edit: I believe this to be true, but Nick's tests say otherwise, and I don't have time to test now. Try it yourself! The rest of the answer is not dependent on the above, though, and I think it's more important.

一般而言,但是,没有网络请求,高速缓存或其他方式,应该需要10秒返回。如果我是你的话,我想看看在某种程度上pre计算请求的努力的一部分。您仍然可以缓存作用的结果,如果你希望缓存的HTML,但它听起来像你的问题比稍大。

Generally speaking, however, no web request, cached or otherwise, should take 10 seconds to return. If I were in your shoes, I would look at somehow pre-computing the hard part of the request. You can still cache the action result if you want to cache the HTML, but it sounds like your problem is somewhat bigger than that.

您的可能的也想<一个href=\"http://blog.stevensanderson.com/2010/01/25/measuring-the-performance-of-asynchronous-controllers/\"相对=nofollow>考虑异步控制器的。最后,需要注意的是,虽然IIS和AS​​P.NET MVC将无法在这个沉重的计算锁,你可以。如果您使用异步控制器上的计算锁相结合,那么你会得到有效你要求的行为。我真的不能说,如果这是最好的解决方案,而更多地了解你做什么。

You might also want to consider asynchronous controllers. Finally, note that although IIS and ASP.NET MVC will not lock on this heavy computation, you could. If you use asynchronous controllers combined with a lock on the computation, then you would get effectively the behavior you're asking for. I can't really say if that's the best solution without knowing more about what your doing.

这篇关于ASP.NET(MVC)的OutputCache和并发请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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