1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

セッション管理とスレッドモデル(ASP.NET編)

Last updated at Posted at 2020-12-18

セッション管理とスレッドモデル(ASP.NET編)

結論

複数のセッションの処理はマルチスレッド処理(平行処理)が行われているかもしれないが、同一セッションの内部では処理は一つずつシリアルで処理されているということ。

実験

親のaspxでセッションを作成、その後、ko0.aspxとko1.aspxに対して同時にアクセスされるはずなので、その様子を見てみよう。

oya.aspx
<%@ Page Language="C#" %>

<script runat="server">
</script>

<html>
 <head>
 </head>
 <body>
 <form id="form1" runat="server">
SessionID= <%= this.Session.SessionID %><br><hr>
  <iframe src="ko0.aspx"></iframe><br><hr>
  <iframe src="ko1.aspx"></iframe>
 </form>
 </body>
</html>

ko0.phpとko1.phpは同じ内容で、10秒間スリープするだけの処理

ko0.aspx
<%@ Page Language="C#" %>

<script runat="server">
</script>

<html>
<head runat="server">
</head>
<body>
<form id="form1" runat="server">
<%
 Response.Write("SessionID=" + this.Session.SessionID + "<br>");
 System.DateTime dateTime1 = System.DateTime.Now;
 Response.Write(dateTime1.Hour.ToString() + ":" + dateTime1.Minute.ToString() + ":" + dateTime1.Second.ToString()+ "<br>");
 Session["aaa"] += "abc";
 Response.Write(Session["aaa"] + "<br>");
 System.Threading.Thread.Sleep(10000);
 System.DateTime dateTime2 = System.DateTime.Now;
 Response.Write(dateTime2.Hour.ToString() + ":" + dateTime2.Minute.ToString() + ":" + dateTime2.Second.ToString()+ "<br>");
%>
</form>
</body>
</html>

結果

04.jpg

ko0.aspx が処理されてから、ko1.aspxが処理されているのがわかる。

時々、セッションがko[0|1].aspxに引き継がれない場合もある...(その時は、個別のセッションなので、ko[0|1].aspxは同時並行に処理される)

つまり

同一セッションで大量にアクセスしても・・・早く終わるわけではない、ということ

考えてみたら・・・

Sessionオブジェクトに複数スレッドから同時アクセスを制御するようなロック処理がないのだから当然といえば当然か・・・

このあたりはClassicASPと互換性(sessionオブジェクトには排他制御がないけど、Applicationオブジェクトにはある・・・とか)を維持しているのかもしれない。

戻る

セッション管理とスレッドモデル

以上

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?