LoadRunner提示:考慮時間設定

來源:互聯網
上載者:User

使用者訪問某個網站或軟體,一般不會不停地做個各種操作,例如一次查詢,使用者需要時間查看查詢的結果是否是自己想要的。例如一次訂單提交,使用者需要時間核對自己填寫的資訊是否正確等。

也就是說使用者在做某些操作時,是會有停留時間的,我把這個時間叫考慮時間。但利用代碼去執行的時候是沒有時間的,當然,指令碼運行本身是需要時間的,但比起人的考慮時間要小很多。這也是我們為什麼要用軟體來代替人的某些工作。

但有時候,我們在做效能測試時,為了更真實的類比使用者的操作,需要給代碼加入考慮時間。來看看在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;}

指令碼有點長,但不要被嚇到了,重要的幾句我已經加了注釋。你只用關注那幾行就行了。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.