我刚刚发现了为什么所有 ASP.Net 网站都很慢,我正在尝试解决这个问题

I just discovered why all ASP.Net websites are slow, and I am trying to work out what to do about it(我刚刚发现了为什么所有 ASP.Net 网站都很慢,我正在尝试解决这个问题)
本文介绍了我刚刚发现了为什么所有 ASP.Net 网站都很慢,我正在尝试解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现 ASP.Net Web 应用程序中的每个请求在请求开始时都会获得一个 Session 锁,然后在请求结束时释放它!

I just discovered that every request in an ASP.Net web application gets a Session lock at the beginning of a request, and then releases it at the end of the request!

如果你忘记了这一点的含义,就像一开始对我一样,这基本上意味着以下几点:

In case the implications of this are lost on you, as it was for me at first, this basically means the following:

  • 任何时候 ASP.Net 网页需要很长时间才能加载(可能是由于数据库调用缓慢或其他原因),并且用户因为厌倦了等待而决定要导航到不同的页面,他们不能!ASP.Net 会话锁强制新页面请求等待,直到原始请求完成其令人痛苦的缓慢加载.啊.

  • Anytime an ASP.Net webpage is taking a long time to load (maybe due to a slow database call or whatever), and the user decides they want to navigate to a different page because they are tired of waiting, THEY CAN'T! The ASP.Net session lock forces the new page request to wait until the original request has finished its painfully slow load. Arrrgh.

任何时候 UpdatePanel 加载缓慢,并且用户决定在 UpdatePanel 完成更新之前导航到不同的页面......他们不能!ASP.net 会话锁强制新页面请求等待原始请求完成其令人痛苦的缓慢加载.双Arrrgh!

Anytime an UpdatePanel is loading slowly, and the user decides to navigate to a different page before the UpdatePanel has finished updating... THEY CAN'T! The ASP.net session lock forces the new page request to wait until the original request has finished its painfully slow load. Double Arrrgh!

那么有哪些选择呢?到目前为止,我想出了:

So what are the options? So far I have come up with:

  • 实现 ASP.Net 支持的自定义 SessionStateDataStore.我没有找到太多可以复制的东西,而且看起来风险很高,而且很容易搞砸.
  • 跟踪所有正在进行的请求,如果请求来自同一用户,则取消原始请求.似乎有点极端,但它会起作用(我认为).
  • 不要使用会话!当我需要用户的某种状态时,我可以只使用缓存,并在经过身份验证的用户名上使用关键项,或者类似的东西.再次显得有些极端.

我真的不敢相信 ASP.Net 微软团队会在 4.0 版本的框架中留下如此巨大的性能瓶颈!我错过了一些明显的东西吗?为 Session 使用 ThreadSafe 集合有多难?

I really can't believe that the ASP.Net Microsoft team would have left such a huge performance bottleneck in the framework at version 4.0! Am I missing something obvious? How hard would it be to use a ThreadSafe collection for the Session?

推荐答案

好的,感谢 Joel Muller 的所有意见.我的最终解决方案是使用这篇 MSDN 文章末尾详细介绍的自定义 SessionStateModule:

OK, so big Props to Joel Muller for all his input. My ultimate solution was to use the Custom SessionStateModule detailed at the end of this MSDN article:

http://msdn.microsoft.com/en-us/library/system.web.sessionstate.sessionstateutility.aspx

这是:

  • 实施起来非常快(实际上似乎比走供应商路线更容易)
  • 使用了很多开箱即用的标准 ASP.Net 会话处理(通过 SessionStateUtility 类)

这对我们的应用程序敏捷"的感觉产生了巨大的影响.我仍然无法相信 ASP.Net Session 的自定义实现会锁定整个请求的会话.这给网站增加了如此多的迟缓.从我必须做的大量在线研究(以及与几位真正有经验的 ASP.Net 开发人员的对话)来看,很多人都遇到过这个问题,但很少有人能找到原因.也许我会写一封信给 Scott Gu……

This has made a HUGE difference to the feeling of "snapiness" to our application. I still can't believe the custom implementation of ASP.Net Session locks the session for the whole request. This adds such a huge amount of sluggishness to websites. Judging from the amount of online research I had to do (and conversations with several really experienced ASP.Net developers), a lot of people have experienced this issue, but very few people have ever got to the bottom of the cause. Maybe I will write a letter to Scott Gu...

我希望这可以帮助一些人!

I hope this helps a few people out there!

这篇关于我刚刚发现了为什么所有 ASP.Net 网站都很慢,我正在尝试解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)