一个非锁定的进程内 ASP.NET 会话状态存储 [英] A non-locking in-process ASP.NET session state store

查看:18
本文介绍了一个非锁定的进程内 ASP.NET 会话状态存储的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 ASP.NET 的进程内会话状态存储.它以独占方式锁定对会话的访问,这意味着对同一会话的并发请求按顺序提供.

I'm using ASP.NET's in-process session state store. It locks access to a session exclusively, and which means concurrent requests to the same session are served sequentially.

我想移除这个隐式排他锁,以便每个会话可以同时处理多个请求.当然,我会在适用的地方同步访问会话状态.

I want to remove this implicit exclusive lock, so multiple requests per session can be handled concurrently. Of course, I'll be synchronizing access to the session state myself where it's applicable.

我正在使用 会话状态提供程序的 MSDN 文档编写我自己的会话状态提供程序,以及 这个问题 将我指向这个示例代码将其实现为一个 HTTP 模块,但代码看起来非常复杂,只是为了移除锁.

I'm using the MSDN documentation of Session State Providers to write my own session state provider, and this SO question pointed me to this example code of implementing this as an HTTP module, but the code looks suspiciously complex just for the purpose of removing the lock.

我可能最终应该使用 ASP.NET 的缓存实现会话状态,并停止使用内置会话,就像 Vivek 在 这篇文章,但现在我想怎么做解除锁定.

I should probably eventually implement the session state using ASP.NET's cache, and stop using the built-in session, like Vivek describes in this post, but for now how would I just like to remove the locking.

任何想法或示例实现?

推荐答案

这不是您要找的答案,但我认为即使有可能,以这种方式改变 SessionState 的工作方式也是一个糟糕的主意.

Not the answer you're looking for, but I think that even if it were possible, changing the way SessionState works in this way is a terrible idea.

想想那些不得不维护你的代码的可怜人.Session 以这种方式序列化请求的事实意味着 ASP.NET 开发人员通常不需要过多担心线程安全.

Think of the poor guys who will have to maintain your code down the line. The fact that Session serializes requests in this way means ASP.NET developers often don't need to worry too much about thread-safety.

此外,如果有人添加了一个碰巧使用 Session 的第三方组件,它会期待通常的关于锁的保证——你会突然开始得到 Heisenbugs.

Also if someone adds a third-party component that happens to use Session, it will expect the usual guarantees regarding locks - and you'll suddenly start getting Heisenbugs.

相反,衡量性能并确定您需要并发处理请求的特定区域 - 我敢打赌它们很少 - 并仅针对所涉及的特定项目仔细实施您自己的锁定机制 - 可能是您正在使用的解决方案计划最终使用 ASP.NET 缓存.

Instead, measure performance and identify specific areas where you need requests to process concurrently - I bet there'll be few of them - and carefully implement your own locking mechanism only for the specific items involved - possibly the solution that you're planning eventually using the ASP.NET cache.

这篇关于一个非锁定的进程内 ASP.NET 会话状态存储的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆