服务器环境:
Intel Pentium 4 1.8G Hz
1G 内存
.net 2.0+access2003
数据库大小:6M
静态类如下所示:
using System;
using System.Data;
using System.Configuration;
using System.Data.OleDb;
namespace vote
{
/// <summary>
/// MyDataAccess 的摘要说明
/// </summary>
public static class MyDataAccess
{
//数据库连接字符串
private static string ConnString = ConfigurationManager.AppSettings["data_connstr"] + System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["data_path"]) + ";";
private static OleDbConnection conn = null;
private static OleDbCommand cmd = null;
public static bool ExcuteSQL(string _cmdtext)
{
bool suc = false;
cmd = new System.Data.OleDb.OleDbCommand(_cmdtext, conn);
OpenConn();
try
{
int i = cmd.ExecuteNonQuery();
if (i > 0)
{
suc = true;
}
}
catch (Exception ex)
{
suc = false;
}
finally
{
CloseConn();
}
return suc;
}
//打开一个连接
private static void OpenConn()
{
if (conn == null)
{
conn = new OleDbConnection(ConnString);
conn.Open();
}
else if(conn.State == ConnectionState.Closed)
{
conn.Open();
}
}
//关闭一个连接
private static void CloseConn()
{
if (conn.State == ConnectionState.Open)
{
conn.Close();
}
}
}
}
如果把这些代码放到页面里面,全部换成多实例类,那么性能似乎比较弱一些,我用web application stress 测试了一下
Overview
================================================================================
Report name: 2008-10-9 16:41:13
Run on: 2008-10-9 16:41:13
Run length: 00:01:00
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 576
Requests per Second: 9.60
Socket Statistics
--------------------------------------------------------------------------------
Socket Connects: 1154
Total Bytes Sent (in KB): 247.93
Bytes Sent Rate (in KB/s): 4.13
Total Bytes Recv (in KB): 679.39
Bytes Recv Rate (in KB/s): 11.32
Socket Errors
--------------------------------------------------------------------------------
Connect: 0
Send: 0
Recv: 0
Timeouts: 0
RDS Results
--------------------------------------------------------------------------------
Successful Queries: 0
Script Settings
================================================================================
Server: localhost
Number of threads: 1
Test length: 00:01:00
Warmup: 00:00:00
Cooldown: 00:00:00
Use Random Delay: No
Follow Redirects: Yes
Max Redirect Depth: 15
Clients used in test
================================================================================
localhost
Clients not used in test
================================================================================
Result Codes
Code Description Count
================================================================================
200 OK 576
Page Summary
Page Hits TTFB Avg TTLB Avg Auth Query
================================================================================
GET /v/addgroup2.aspx 576 4.24 89.18 No No
下面是用静态类实现的:
Overview
================================================================================
Report name: 2008-10-9 16:45:19
Run on: 2008-10-9 16:45:19
Run length: 00:01:00
Web Application Stress Tool Version:1.1.293.1
Number of test clients: 1
Number of hits: 657
Requests per Second: 10.95
Socket Statistics
--------------------------------------------------------------------------------
Socket Connects: 1316
Total Bytes Sent (in KB): 281.45
Bytes Sent Rate (in KB/s): 4.69
Total Bytes Recv (in KB): 5605.48
Bytes Recv Rate (in KB/s): 93.41
Socket Errors
--------------------------------------------------------------------------------
Connect: 0
Send: 0
Recv: 0
Timeouts: 0
RDS Results
--------------------------------------------------------------------------------
Successful Queries: 0
Script Settings
================================================================================
Server: 202.197.75.124
Number of threads: 1
Test length: 00:01:00
Warmup: 00:00:00
Cooldown: 00:00:00
Use Random Delay: No
Follow Redirects: Yes
Max Redirect Depth: 15
Clients used in test
================================================================================
localhost
Clients not used in test
================================================================================
Result Codes
Code Description Count
================================================================================
200 OK 657
Page Summary
Page Hits TTFB Avg TTLB Avg Auth Query
================================================================================
GET /v/addgroup.aspx 657 1.13 78.18 No No
但还有个问题,我发现这些结果是不一定的,有时候两者差不多,有时候两者有些差距,究竟哪个性能更好,还有待研究!