One of the reasons that ASP. NET MVC request is slow (session affects concurrency)

Source: Internet
Author: User

Phenomenon: In the Web site, open a page time is more serious, and then open another page for login verification, found that multiple HTTP requests do not respond and return values.

On-line information, accidental discovery is due to the session of the lock mechanism.

The original session implemented the Reader/writer lock mechanism:

When the page has a writable function on the session (that is, the page has a <%@ page enablesessionstate= "True"%> tag), this time until the session requesting completion of the page holds a write lock.

When the page has read-only functionality to the session (that is, the page has a <%@ page enablesessionstate= "ReadOnly"%> tag), the session that requested completion of the page holds a read lock.

Read locks block A write lock, read locks do not block read locks, and write locks block all read and write locks. That's why when the same page in both frames goes to the same session, one of them waits for the other (slightly faster) to finish before it starts writing.

Solution:

1. Set session state in Global.asax

public override void Init () {
This. Postauthenticaterequest + = (sender, e) = =
HttpContext.Current.SetSessionStateBehavior (sessionstatebehavior.readonly);
Base. Init ();
}

2. Set session state in a separate page

<%@ page enablesessionstate= "ReadOnly"%>

One of the reasons that ASP. NET MVC request is slow (session affects concurrency)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.