什么是网络应用程序或网站中的无状态状态
我刚刚开始学习网络应用程序开发的基础知识。当我阅读 ASP.Net Web Forms、ASP.Net MVC 等不同方法时。大多数教程在解释 MVC 等内容时都提到了术语“无状态”。我无法正确理解这个术语。你能帮忙解释一下吗?
谢谢
I am just into learning the basics of web application development. As i was reading the different approaches like ASP.Net Web Forms, ASP.Net MVC ,etc. Most of the tutorials mentioned the term 'stateless' when explaining about MVC and all. I was unable to get the term correctly. Could you help explaining a bit about it.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这意味着一般的 Web 应用程序。无状态意味着服务器和客户端之间没有持久连接。客户说“嘿 google.com,给我那个网站”然后谷歌回复。之后连接关闭。
您需要更多信息吗?
this means web applications in general. Stateless means that there is no persistant connection between server and client. The client say "Hey google.com, gimme that site" and google response.. After that the connection is closed.
Do you need more informations ?
这里的状态是指服务器为其连接的每个客户端维护的交互状态。 (请注意,它与 MVC 无关。)
或者换句话说:
您走进一家汉堡店,柜台后面有几个人在帮助人们点餐。
如果在与柜台后面的人的每一次互动中,柜台后面的任何一名工作人员都能够为顾客提供服务,那么汉堡店的流程就是“无状态的”。例如,你说“给我一个汉堡”,有人给你一个汉堡。你说“卡奇普”?别人给了你你所要求的东西。
如果这是一家“有状态”的汉堡店,您就会排队,每个顾客都会在柜台后面有一个特定的人来查看他们的整个订单。
有什么区别?
在第一种情况下,无论柜台后面的工作人员发生什么情况,您的订单都会一步步进行。每个步骤可能是由不同的工作人员处理的(或者也可能是同一个工作人员随机完成所有步骤,但这只是偶然)。您只需继续向柜台下订单即可。
在第二种情况下,如果您的服务器中途发生某些情况,对话的状态必须传递到另一台服务器,以便它可以继续为您提供服务。否则你需要从头开始。保存状态需要花费一些精力 - 您需要将其写在某个地方,并且在服务器停止运行的情况下,接管您订单的其他服务器需要获取该状态并恢复其所在位置的交互离开。
在午餐高峰期去汉堡店怎么样?
在这两种情况下,经理都可以简单地在柜台后面添加新员工。
鉴于第一个案例的无国籍状态,新工人可以加入运营并开始为已经在订单中的客户做出贡献。有人说“卡奇普?”也许一个新的服务器会返回“给你”。
在第二种情况下,每个额外的服务器只能帮助处理新订单(但不能帮助处理已经处理的订单)。
State here refers to the interaction state that a server maintains for each of its connected client. (Note that it has nothing to do with MVC.)
Or in other words:
You walk into a burger joint and there are a few people behind the counter helping people with their orders.
The burger joint's process is 'stateless' if, in every single interaction with the people behind the counter any one of the workers behind the counter would be able to serve the customer. For example, you say "give me a burger" and someone gives you a burger. You say "Katchup?" and someone else gives you what you asked.
If it was a 'stateful' burger joint you form queues, and each client gets a specific person behind the counter to see them through their whole order.
What's the difference?
In the first case, regardless of what happens to any of the workers behind the counter your order progresses step by step. Each step may have been handled by a different worker (or also possible that it randomly happens that the same worker does it all, but that's just chance). You simply continue with your orders to the counter.
In the second case, if something happens mid-order to your server, the state of the conversation must be passed to another server so it may continue to server you. Otherwise you need to start from scratch. Saving the state costs a bit of effort -- you need to write it down somewhere and in case of the out-of-action-server the other server that takes over your order needs to get that state and resume the interaction where it was left off.
How about scaling the burger joint for the lunch rush?
In both cases, the manager can simply add new workers behind the counter.
Given the stateless state of affairs of the first case, the new workers can join the operations and start contributing to clients already in middle of an order. Some says "Katchup?" and perhaps a new server pipes back "here you go".
In the second case, each additional servers can only help with new orders (but not orders already in progress).
http://en.wikipedia.org/wiki/Stateless_server
举个简单的例子,当您在无状态环境中,您可以修改变量(比方说,用户名),但如果您重新加载页面(因为我们正在讨论网络应用程序),则变量会重置。这就是为什么它被称为无状态,两种状态之间没有持久性(例如,每次页面刷新都是一个状态)。
http://en.wikipedia.org/wiki/Stateless_server
In a quick example, when you're in a stateless environement, you can modify variables (let's say, username) but if you reload the page (since we're talking about webapps) that variable resets. That's why it's called stateless, there's no persistance between two states (every page refresh, example, is a state).