使用 Microsoft Application Center Test 为WEB应用程序获取可量化的性能指标

类别:.NET开发 点击:0 评论:0 推荐:

Microsoft Application Center Test是VS.Net自带的一个测试工具.使用它可以收集性能信息.确定WEB应用程序的容量.也可以创建测试,模拟同时从WEB应用程序请求网页的多个用户.这些模拟测试有助于确定应用程序的稳定性.速度和响应能力.
我们下面使用两个例子来看看不同的实现方式.
第一个例子比较简单.目的是测试字符串对象使用"+"连接符操作和使用StringBuilder的Append方法进行字符串连接操作的区别.
最终的结果是相同的.即生产10000个A组成的字符串.
这是使用+操作符的代码
文件名:StringPlus.aspx
private void Button1_Click(object sender, System.EventArgs e)
{
string S = string.Empty;
for (int i=0;i<10000;i++)
S += "A";

this.Label1.Text = S.ToString();
}
以下是使用Append方法的代码
文件名:StringAppend.aspx
private void Button1_Click(object sender, System.EventArgs e)
{

StringBuilder S = new StringBuilder();
for (int i=0;i<10000;i++)
S.Append("A");

this.Label1.Text = S.ToString();
}

大家可以看到.以上是同样结果的两种不同实现方式.代码编写完成后,我们用Microsoft Application Center Test 来测试一下其性能差距.
打开"Visual Studio .NETàVisual Studio .NET 企业版功能àMicrosoft Application Center Test" 启动应用程序.
在”测试”项目上点右键.新建项目à录制项目 开始录制 输入网址后.录制要测试的项目的操作.然后按 停止录制.为这个测试项目起个名字.保存.即完成了一个测试项目的创建.
选择一个测试项目点 启动测试 按钮.即开始测试.
以下是测试的结果.

screen.width-333) {this.width=screen.width-333;this.title='open new window';}" border=0 ;>

性能大约是14.5 BPS (BPS--每秒平均请求数)
以同样的方法测试使用Append方法的代码的文件StringAppend.aspx 得出的结果是


screen.width-333) {this.width=screen.width-333;this.title='open new window';}" border=0 ;>

性能大约是170 BPS (BPS--每秒平均请求数)

可以看出.使用Append方法进行字符串连接比使用”+”操作符要高效得多.(在这个例子里使用Append方法效率提升了12倍)


第二个例子是关于COM+
COM+仅在必要时使用.COM+在提供事务处理,队列等先进性能的同时也额外耗费系统资源.在这个例子里我测试了使用COM+和没有使用Com+两种环境下的应用程序的效率.
WEB页面程序是一样的.所不同的是组件. 不使用COM+的代码是如下代码.
namespace PlentySoft.Naola.ComPlusComponent2
{
/// <summary>
/// Class1 的摘要说明。
/// </summary>
public class I
{
public I()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
public string getString()
{
You Y = new You();
string sR;
sR = Y.returnV();

return "Demo1's is I,Demo2's value is " + sR ;
}
}
}
使用COM+的代码只是多了个 : ServicedComponent
经过测试.不使用COM+测试结果为


screen.width-333) {this.width=screen.width-333;this.title='open new window';}" border=0 ;>

性能大约是337 BPS (BPS--每秒平均请求数)

使用COM+后.应用程序测试的结果为


screen.width-333) {this.width=screen.width-333;this.title='open new window';}" border=0 ;>
性能大约是245 BPS (BPS--每秒平均请求数)

也可以说不使用COM+ 可提升50%的性能.
但在我们的ERP应用程序里.包括报表都使用的COM+环境.这是没有必要的.可以改良的.

以上两个例子只是Microsoft Application Center Test应用的两个小例子.意只在抛砖引玉.让大家用好这个工具.做出性能更完善的应用程序.

本文地址:http://com.8s8s.com/it/it42161.htm