What will be the most efficient way to make an ASP.NET MVC application web-farm ready.
什么是使ASP.NET MVC应用程序Web场准备就绪的最有效方法。
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.
我听说过/读过MemCache但没有看到关于如何实现和测试它的简单适用方式(文档)。
1 个解决方案
#1
21
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.
请求上下文任何访问Web场的请求都由可用的IIS服务器提供服务。在那里创建上下文,整个请求由同一服务器提供服务。因此上下文不应成为问题。请求是无状态执行管道,因此它不需要以任何形式或形式与其他服务器共享数据。它将由同一台机器从头到尾提供。用户信息从cookie中读取并由提供请求的服务器处理。这取决于你是否在某处缓存完整的用户对象。
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.).
会话如果您使用TempData字典,您应该知道它存储在Session字典中。在服务器场中,这意味着您应使用InProc会话之外的其他方法,因为它们不在服务器场中的IIS服务器之间共享。您应该配置使用数据库或其他(状态服务器等)的其他会话管理器。
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.
缓存当谈到缓存时,它是一个不同的故事。为了使其尽可能高效,还应提供缓存。默认情况下不是。但是看一下缓存它几乎没有意味着当没有缓存时它应该被读取并存储在缓存中。因此,如果特定服务器场服务器没有某个缓存对象,则会创建它。所有这些都会缓存一些共享的公共使用数据。或者......你可以使用像memcached这样的库(如你所提到的)并利用共享缓存。网上有几个例子如何使用它。
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.
但是这些解决方案都会带来额外的开销(例如网络和第三个进程处理和数据获取等),如果没有别的话。所以默认缓存是最快的,如果你明确需要共享缓存,那么决定一个。除非确实需要,否则不要共享缓存。
#1
21
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.
请求上下文任何访问Web场的请求都由可用的IIS服务器提供服务。在那里创建上下文,整个请求由同一服务器提供服务。因此上下文不应成为问题。请求是无状态执行管道,因此它不需要以任何形式或形式与其他服务器共享数据。它将由同一台机器从头到尾提供。用户信息从cookie中读取并由提供请求的服务器处理。这取决于你是否在某处缓存完整的用户对象。
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.).
会话如果您使用TempData字典,您应该知道它存储在Session字典中。在服务器场中,这意味着您应使用InProc会话之外的其他方法,因为它们不在服务器场中的IIS服务器之间共享。您应该配置使用数据库或其他(状态服务器等)的其他会话管理器。
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.
缓存当谈到缓存时,它是一个不同的故事。为了使其尽可能高效,还应提供缓存。默认情况下不是。但是看一下缓存它几乎没有意味着当没有缓存时它应该被读取并存储在缓存中。因此,如果特定服务器场服务器没有某个缓存对象,则会创建它。所有这些都会缓存一些共享的公共使用数据。或者......你可以使用像memcached这样的库(如你所提到的)并利用共享缓存。网上有几个例子如何使用它。
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.
但是这些解决方案都会带来额外的开销(例如网络和第三个进程处理和数据获取等),如果没有别的话。所以默认缓存是最快的,如果你明确需要共享缓存,那么决定一个。除非确实需要,否则不要共享缓存。