I just discovered why all ASP.Net websites are slow, and I am trying to work out what to do about it

前端 未结 10 781
情话喂你
情话喂你 2020-11-22 07:53

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!

10条回答
  •  深忆病人
    2020-11-22 08:32

    Unless your application has specially needs, I think you have 2 approaches:

    1. Do not use session at all
    2. Use session as is and perform fine tuning as joel mentioned.

    Session is not only thread-safe but also state-safe, in a way that you know that until the current request is completed, every session variable wont change from another active request. In order for this to happen you must ensure that session WILL BE LOCKED until the current request have completed.

    You can create a session like behavior by many ways, but if it does not lock the current session, it wont be 'session'.

    For the specific problems you mentioned I think you should check HttpContext.Current.Response.IsClientConnected. This can be useful to to prevent unnecessary executions and waits on the client, although it cannot solve this problem entirely, as this can be used only by a pooling way and not async.

提交回复
热议问题