对于网络来说,什么样的状态比无国籍更好?

时间:2023-01-15 12:59:36

I have always advocated the stateless web, but would like to know what the advocates of the stateful web are saying.

我一直主张无状态网络,但想知道有状态网络的拥护者在说什么。

Do you have any situation where stateful is more appropriate than stateless?

你是否有任何有状态比无国籍更合适的情况?

5 个解决方案

#1


Our project uses the Wicket web framework, which allows stateful or stateless interaction. Stateful pages have a number of advantages:

我们的项目使用Wicket Web框架,允许有状态或无状态的交互。有状态页面有许多优点:

  • Using a stateful page in wicket makes it easier to perform partial page updates using wicket's AJAX framework
  • 在wicket中使用有状态页面可以更轻松地使用wicket的AJAX框架执行部分页面更新

  • Stateful is a more "intuitive" programming model. For example, in a wicket page class, I can declare a private member field on the server side, set it when the page is loaded, and access it again every time an AJAX request hits the page to perform some update.
  • 有状态是一种更“直观”的编程模型。例如,在wicket页面类中,我可以在服务器端声明一个私有成员字段,在加载页面时设置它,并在每次AJAX请求到达页面以执行某些更新时再次访问它。

  • Wicket prevents most common concurrency problems in the web tier by synchronizing on the user session object when handling a request.
  • Wicket通过在处理请求时同步用户会话对象来防止Web层中的大多数常见并发问题。

  • Storing state on the server side can sometimes improve performance; for example, an object that's time-consuming to construct but has to be available to the page can be loaded only once when the page is first instantiated.
  • 在服务器端存储状态有时可以提高性能;例如,在首次实例化页面时,只能加载一个构造但必须可用于页面的对象,该对象只能加载一次。

Anything that's possible in a stateful application could also be implemented as stateless - you simply have to store the state on the client, and submit all relevant state information on every request.

在有状态应用程序中可能执行的任何操作也可以实现为无状态 - 您只需将状态存储在客户端上,并在每个请求上提交所有相关的状态信息。

Link to wicket: http://wicket.apache.org/

链接到检票口:http://wicket.apache.org/

#2


Using states generally makes the programmer's job easier.

使用状态通常使程序员的工作更容易。

However, states also introduce all sorts of concurrency issues that are simply not present in stateless situations.

但是,各州还引入了无状态情况下根本不存在的各种并发问题。

This is essentially the debate between functional and imperative programming.

这实际上是功能和命令式编程之间的争论。

#3


I'm in the statefull client-stateless server camp due to scaleability but when facing the hurdles of explaining why this and that became harder to implement using a stateless server, you get kind of resigned in the long run, this is where stateful server shines:). Eventhough I prefer statefull client this is not easy to implement efficiently using asp.net viewstate and perhaps this is where statefull web gets practical. I think statefull client, stateless server makes you more aware of the amount of data that is transported back and forth between tires. That is sometimes hidden until trouble occures using statefull server programming model. Also, going from stateless to statefull is easy (just ignore state info that you are providing since you already know it.. ). Going the opposite is almost impossible/not worth it. Another thing using a statefull server is that clearing state/cache is often a problem when you are using also a statefull client. It's just unintuitive and confusing, or maby just I am :)

由于可扩展性,我处于有状态的客户端无状态服务器阵营,但是当遇到解释为什么使用无状态服务器变得更难以实现的障碍时,从长远来看,你会得到一些辞职,这是有状态服务器闪耀的地方:)。虽然我更喜欢有状态的客户端,但使用asp.net viewstate并不容易有效实现,也许这就是状态网络实用的地方。我认为有状态的客户端,无状态服务器让您更加了解轮胎之间来回传输的数据量。在使用有状态服务器编程模型发生故障之前,有时会隐藏这一点。此外,从无状态变为有状态很容易(只是忽略你提供的状态信息,因为你已经知道它了......)。相反的情况几乎不可能/不值得。使用statefull服务器的另一件事是,当您还使用有状态客户端时,清除状态/缓存通常是个问题。它只是不直观和令人困惑,或maby只是我:)

Anyhow GWT and many other modern toolkits (Silverlight talking to WCF) seems to prefer stateful client, stateless server due to scaleability issues. Maybe stateful server should be the exception to the stateless rule ... one could choose per page/window.

无论如何,由于可扩展性问题,GWT和许多其他现代工具包(Silverlight与WCF交谈)似乎更喜欢有状态客户端,无状态服务器。也许有状态服务器应该是无状态规则的例外...可以选择每页/窗口。

sources: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2871ef5076c1bdb6/43e7a5377047aa44?#43e7a5377047aa44

#4


Stateless web applications are essential when you start having higher traffic.

当您开始拥有更高的流量时,无状态Web应用程序至关重要。

There could be plenty of user data that you don't want to store on the client side for security reasons for example. In this case you need to store it server-side. You could use the web applications default session but if you have more than one instance of the application you will need to make sure that each user is always directed to the same instance.

出于安全原因,可能存在大量您不希望存储在客户端的用户数据。在这种情况下,您需要将其存储在服务器端。您可以使用Web应用程序默认会话,但如果您有多个应用程序实例,则需要确保每个用户始终定向到同一实例。

Load balancers often have the ability to have 'sticky sessions' where the load balancer some how knows which server to send the users request to. This is not ideal though, for example it means every time you restart your web application, all connected users will lose their session.

负载均衡器通常具有“粘性会话”的能力,其中负载均衡器可以知道哪个服务器发送用户请求。这并不理想,例如,这意味着每次重新启动Web应用程序时,所有连接的用户都将丢失会话。

A better approach is to store the session behind the web servers in some sort of data store, these days there are loads of great nosql products available for this (redis, mongo, elasticsearch, memcached). This way the web servers are stateless but you still have state server-side and the availability of this state can be managed by choosing the right datastore setup. These data stores usually have great redundancy so it should almost always be possible to make changes to your web application and even the data store without impacting the users.

一种更好的方法是将Web服务器后面的会话存储在某种数据存储中,现在有很多很好的nosql产品可用于此(redis,mongo,elasticsearch,memcached)。这样,Web服务器是无状态的,但您仍然具有状态服务器端,并且可以通过选择正确的数据存储设置来管理此状态的可用性。这些数据存储通常具有很强的冗余性,因此几乎总是可以对Web应用程序甚至数据存储进行更改,而不会影响用户。

#5


Things like long forms (and really anything that takes more than one page refresh) are much easier with persistent state, since you can actually keep track of what page/stage the user is on in an easy and straight-forward way. However, I personally don't think such a small advantage is worth it, but it greatly depends on the web application in question.

像持久状态这样的长形式(实际上任何需要多页刷新的东西)都更容易,因为您可以通过简单直接的方式实际跟踪用户所在的页面/阶段。但是,我个人并不认为这样的小优势是值得的,但它在很大程度上取决于所讨论的Web应用程序。

#1


Our project uses the Wicket web framework, which allows stateful or stateless interaction. Stateful pages have a number of advantages:

我们的项目使用Wicket Web框架,允许有状态或无状态的交互。有状态页面有许多优点:

  • Using a stateful page in wicket makes it easier to perform partial page updates using wicket's AJAX framework
  • 在wicket中使用有状态页面可以更轻松地使用wicket的AJAX框架执行部分页面更新

  • Stateful is a more "intuitive" programming model. For example, in a wicket page class, I can declare a private member field on the server side, set it when the page is loaded, and access it again every time an AJAX request hits the page to perform some update.
  • 有状态是一种更“直观”的编程模型。例如,在wicket页面类中,我可以在服务器端声明一个私有成员字段,在加载页面时设置它,并在每次AJAX请求到达页面以执行某些更新时再次访问它。

  • Wicket prevents most common concurrency problems in the web tier by synchronizing on the user session object when handling a request.
  • Wicket通过在处理请求时同步用户会话对象来防止Web层中的大多数常见并发问题。

  • Storing state on the server side can sometimes improve performance; for example, an object that's time-consuming to construct but has to be available to the page can be loaded only once when the page is first instantiated.
  • 在服务器端存储状态有时可以提高性能;例如,在首次实例化页面时,只能加载一个构造但必须可用于页面的对象,该对象只能加载一次。

Anything that's possible in a stateful application could also be implemented as stateless - you simply have to store the state on the client, and submit all relevant state information on every request.

在有状态应用程序中可能执行的任何操作也可以实现为无状态 - 您只需将状态存储在客户端上,并在每个请求上提交所有相关的状态信息。

Link to wicket: http://wicket.apache.org/

链接到检票口:http://wicket.apache.org/

#2


Using states generally makes the programmer's job easier.

使用状态通常使程序员的工作更容易。

However, states also introduce all sorts of concurrency issues that are simply not present in stateless situations.

但是,各州还引入了无状态情况下根本不存在的各种并发问题。

This is essentially the debate between functional and imperative programming.

这实际上是功能和命令式编程之间的争论。

#3


I'm in the statefull client-stateless server camp due to scaleability but when facing the hurdles of explaining why this and that became harder to implement using a stateless server, you get kind of resigned in the long run, this is where stateful server shines:). Eventhough I prefer statefull client this is not easy to implement efficiently using asp.net viewstate and perhaps this is where statefull web gets practical. I think statefull client, stateless server makes you more aware of the amount of data that is transported back and forth between tires. That is sometimes hidden until trouble occures using statefull server programming model. Also, going from stateless to statefull is easy (just ignore state info that you are providing since you already know it.. ). Going the opposite is almost impossible/not worth it. Another thing using a statefull server is that clearing state/cache is often a problem when you are using also a statefull client. It's just unintuitive and confusing, or maby just I am :)

由于可扩展性,我处于有状态的客户端无状态服务器阵营,但是当遇到解释为什么使用无状态服务器变得更难以实现的障碍时,从长远来看,你会得到一些辞职,这是有状态服务器闪耀的地方:)。虽然我更喜欢有状态的客户端,但使用asp.net viewstate并不容易有效实现,也许这就是状态网络实用的地方。我认为有状态的客户端,无状态服务器让您更加了解轮胎之间来回传输的数据量。在使用有状态服务器编程模型发生故障之前,有时会隐藏这一点。此外,从无状态变为有状态很容易(只是忽略你提供的状态信息,因为你已经知道它了......)。相反的情况几乎不可能/不值得。使用statefull服务器的另一件事是,当您还使用有状态客户端时,清除状态/缓存通常是个问题。它只是不直观和令人困惑,或maby只是我:)

Anyhow GWT and many other modern toolkits (Silverlight talking to WCF) seems to prefer stateful client, stateless server due to scaleability issues. Maybe stateful server should be the exception to the stateless rule ... one could choose per page/window.

无论如何,由于可扩展性问题,GWT和许多其他现代工具包(Silverlight与WCF交谈)似乎更喜欢有状态客户端,无状态服务器。也许有状态服务器应该是无状态规则的例外...可以选择每页/窗口。

sources: http://groups.google.com/group/google-web-toolkit/browse_thread/thread/2871ef5076c1bdb6/43e7a5377047aa44?#43e7a5377047aa44

#4


Stateless web applications are essential when you start having higher traffic.

当您开始拥有更高的流量时,无状态Web应用程序至关重要。

There could be plenty of user data that you don't want to store on the client side for security reasons for example. In this case you need to store it server-side. You could use the web applications default session but if you have more than one instance of the application you will need to make sure that each user is always directed to the same instance.

出于安全原因,可能存在大量您不希望存储在客户端的用户数据。在这种情况下,您需要将其存储在服务器端。您可以使用Web应用程序默认会话,但如果您有多个应用程序实例,则需要确保每个用户始终定向到同一实例。

Load balancers often have the ability to have 'sticky sessions' where the load balancer some how knows which server to send the users request to. This is not ideal though, for example it means every time you restart your web application, all connected users will lose their session.

负载均衡器通常具有“粘性会话”的能力,其中负载均衡器可以知道哪个服务器发送用户请求。这并不理想,例如,这意味着每次重新启动Web应用程序时,所有连接的用户都将丢失会话。

A better approach is to store the session behind the web servers in some sort of data store, these days there are loads of great nosql products available for this (redis, mongo, elasticsearch, memcached). This way the web servers are stateless but you still have state server-side and the availability of this state can be managed by choosing the right datastore setup. These data stores usually have great redundancy so it should almost always be possible to make changes to your web application and even the data store without impacting the users.

一种更好的方法是将Web服务器后面的会话存储在某种数据存储中,现在有很多很好的nosql产品可用于此(redis,mongo,elasticsearch,memcached)。这样,Web服务器是无状态的,但您仍然具有状态服务器端,并且可以通过选择正确的数据存储设置来管理此状态的可用性。这些数据存储通常具有很强的冗余性,因此几乎总是可以对Web应用程序甚至数据存储进行更改,而不会影响用户。

#5


Things like long forms (and really anything that takes more than one page refresh) are much easier with persistent state, since you can actually keep track of what page/stage the user is on in an easy and straight-forward way. However, I personally don't think such a small advantage is worth it, but it greatly depends on the web application in question.

像持久状态这样的长形式(实际上任何需要多页刷新的东西)都更容易,因为您可以通过简单直接的方式实际跟踪用户所在的页面/阶段。但是,我个人并不认为这样的小优势是值得的,但它在很大程度上取决于所讨论的Web应用程序。