《LoadRunner 12七天速成宝典》—第2章2.6节第二个性能测试案例

本文涉及的产品
性能测试 PTS,5000VUM额度
简介: 理解动态访问会带来的负载点及系统处理业务的逻辑概念。

本节书摘来自异步社区《LoadRunner 12七天速成宝典》一书中的第2章,第2.6节第二个性能测试案例,作者陈霁,更多章节内容可以访问云栖社区“异步社区”公众号查看。

2.6 第二个性能测试案例
云云:烤鱼吃得很爽。

恋恋:就是你非要吃香辣味的,害得我嘴巴都麻了。

云云:香辣味的好吃,就是鲶鱼吃得有点腻,能吃黑鱼就好了。

恋恋:下次多找几个人一起吃饭啊,这下他们生意就更好了。

云云:那么我问你一下点一样的鱼和点不同的鱼有什么区别?

恋恋:嘿,你又要考我啦,其实刚才你还没提问,我脑子里面就在想这个问题了。

云云:哦,美美狗开窍了?

恋恋:不但我是美美狗还是聪聪狗,你那点小花样我早看出来了。

云云:那么你说说,让我欣赏一下你的“光芒”。

恋恋:这个问题按照你的思路,我可以先从我公司门口的食堂说起,一般食堂都有固定的菜色,因为烧同样的东西处理能力强、成本低,而如果为每一个顾客单独炒菜,那么成本就会高很多。

云云:你这个跑题有点远啊!

恋恋:所以作为顾客,我们一般几个人都点相同的菜,这样厨子烧的快,无论从配菜,到烧菜都会并行处理。总的来说就是,如果每个人都要不同的东西,会让一个饭店很忙,处理能力降低,而如果要的东西类似,那么就会极大地提高处理效率,从而增加营业额。

云云:哎哟,貌似靠谱了。

恋恋:作为软件系统来说也是这样,如果每次对服务器发出的请求不同,那么服务器也会为每一个请求单独计算,从而会让服务器很忙,提高效率就是要让客户做的事情尽量相同,然后服务器就可以并行处理了。

云云:嗯,不错,不过有些不太专业。

恋恋:比如A和B做相同的请求,那么对于数据库来说查询的内容都相同,那么就可以只计算一次,然后内容就可以一次发给客户啦,就好像两个人都点宫保鸡丁炒饭一样,一次炒制,两盘出锅。

云云:虽然请求相同,但是可能因为业务不同而导致结果不同啊,比如A是管理员能看所有的记录,而B是普通用户只能看自己的记录!

恋恋:这个……

云云:那你觉得请求应该相同还是不相同呢?

恋恋:我觉得请求应该不同,因为你既然让我把脚本动起来,还给我说怎么做参数变量、处理业务,本质上就是要让每次输入的东西都不一样。

云云:没错,如果每次请求都一样,那么服务器会自动使用Cache机制,这也是一个使服务器提高处理能力的策略,当发现请求或者查询内容相同,系统会先从缓存(内存)中查找是否存在匹配的记录,如果有就返回,否则就执行一次,将结果存放入缓存,唯一特例就是所谓的要做及时查询,就是锁概念。

恋恋:嗯,我也听说过什么MemCache、PGA&SGA还有啥JVM内存管理,都是和缓存有关系,锁这个概念我就不太懂了。

云云:锁这个概念怎么说呢,这样吧,你知道12306买火车票难吧。

恋恋:知道啊,不知道谁做那么差个系统,查个火车票都经常刷不出来。

云云:这就叫做外行看热闹,内行看门道。其实做火车订票系统是很难的,因为查票是及时的,要锁定票。

恋恋:Go on!

云云:每当一张票被订的时候,所有的查询都要得到全新的少了一张票的情况,所有的订票都要告诉别人这个位置的这个票已经被订了。所以当成千上万的人去买票的时候,一张票被锁定会影响几万个查询,每次查询都不能用Cache,否则会得到错误的信息,你明明看到这个票有,但是订的时候却失败。

恋恋:Go on!

云云:这里面还有更复杂的业务,比如从上海到北京的高铁,如果我订了一张从南京到天津的票,就意味着会多一张上海到南京的票,还有一张从天津到北京的票!

恋恋:那么怎么优化呢?

云云:很简单,首先不要做及时查询,例如不要直接给每个客户看有多少张剩票,其次当一张票订了后,不要立即计算出可能导致生成的部分路程的票,最后将坐全程的票和坐半程的票位置分开做表分离,这样就算买了半程票影响的记录会比较少,处理起来相对简单,让专门的服务器去处理多程票!

恋恋:来吃个梨,你看又进入状态了吧,后面一个人就亢奋的说啊说啊,完全不管别人懂不懂。

云云:真是好心没有好报,看在你给我削梨的举动上就原谅你了。睡觉前是不是可以做第二个性能测试案例了啊。

恋恋:今天晚上要做啥啊?

云云:做一个脚本比较一下点击相同的帖子和点击不同的帖子的性能有何区别!

恋恋:好,开工。

**小结
理解动态访问会带来的负载点及系统处理业务的逻辑概念。
录制脚本运行
**
恋恋:打开LR启动VuGen录制一个脚本。

云云:别忘了你首先要有那么多帖子,否则你查询不到。

恋恋:对,那么先录一个生成帖子的脚本吧。

(几分钟过去后)

恋恋:脚本生成。

Action()
{
    int i;
    web_add_cookie("38We_2132_sid=NDgF6W; DOMAIN=127.0.0.1");
    web_add_cookie("38We_2132_lastvisit=1462200716; DOMAIN=127.0.0.1");
    web_add_cookie("38We_2132_lastact=1462204316%09home.php%09misc; DOMAIN=127.0.0.1");
    web_add_cookie("38We_2132_onlineusernum=1; DOMAIN=127.0.0.1");
    web_add_cookie("38We_2132_sendmail=1; DOMAIN=127.0.0.1");
    web_url("discuz", 
        "URL=http://127.0.0.1/discuz/", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t2.inf", 
        "Mode=HTML", 
        EXTRARES, 
            "Url=static/image/common/background.png", "Referer=http://127.0.0.1/discuz/forum. php", ENDITEM, 
              "Url=static/image/common/search.gif", "Referer=http://127.0.0.1/discuz/forum.php", ENDITEM, 
              "Url=static/image/common/chart.png", "Referer=http://127.0.0.1/discuz/forum.php", ENDITEM, 
              "Url=static/image/common/px.png", "Referer=http://127.0.0.1/discuz/forum.php", ENDITEM, 
              "Url=static/image/common/qmenu.png", "Referer=http://127.0.0.1/discuz/forum.php", ENDITEM, 
              "Url=static/image/common/nv.png", "Referer=http://127.0.0.1/discuz/forum.php", ENDITEM, 
              "Url=static/image/common/titlebg.png", "Referer=http://127.0.0.1/discuz/forum. php", ENDITEM, 
        "Url=static/image/common/nv_a.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/cls.gif", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        LAST);
    web_submit_data("member.php", 
        "Action=http://127.0.0.1/discuz/member.php?mod=logging&action=login&loginsubmit   
              =yes&infloat=yes&inajax=1", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t3.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=fastloginfield", "Value=username", ENDITEM, 
        "Name=username", "Value=admin", ENDITEM, 
        "Name=password", "Value=123456", ENDITEM, 
        "Name=quickforward", "Value=yes", ENDITEM, 
        "Name=handlekey", "Value=ls", ENDITEM, 
        "Name=questionid", "Value=0", ENDITEM, 
        "Name=answer", "Value=", ENDITEM, 
        LAST);
    web_add_cookie("38We_2132_lastact=1462204476%09forum.php%09; DOMAIN=127.0.0.1");
    web_url("forum.php", 
        "URL=http://127.0.0.1/discuz/forum.php", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t4.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=uc_server/images/noavatar_small.gif", ENDITEM, 
        "Url=static/image/common/user_online.gif", ENDITEM, 
        "Url=static/image/common/arrwd.gif", ENDITEM, 
        LAST);
    web_add_cookie("38We_2132_checkpm=1; DOMAIN=127.0.0.1");
    web_add_cookie("38We_2132_smile=1D1; DOMAIN=127.0.0.1");
    web_url("默认版块", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t5.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=data/cache/style_1_forum_moderator.css?z69", "Referer=http://127.0.0.1/   
              discuz/forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/smile.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/sad.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/cry.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/biggrin.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/shocked.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/huffy.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/shy.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/tongue.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/mad.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/titter.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/sweat.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/loveliness.gif", "Referer=http://127.0.0.1/   
              discuz/forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/funk.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/lol.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/curse.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/hug.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/sleepy.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/time.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/dizzy.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/shutup.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/victory.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/kiss.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/call.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/smiley/default/handshake.gif", "Referer=http://127.0.0.1/   
              discuz/forum.php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pt_icn.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_r.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/fav.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_l.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/feed.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pt_item.png", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/recyclebin.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/atarget.png", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/editor/editor.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/mdly.png", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pollsmall.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=forumdisplay&fid=2", ENDITEM, 
        LAST);
    web_add_cookie("38We_2132_editormode_e=1; DOMAIN=127.0.0.1");
    web_url("高级模式", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=post&action=newthread&fid=2", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "Snapshot=t6.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/card_btn.png", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=post&action=newthread&fid=2", ENDITEM, 
        "Url=static/image/common/notice.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=post&action=newthread&fid=2", ENDITEM, 
        "Url=static/image/common/upload.swf?site=/discuz/misc.php%3fmod=swfupload%26type   
              =image%26fid=2&type=image&random=O2WM", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod =post&action=newthread&fid=2", ENDITEM, 
        "Url=static/image/common/upload.swf?site=/discuz/misc.php%3fmod=swfupload%26fid   
              =2&random=pm3E", "Referer=http://127.0.0.1/discuz/forum.php?mod=post&action=   
              newthread&fid=2", ENDITEM, 
        LAST);
    for(i=0;i<1000;i++)
    {
    web_submit_data("forum.php_2", 
        "Action=http://127.0.0.1/discuz/forum.php?mod=post&action=newthread&fid=2&extra   
              =&topicsubmit=yes", 
        "Method=POST", 
        "TargetFrame=", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=post&action=newthread&fid=2", 
        "Snapshot=t7.inf", 
        "Mode=HTML", 
        ITEMDATA, 
        "Name=formhash", "Value=27ad1fe9", ENDITEM, 
        "Name=posttime", "Value=1462204484", ENDITEM, 
        "Name=wysiwyg", "Value=1", ENDITEM, 
        "Name=subject", "Value=第二天测试专用{topic}", ENDITEM, 
        "Name=message", "Value=美美狗代表云层天咨发帖了{topic}", ENDITEM, 
        "Name=save", "Value=", ENDITEM, 
        "Name=uploadalbum", "Value=", ENDITEM, 
        "Name=newalbum", "Value=", ENDITEM, 
        "Name=readperm", "Value=", ENDITEM, 
        "Name=price", "Value=", ENDITEM, 
        "Name=usesig", "Value=1", ENDITEM, 
        "Name=allownoticeauthor", "Value=1", ENDITEM, 
        EXTRARES, 
        "Url=uc_server/images/noavatar_middle.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=data/cache/style_1_forum_viewthread.css?z69", "Referer=http://127.0.0.1/   
              discuz/forum.php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/js/forum_viewthread.js?z69", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=868&extra=", ENDITEM, 
        LAST);
    }
    web_custom_request("home.php", 
        "URL=http://127.0.0.1/discuz/home.php?mod=spacecp&ac=pm&op=checknewpm&rand   
              =1462204515", 
        "Method=GET", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=viewthread&tid=868&extra=", 
        "Snapshot=t8.inf", 
        "Mode=HTML", 
        "EncType=application/x-www-form-urlencoded", 
        EXTRARES, 
        "Url=static/image/common/flbg.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/rec_add.gif", "Referer=http://127.0.0.1/discuz/forum.  
              php? mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/oshr.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/rec_subtract.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/fastreply.gif", "Referer=http://127.0.0.1/discuz/ forum.  
              php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/midavt_shadow.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/repquote.gif", "Referer=http://127.0.0.1/discuz/ forum.  
              php?mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/edit.gif", "Referer=http://127.0.0.1/discuz/ forum.php?  
              mod=viewthread&tid=868&extra=", ENDITEM, 
        "Url=static/image/common/popupcredit_bg.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=868&extra=", ENDITEM, 
        LAST);
    return 0;
}

恋恋:这里我用了一个循环,做了1000次。

云云:那么你发帖的那个参数是?

恋恋:{topic}啊,这是我定义的一个时间参数,这样每次帖子都不一样,如图2-23所示。


22e7ba550c6d943340b58b55639124aac2b262f3

云云:哎哟,不错哦。

恋恋:好了,单击运行,我去给你削个梨。

云云:好!不过,如果你用场景,运行会快一些。

恋恋:好啊,你自己削梨去,EQ真低。

云云:我错了,还是你帮我削吧。

(几分钟后,帖子生成)如图2-24所示。


6ff47e29ed6b3692189540fa54e22f2d4c3565f9

恋恋:接着我要录制一个用户随机访问帖子的脚本和一个用户访问一个固定帖子的脚本。
Action()
{
    web_url("discuz", 
        "URL=http://127.0.0.1/discuz/", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/background.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/search.gif", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/nv.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/px.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/titlebg.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/nv_a.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/qmenu.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/chart.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        LAST);
    lr_think_time(5);
    web_url("默认版块", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t2.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/pt_icn.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pt_item.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arrwd.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/fav.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/feed.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_l.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_r.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/atarget.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/editor/editor.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        LAST);
    lr_think_time(4);
    web_url("第二天测试专用2016-05-03 00:09:10.850", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=viewthread&tid=1867&extra=page%3D1", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "Snapshot=t3.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=uc_server/images/noavatar_middle.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/oshr.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_add.gif", "Referer=http://127.0.0.1/discuz/forum.  
              php? mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/midavt_shadow.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/fastreply.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_subtract.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/flbg.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/repquote.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        LAST);
    return 0;
}

恋恋:找到看帖请求的那个函数,然后将这个请求内容做一个参数化,参数名称叫作tid,并且设置从1~1000的随机数,如图2-25所示。


387ef287a655181cd1840368ba7f9852fbc1eae7
Action()
{
    web_url("discuz", 
        "URL=http://127.0.0.1/discuz/", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/background.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/search.gif", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/nv.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/px.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/titlebg.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/nv_a.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/qmenu.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/chart.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        LAST);
    lr_think_time(5);
    web_url("默认版块", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t2.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/pt_icn.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pt_item.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arrwd.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/fav.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/feed.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_l.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_r.gif", "Referer=http://127.0.0.1/discuz/ forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/atarget.png", "Referer=http://127.0.0.1/discuz/forum.  
              php? mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/editor/editor.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        LAST);
    lr_think_time(4);
    web_url("第二天测试专用2016-05-03 00:09:10.850", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=viewthread&tid={tid}&extra=page%3D1", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "Snapshot=t3.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=uc_server/images/noavatar_middle.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/oshr.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_add.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/midavt_shadow.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/fastreply.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_subtract.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/flbg.gif", "Referer=http://127.0.0.1/discuz/forum. php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/repquote.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        LAST);
    return 0;
}

恋恋:最后还要在查询前后加个事务,让脚本运行的时候能够统计响应时间,先来试着运行一下。

Action()
{
    web_url("discuz", 
        "URL=http://127.0.0.1/discuz/", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=", 
        "Snapshot=t1.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/background.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/search.gif", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/nv.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/px.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/titlebg.png", "Referer=http://127.0.0.1/discuz/forum.   
              php", ENDITEM, 
        "Url=static/image/common/nv_a.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/qmenu.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        "Url=static/image/common/chart.png", "Referer=http://127.0.0.1/discuz/forum.php",   
              ENDITEM, 
        LAST);
    lr_think_time(5);
    web_url("默认版块", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php", 
        "Snapshot=t2.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=static/image/common/pt_icn.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/pt_item.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arrwd.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/fav.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/feed.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_l.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/arw_r.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/common/atarget.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        "Url=static/image/editor/editor.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=forumdisplay&fid=2", ENDITEM, 
        LAST);
    lr_think_time(4);
    lr_start_transaction("viewtopic");
    web_url("第二天测试专用2016-05-03 00:09:10.850", 
        "URL=http://127.0.0.1/discuz/forum.php?mod=viewthread&tid={tid}&extra=page%3D1", 
        "TargetFrame=", 
        "Resource=0", 
        "RecContentType=text/html", 
        "Referer=http://127.0.0.1/discuz/forum.php?mod=forumdisplay&fid=2", 
        "Snapshot=t3.inf", 
        "Mode=HTML", 
        EXTRARES, 
        "Url=uc_server/images/noavatar_middle.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/oshr.png", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_add.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/midavt_shadow.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/fastreply.gif", "Referer=http://127.0.0.1/discuz/ forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/rec_subtract.gif", "Referer=http://127.0.0.1/discuz/   
              forum.php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/flbg.gif", "Referer=http://127.0.0.1/discuz/forum.php?   
              mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        "Url=static/image/common/repquote.gif", "Referer=http://127.0.0.1/discuz/forum.   
              php?mod=viewthread&tid=1867&extra=page%3D1", ENDITEM, 
        LAST);
lr_end_transaction("viewtopic", LR_AUTO);
    return 0;
}

恋恋:代码运行大功告成!

云云:值得表扬!

(分别运行未参数化和参数化过的脚本)。

恋恋:好像查询条件是随机的会慢一点。

云云:Go On。

恋恋:OK,搞定两个脚本,一个是原脚本,查询条件不变的;还有一个是查询条件是随机的内容,接着分别到场景里面去运行一下。

恋恋:场景里面要添加监控内容(Windows资源),单击开始运行。

相关实践学习
通过性能测试PTS对云服务器ECS进行规格选择与性能压测
本文为您介绍如何利用性能测试PTS对云服务器ECS进行规格选择与性能压测。
相关文章
|
6月前
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
Mybatis+mysql动态分页查询数据案例——测试类HouseDaoMybatisImplTest)
|
6月前
|
Java 关系型数据库 数据库连接
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
Mybatis+MySQL动态分页查询数据经典案例(含代码以及测试)
|
6月前
|
Java 编译器
Java注解案例-简单测试框架
Java注解案例-简单测试框架
47 0
|
1月前
|
分布式计算 大数据 Spark
大数据-95 Spark 集群 SparkSQL Action与Transformation操作 详细解释与测试案例(二)
大数据-95 Spark 集群 SparkSQL Action与Transformation操作 详细解释与测试案例(二)
39 1
|
2月前
|
前端开发 机器人 测试技术
【RF案例】Web自动化测试弹窗处理
在进行Web自动化测试时,常会遇到不同类型的弹窗,如ajax、iframe、新窗口及alert/Confirm等。这些弹窗可通过Selenium进行定位与处理。其中,ajax弹窗直接定位处理;iframe需先选中再操作;新窗口类似iframe处理;而alert/Confirm则需特殊方法应对。在Robot Framework中,需先定义并获取窗口后使用特定关键字处理。此外,还有部分div弹窗需在消失前快速定位。希望本文能帮助大家更好地处理各类弹窗。
41 6
【RF案例】Web自动化测试弹窗处理
|
1月前
|
存储 SQL 分布式计算
大数据-95 Spark 集群 SparkSQL Action与Transformation操作 详细解释与测试案例(一)
大数据-95 Spark 集群 SparkSQL Action与Transformation操作 详细解释与测试案例(一)
37 0
|
5月前
|
测试技术 Windows
软件测试之 性能测试 性能测试基础指标 Loadrunner、Jmeter等工具(下)
软件测试之 性能测试 性能测试基础指标 Loadrunner、Jmeter等工具(下)
71 2
|
5月前
|
测试技术 程序员
软件测试之 性能测试 性能测试基础指标 Loadrunner、Jmeter等工具(上)
软件测试之 性能测试 性能测试基础指标 Loadrunner、Jmeter等工具(上)
98 1
支付系统---微信支付14----创建案例项目---介绍,第二步引入Swagger,接口文档和测试页面生成工具,定义统一结果的目的是让结果变得更加规范,以上就是谷粒项目的几个过程
支付系统---微信支付14----创建案例项目---介绍,第二步引入Swagger,接口文档和测试页面生成工具,定义统一结果的目的是让结果变得更加规范,以上就是谷粒项目的几个过程
|
5月前
|
安全 测试技术
软件测试项目式学习二(认识软件测试及软件测试分类与案例分析)
软件测试项目式学习二(认识软件测试及软件测试分类与案例分析)
81 1