SQLServer 与 StateServer 的 ASP.NET 会话状态性能比较

发布于 2024-08-05 00:14:57 字数 165 浏览 4 评论 0原文

我正在学习 MS 认证,我正在进行的练习测试之一有一个问题,争论的焦点是在 SQL Server 中存储会话与在 StateServer 中存储会话之间的性能。

考虑到应用程序在网络场中运行,哪种会话状态解决方案可提供最佳性能(SQL Server 或 StateServer),最重要的是,为什么?

I'm studying for a MS certification and one of the practice tests I'm doing has a question where the point of contention is the performance between storing the session in SQL Server as opposed to StateServer.

Given the app is running in a web farm, which solution for session state gives the best performance (SQL Server or StateServer) and most importantly, why?

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

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

发布评论

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

评论(4

北凤男飞 2024-08-12 00:14:57

状态服务器速度更快,因为它将会话数据存储在内存字典中。 SQL Server 速度较慢,因为它存储在将数据保存到磁盘的数据库中。

SQL Server 也较慢,因为所有内容都存储在一张表中,随着越来越多的客户端访问/更新会话数据,这会导致争用。

SQL Server更可靠,因为它持久保存到磁盘上,并且可以设置为具有故障转移功能的集群。

有关深入说明,请参阅本文中的序言。

State Server is faster because it stores session data in an in-memory dictionary. SQL Server is slower because it's stored in a database which persists data to disk.

SQL server is also slower because everything is stored in one table which leads to contention as more and more clients access/update the session data.

SQL server is more reliable because it is persisted to disk and can be set up as a cluster with failover capability.

See the preamble in this article for an indepth explanation.

南烟 2024-08-12 00:14:57

一点但很重要的旁注:InProc 不能在场中使用,顾名思义,它在当前的 w3wp 进程中运行,并且不能在场中共享。 StateServer是一个Windows服务,所以使用StateServer的速度取决于stateserver服务运行的机器的速度,它只是内存。 SQL当然需要写入数据并检索,这可能比仅使用内存慢。

来自此处

  • 正在进行中。进程内的性能最佳,因为会话状态内存保存在 ASP.NET 进程内。对于托管在单个服务器上的 Web 应用程序,保证将用户重定向到正确的服务器,或者当会话状态数据不重要时(在某种意义上它可以重新构造或重新填充)的应用程序,这是要选择的模式。
  • 超出进程。当性能很重要但您无法保证用户将从哪个服务器请求应用程序时,最好使用此模式。通过进程外模式,您可以获得从内存读取的性能以及管理所有服务器状态的单独进程的可靠性。
  • SQL 服务器。当数据的可靠性对于应用程序的稳定性至关重要时,最好使用此模式,因为数据库可以针对故障场景进行集群。性能不如进程外那么快,但代价是更高的可靠性。

A little, but important sidenote: InProc is not usable in a farm, as the name suggests, it runs in the current w3wp proces and cannot be shared across a farm. StateServer is a Windows service, so the speed of using StateServer is dependend on how fast the machine the stateserver service is running on, it is memory only. SQL of course needs to write the data and retrieve, which is probably slower than memory only.

From here:

  • In process. In process will perform best because the session state memory is kept within the ASP.NET process. For Web applications hosted on a single server, applications in which the user is guaranteed to be re-directed to the correct server, or when session state data is not critical (in the sense that it can be re-constructed or re-populated), this is the mode to choose.
  • Out of process. This mode is best used when performance is important but you can't guarantee which server a user will request an application from. With out-of-process mode, you get the performance of reading from memory and the reliability of a separate process that manages the state for all servers.
  • SQL Server. This mode is best used when the reliability of the data is fundamental to the stability of the application, as the database can be clustered for failure scenarios. The performance isn't as fast as out of process, but the tradeoff is the higher level of reliability.
温柔女人霸气范 2024-08-12 00:14:57

通过此链接:http://www.eggheadcafe.com/articles/20021016.asp

性能

  • InProc - 最快,但会话数据越多,内存就越多
    在网络服务器上消耗,并且
    会影响性能。

  • StateServer - 存储基本类型的数据时(例如字符串、整数、
    等),在一个测试环境中为 15%
    比 InProc 慢。然而,成本
    序列化/反序列化可以
    如果您正在存储,则会影响性能
    地段
    的物体。您必须自己进行性能测试
    场景。

  • SQLServer - 存储基本类型的数据(例如字符串、整数、
    等),在一个测试环境中为 25%
    比 InProc 慢。同样的警告
    与 StateServer 中一样的序列化。

因此,StateServer 存储会话状态的速度似乎比 SQL Server 快一些。

就原因而言,我建议 SQL Server 具有更多用途,并且也可能用于其他用途。不仅如此,存储机制是磁盘,因为 StateServer 在单独的进程中运行,但它只是将数据存储在另一个进程的内存空间中,而不是必须将其写入磁盘(虚拟内存允许)

From this link: http://www.eggheadcafe.com/articles/20021016.asp

Performance

  • InProc - Fastest, but the more session data, the more memory is
    consumed on the web server, and that
    can affect performance.

  • StateServer - When storing data of basic types (e.g. string, integer,
    etc), in one test environment it's 15%
    slower than InProc. However, the cost
    of serialization/deserialization can
    affect performance if you're storing
    lots
    of objects. You have to do performance testing for your own
    scenario.

  • SQLServer - When storing data of basic types (e.g. string, integer,
    etc), in one test environment it's 25%
    slower than InProc. Same warning about
    serialization as in StateServer.

So it would seem that StateServer is a little faster that SQL Server for storing session state.

In terms of the why, I'd suggest that the SQL Server is more multi-purpose and will likely be used for other things as well. Not only that but the storage mechanism is to disk, where as the StateServer is running in a separate process, yet it is simply storing the data in the memory space of the other process rather than having to write it to disk (virtual memory permitting)

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