qileilove

blog已经转移至github,大家请访问 http://qaseven.github.io/

LoadRunner 技巧之思考时间设置

 用户访问某个网站或软件,一般不会不停地做个各种操作,例如一次查询,用户需要时间查看查询的结果是否是自己想要的。例如一次订单提交,用户需要时间核对自己填写的信息是否正确等。

  也就是说用户在做某些操作时,是会有停留时间的,我把这个时间叫思考时间。但利用代码去执行的时候是没有时间的,当然,脚本运行本身是需要时间的,但比起人的思考时间要小很多。这也是我们为什么要用软件来代替人的某些工作

  但有时候,我们在做性能测试时,为了更真实的模拟用户的操作,需要给代码加入思考时间。来看看在loadrunner是如何设置思考时间的。

  打开loadrunner 的Virtual User Generator

  菜单栏:Vuser ---Run-Time settings...,切换到Thark Time选项

  好吧!为了更好的理解这个界面上设置,现在我们通过一个脚本来分析。

Action()
{

     double trans_time;  //定义变量

    web_url("www.baidu.com",
        "URL=http://www.baidu.com/",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=",
        "Snapshot=t1.inf",
        "Mode=HTML",
        LAST);


    web_url("i-1.0.0.png",
        "URL=http://s1.bdstatic.com/r/www/img/i-1.0.0.png",
        "Resource=1",
        "RecContentType=image/png",
        "Referer=http://www.baidu.com/",
        "Snapshot=t2.inf",
        LAST);

    web_url("favicon.ico",
        "URL=http://www.baidu.com/favicon.ico",
        "Resource=1",
        "RecContentType=image/x-icon",
        "Referer=",
        "Snapshot=t3.inf",
        LAST);

    web_url("su",
        "URL=http://suggestion.baidu.com/su?wd=&cb=window.bdsug.sugPreRequest&sid=1466&t=1362316450913",
        "Resource=1",
        "RecContentType=baiduapp/json",
        "Referer=http://www.baidu.com/",
        "Snapshot=t4.inf",
        LAST);


    lr_start_transaction("注册");  //添加事务
    lr_think_time(20);    //设置思考时间   

    web_url("v.gif",
        "URL=http://nsclick.baidu.com/v.gif?pid=201&pj=www&rsv_sid=1466&fm=behs&tab=tj_reg&un=&path=http%3A%2F%2Fwww.baidu.com%2F&t=1362316485456",
        "Resource=1",
        "Referer=http://www.baidu.com/",
        LAST);


    web_url("favicon.ico_2",
        "URL=https://passport.baidu.com/favicon.ico",
        "Resource=1",
        "RecContentType=application/octet-stream",
        "Referer=",
        "Snapshot=t5.inf",
        LAST);

    web_link("注册",
        "Text=注册",
        "Snapshot=t6.inf",
        LAST);

    web_custom_request("urs.asmx",
        "URL=https://urs.microsoft.com/urs.asmx?MSURS-Client-Key=WI0pAZHPdb%2b3UDOD0AtzxA%3d%3d&MSURS-Patented-Lock=S1IpDfNCCC4%3d",
        "Method=POST",
        "Resource=0",
        "RecContentType=text/xml",
        "Referer=",
        "Snapshot=t7.inf",
        "Mode=HTML",
        "EncType=text/xml; charset=utf-8",
        "Body=<RepLookup v=\"3\"><G>ED8654D5-B9F0-4DD9-B3E8-F8F560086FDF</G><O>F03F2D77-79E1-4DEC-BBF8-81A5C0790160</O><D>9.0.8110.0</D><C>9.00.8112.16421</C><OS>6.1.7601.1.0</OS><I>9.0.8112.16421</I><L>zh-CN</L><R><Rq><URL>aHR0cHM6Ly9wYXNzcG9ydC5iYWlkdS5jb20vdjIvP3JlZyZyZWdUeXBlPTEmdHBsPW1uJnU9aHR0cCUzQSUyRiUyRnd3dy5iYWlkdS5jb20lMkY=</URL><O>PRE</O><T>TOP</T><HIP>220.181.111.48</HIP></Rq></R></RepLookup>",
        EXTRARES,
        "Url=https://passport.baidu.com/img/topbarnav_bg.png", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        "Url=https://passport.baidu.com/passApi/js/reg_6e270622.js", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        "Url=https://passport.baidu.com/passApi/img/small_blank_9dbbfbb1.gif", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        LAST);

    web_url("api",
        "URL=https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1362316491971&class=reg&callback=bd__cbs__c93h6w",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F",
        "Snapshot=t8.inf",
        "Mode=HTML",
        EXTRARES,
        "Url=/img/v.gif?type=1&regType=mail", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        LAST);

    web_url("api_2",
        "URL=https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1362316491978&class=regPhone&callback=bd__cbs__xs2rv5",
        "Resource=0",
        "RecContentType=text/html",
        "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F",
        "Snapshot=t9.inf",
        "Mode=HTML",
        EXTRARES,
        "Url=/cgi-bin/genimage?001362316472015690A3686612594D3D2C14ABF30D0B432CF4462DF3A4B5A8E5E7B7EE094DCAB428311C96E23B35A3CB73A67533699084E25A27CF6C9745497B5C5435611E0593A615CC284B27D70CA5FFB5F771E5D7DC9EE266F6FD61A2D88FEC7B7BA20EFF5DE2CD301E011E634D5063BDDCD35A47C1EB7B5EF365B347DD5800C612B744FAEF845540239F1036CC800902957BD17F36F6547B71C198C154162F8F71077B935E6B", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        "Url=/img/bd-split.gif", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        "Url=/img/reg_tip_header_t.gif", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        "Url=/img/reg_tip_bg_bottom.gif", "Referer=https://passport.baidu.com/v2/?reg&regType=1&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2F", ENDITEM,
        LAST);


    trans_time=lr_get_transaction_wasted_time("注册");  //获得消耗时间

    if (trans_time) {
        lr_output_message("The duration up to the submit is %f seconds",trans_time);  //打印输出消耗实时间
    }else{
        lr_output_message("the duration cannot be determined. ");
    }

    lr_end_transaction("注册",LR_AUTO);  //事务结束

    return 0;
}


脚本有点长,但不要被吓到了,重要的几句我已经加了注释。你只用关注那几行就行了。

  lgnore think time:忽视思考时间,也就说勾选这一项的时候 ,你脚本中加入的lr_think_time 函数设置是无效的。选中这一项,运行上面的脚本。

Action.c(62): The duration up to the submit is 0.032043 seconds
Action.c(67): Notify: Transaction "注册" ended with "Pass" status (Duration: 12.4113 Wasted Time: 0.0320).

  虽然我在脚本中加入了lr_think_time(20); 这条语句,显现没起到任何作用。

  Replay think time:回放思考时间

  来看第一个选项:

  As recorded:取决于记录,选种这一项再来运行上面的脚本。

Action.c(111): The duration up to the submit is 0.034508 seconds
Action.c(116): Notify: Transaction "注册" ended with "Pass" status (Duration: 50.4453 Think Time: 20.0000 Wasted Time: 0.0345).
Ending action Action.

  运行结果中多了一个 Think Time: 20.0000;这说明我们脚本中的lr_think_time(20); 起到了作用,选中这一项后,我们可以在脚本中任意的添加思考时间。

  Multiply recorded think time by:录制思考时间乘以,使用录制思考时间的倍数。

  其实,在我们脚本录制的过程中,根据我们的操作,脚本中就可以生成相应的思考时间。这个参数是根据脚本中的思考时间进行调整的。

  例如:脚本是20秒,输入2,那么在脚本实际运行时,思考时间将为40秒;输入0.5 ,脚本在运行时的思考时间为10秒。下面选中此项,输入0.5,再来查看脚本运行结果:

Action.c(111): The duration up to the submit is 0.036610 seconds
Action.c(116): Notify: Transaction "注册" ended with "Pass" status (Duration: 131.2022 Think Time: 9.9998 Wasted Time: 0.0366).

  注:将原谅脚本会有0.0002秒的误差。

  Use random percentage of recorded think time:使用录制思考时间的百分比。

  通过指定思考的时间的范围,可以设置思考时间值的范围。假如思考时间为20秒,这里设置的范围为50% 到100% ,那么脚本运行时候将随即的在这个范围(10秒到20秒之间)内取值。下面再来查看脚本运行时间:

Action.c(111): The duration up to the submit is 0.036191 seconds
Action.c(116): Notify: Transaction "注册" ended with "Pass" status (Duration: 40.8002 Think Time: 15.0050 Wasted Time: 0.0362).

  这一次Think Time: 为15.0050,是在10到20秒的范围之内,你再次运行会发现这个时间不一样,但不会超出设定的范围。

  Limit think time to:限制思考时间的最大值。

  假如脚本设置的思考时间为20秒,选中这一项并设置为10秒。那么脚本在运行时,思考时间不会超过10秒。也就是说这设置同样也制约前面几个选项。这个你可以自行设置验证。

  感谢:

double trans_time;  //定义变量
......
lr_start_transaction("注册"); //添加事物
    lr_think_time(8);   //思考时间

.......
trans_time=lr_get_transaction_wasted_time("注册");  //获得消耗时间

    if (trans_time) {
        lr_output_message("The duration up to the submit is %f seconds",trans_time);  //打印输出消耗实时间
    }else{
        lr_output_message("the duration cannot be determined. ");
    }

lr_end_transaction("注册",LR_AUTO);  //事务结束
..........

  感谢上面这段代码很好帮助我们理解思考时间。

  备注:添加思考时间可以更真实的模拟用户行为,但它同时降低了用户并发。也就是说思考时间越长,对服务器的压力会越小。

相关链接:

LoadRunner 技巧之协议分析

LoadRunner 技巧之THML 与 URL两种录制模式分析

posted on 2013-03-12 10:42 顺其自然EVO 阅读(610) 评论(0)  编辑  收藏 所属分类: loadrunner性能测试


只有注册用户登录后才能发表评论。


网站导航:
 
<2013年3月>
242526272812
3456789
10111213141516
17181920212223
24252627282930
31123456

导航

统计

常用链接

留言簿(55)

随笔分类

随笔档案

文章分类

文章档案

搜索

最新评论

阅读排行榜

评论排行榜