且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

做一个ASP.NET MVC应用程序的Web农场就绪

更新时间:2023-02-25 18:31:21

请求上下文结果
击中Web场的任何请求被通过一个可用的IIS服务器提供服务。上下文被创建并有全请求被由同一个服务器提供服务。所以上下文不应该是一个问题。请求是无国籍执行管线,因此不需要以任何方式或形式的其他服务器共享数据。它会从一开始就由同一台机器最终送达。结果
用户信息从一个cookie读取和服务于该请求的服务器处理。这要看那么如果你的地方缓存完整的用户对象。

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.

会议结果
如果你使用的TempData ​​ code>字典你应该知道,它的内部存储会话字典。在服务器场,这意味着你应该使用其他手段,而不是是InProc会话,因为他们不能跨越农场IIS服务器之间共享。您应该配置其他会话管理器,要么使用DB或他人(国家服务器等)。

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.).

缓存结果
当涉及到缓存这是一个不同的故事。为了使它尽可能高效的高速缓存应该也送达。默认情况下它不是。但看缓存它几乎意味着当没有缓存应该读取并存储在缓存中。所以,如果一个特定的服务器场服务器没有一些缓存对象,将创建它。随着时间的推移他们都将缓存一些共享公共使用的数据。结果
或...你可以使用库例如的memcached (正如你所提到它),利用共享缓存。上有净如何使用它的几个例子。

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.