使 ASP.NET MVC 应用程序为 Web Farm 做好准备

发布于 2024-09-13 22:46:38 字数 158 浏览 8 评论 0原文

使 ASP.NET MVC 应用程序 Web 场做好准备的最有效方法是什么。

最重要的是共享当前用户的信息(上下文)和(不太重要)缓存的对象,例如查找项目(州、街道类型、县等)。

我听说过/读过 MemCache,但还没有看到关于如何实现和测试它的简单适用方法(文档)。

What will be the most efficient way to make an ASP.NET MVC application web-farm ready.

Most importantly sharing the current user's information (Context) and (not so important) cached objects such as look-up items (States, Street Types, counties etc.).

I have heard of/read MemCache but haven't seen a simple applicable way (documentation) on how to implement and test it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

赠佳期 2024-09-20 22:46:38

请求上下文
任何到达网络场的请求都会由可用的 IIS 服务器提供服务。上下文在那里创建,整个请求由同一服务器提供服务。所以上下文应该不是问题。请求是无状态执行管道,因此它不需要以任何方式与其他服务器共享数据。它将由同一台机器从头到尾提供服务。
用户信息从 cookie 中读取并由服务该请求的服务器进行处理。这取决于您是否将完整的用户对象缓存在某处。

会议
如果您使用 TempData 字典,您应该知道它存储在 Session 字典中。在服务器场中,这意味着您应该使用 InProc 会话以外的其他方式,因为它们不在场中的 IIS 服务器之间共享。您应该配置使用数据库或其他(状态服务器等)的其他会话管理器。

缓存
当谈到缓存时,情况就不同了。为了使其尽可能高效,还应该提供缓存服务。默认情况下不是。但看看缓存,它几乎意味着当没有缓存时,应该读取它并将其存储在缓存中。因此,如果特定服务器场服务器没有某些缓存对象,它将创建它。随着时间的推移,它们都会缓存一些共享的公开使用的数据。
或者...您可以使用像 memcached 这样的库(正如您提到的)并利用共享缓存。网上有几个如何使用它的示例。

但是,如果没有其他问题,这些解决方案都会带来一些额外的开销(例如网络和第三进程处理以及数据获取等)。因此,默认缓存是最快的,如果您明确需要共享缓存,请决定使用一个。除非确实必要,否则不要共享缓存。

Request context
Any request that hits a web farm gets served by an available IIS server. Context gets created there and the whole request gets served by the same server. So context shouldn't be a problem. A request is a stateless execution pipeline so it doesn't need to share data with other servers in any way shape or form. It will be served from the beginning to the end by the same machine.
User information is read from a cookie and processed by the server that serves the request. It depends then if you cache complete user object somewhere.

Session
If you use TempData dictionary you should be aware that it's stored inside Session dictionary. In a server farm that means you should use other means than InProc sessions, because they're not shared between IIS servers across the farm. You should configure other session managers that either use a DB or others (State server etc.).

Cache
When it comes to cache it's a different story. To make it as efficient as possible cache should as well be served. By default it's not. But looking at cache it barely means that when there's no cache it should be read and stored in cache. So if a particular server farm server doesn't have some cache object it would create it. In time all of them would cache some shared publicly used data.
Or... You could use libraries like memcached (as you mentioned it) and take advantage of shared cache. There are several examples on the net how to use it.

But these solutions all bring additional overhead of several things (like network and third process processing and data fetching etc.) if nothing else. So default cache is the fastest and if you explicitly need shared cache then decide for one. Don't share cache unless really necessary.

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