Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my ASP.NET site acting single threaded?

I have an ASP.NET site running in IIS that I've noticed seems to run slow if one page is slow, so I set up a test to see if it was running as if it was a single thread (i.e. if one page request is running, all others must wait). I created a very simple page (no master page, only has the default aspx code except I added a Literal to dump debug code into) with code to read the current time, sleep 10 seconds, and then exit, like so:

protected void Page_Load(object sender, EventArgs e)
{
    DateTime now = DateTime.Now;
    System.Threading.Thread.Sleep(10000);         
    Literal1.Text = now.ToShortDateString() + " " + now.ToShortTimeString() + " " + now.Second + ":" + now.Millisecond;
}

I then open the page in two different tabs at the same time. The timestamp on each tab is almost exactly 10 seconds apart, which seems to me to mean that the second page request is blocked and waits until the first one completes before running.

I tried commenting out all http modules in web.config and disabling all code in Global.asax, but I still see this issue.

like image 983
datadamnation Avatar asked Dec 26 '22 08:12

datadamnation


1 Answers

This sounds like a session state issue.

Access to ASP.NET session state is exclusive per session, which means that if two different users make concurrent requests, access to each separate session is granted concurrently. However, if two concurrent requests are made for the same session (by using the same SessionID value), the first request gets exclusive access to the session information. The second request executes only after the first request is finished. [...]

Source: ASP.Net Session State Overview

Try disabling session state in web.config (or mark it as readonly) to confirm that this is indeed the issue, or use two different browsers (which gets different sessions).

like image 62
sisve Avatar answered Jan 12 '23 00:01

sisve