考虑到性能可扩展能力,想尝试下抛弃ASP.NET的页面处理,玩一下“自做主张”。昨天写了一个简单的测试框架。并用ACT测试了一下,效果不错,比标准ASP.NET快15%以上。随着页面复杂性的提高,希望能有更出色的表现。
这个是“自做主张”的default.aspx文件内容,和标准的ASPX非常相像:
这个是“Code behind”:
为了测试性能,写了标准的ASP.NET页面和代码:
ACT测试:
1)连接
2)按Action按钮
3) 按Cancel按钮
4)结束
结果如下:
测试之前都执行iisreset.exe,测试时间为两分钟。标准ASP.NET处理了29544个请求,而我自己的处理了34108个。快了15%以上。虽然页面简单不能说明全部问题,我的事件处理也没有优化,但这种“另类”做法在性能上的提高是毫无疑问的。下面要考虑的是如何简化设计,以及利用CodeDom进一步提高可扩展性,当然是在不影响性能提高的前提下。
这个是“自做主张”的default.aspx文件内容,和标准的ASPX非常相像:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="ProgId" content="VisualStudio.HTML">
<meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
<script language="javascript">
function fnDoSubmit(obj,arg)
{
document.all("__EVENTTARGET").value = obj.id;
document.all("__EVENTARGUMENT").value = arg;
document.all("defaultForm").submit();
}
</script>
</head>
<body>
<form action="default.aspx" method="post" runat="server" id="defaultForm" name="defaultForm">
MyPage<br>
<input type="hidden" id="__EVENTTARGET" name="__EVENTTARGET">
<input type="hidden" id="__EVENTARGUMENT" name="__EVENTARGUMENT">
<%textResult%>
<%buttAction%>
<%buttCancel%>
</form>
</body>
</html>
<html>
<head>
<title></title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="ProgId" content="VisualStudio.HTML">
<meta name="Originator" content="Microsoft Visual Studio .NET 7.1">
<script language="javascript">
function fnDoSubmit(obj,arg)
{
document.all("__EVENTTARGET").value = obj.id;
document.all("__EVENTARGUMENT").value = arg;
document.all("defaultForm").submit();
}
</script>
</head>
<body>
<form action="default.aspx" method="post" runat="server" id="defaultForm" name="defaultForm">
MyPage<br>
<input type="hidden" id="__EVENTTARGET" name="__EVENTTARGET">
<input type="hidden" id="__EVENTARGUMENT" name="__EVENTARGUMENT">
<%textResult%>
<%buttAction%>
<%buttCancel%>
</form>
</body>
</html>
这个是“Code behind”:
using System;
namespace AspxHandler
{
/// <summary>
/// Summary description for MyPage.
/// </summary>
public class MyPage : MyHttpHandler, IEventHandler
{
protected MyControl memButtAction, memButtCancel;
protected MyEditBox memTextResult;
public MyPage() : base()
{
memButtAction = new MyButton(this,"buttAction","Action");
memButtCancel = new MyButton(this,"buttCancel","Cancel");
memTextResult = new MyEditBox(this,"textResult","");
}
IEventHandler Members
}
}
namespace AspxHandler
{
/// <summary>
/// Summary description for MyPage.
/// </summary>
public class MyPage : MyHttpHandler, IEventHandler
{
protected MyControl memButtAction, memButtCancel;
protected MyEditBox memTextResult;
public MyPage() : base()
{
memButtAction = new MyButton(this,"buttAction","Action");
memButtCancel = new MyButton(this,"buttCancel","Cancel");
memTextResult = new MyEditBox(this,"textResult","");
}
IEventHandler Members
}
}
<%@ Page language="c#" Codebehind="default.aspx.cs" AutoEventWireup="false" Inherits="AspxHandler._default" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>default</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
ASP.NET<br>
<asp:TextBox id="textResult" runat="server"></asp:TextBox>
<asp:Button id="buttAction" runat="server" Text="Action"></asp:Button>
<asp:Button id="buttCanel" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>default</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
ASP.NET<br>
<asp:TextBox id="textResult" runat="server"></asp:TextBox>
<asp:Button id="buttAction" runat="server" Text="Action"></asp:Button>
<asp:Button id="buttCanel" runat="server" Text="Button"></asp:Button>
</form>
</body>
</HTML>
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AspxHandler
{
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox textResult;
protected System.Web.UI.WebControls.Button buttAction;
protected System.Web.UI.WebControls.Button buttCanel;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web Form Designer generated code
private void buttAction_Click(object sender, EventArgs e)
{
textResult.Text = "buttAction(onclick)";
}
private void buttCanel_Click(object sender, EventArgs e)
{
textResult.Text = "buttCancel(onclick)";
}
}
}
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace AspxHandler
{
public class _default : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox textResult;
protected System.Web.UI.WebControls.Button buttAction;
protected System.Web.UI.WebControls.Button buttCanel;
private void Page_Load(object sender, System.EventArgs e)
{
}
Web Form Designer generated code
private void buttAction_Click(object sender, EventArgs e)
{
textResult.Text = "buttAction(onclick)";
}
private void buttCanel_Click(object sender, EventArgs e)
{
textResult.Text = "buttCancel(onclick)";
}
}
}
ACT测试:
1)连接
2)按Action按钮
3) 按Cancel按钮
4)结束
结果如下:
测试之前都执行iisreset.exe,测试时间为两分钟。标准ASP.NET处理了29544个请求,而我自己的处理了34108个。快了15%以上。虽然页面简单不能说明全部问题,我的事件处理也没有优化,但这种“另类”做法在性能上的提高是毫无疑问的。下面要考虑的是如何简化设计,以及利用CodeDom进一步提高可扩展性,当然是在不影响性能提高的前提下。