天天看點

LoadRunner 技巧之思考時間設定

使用者通路某個網站或軟體,一般不會不停地做個各種操作,例如一次查詢,使用者需要時間檢視查詢的結果是否是自己想要的。例如一次訂單送出,使用者需要時間核對自己填寫的資訊是否正确等。

  打開loadrunner 的virtual user generator

  菜單欄:vuser ---run-time settings...,切換到thark time選項

LoadRunner 技巧之思考時間設定

  好吧!為了更好的了解這個界面上設定,現在我們通過一個腳本來分析。

action()

{

     double trans_time;  //定義變量

        "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",

    web_url("favicon.ico",

        "url=http://www.baidu.com/favicon.ico",

        "reccontenttype=image/x-icon",

        "snapshot=t3.inf",

    web_url("su",

        "url=http://suggestion.baidu.com/su?wd=&cb=window.bdsug.sugprerequest&sid=1466&t=1362316450913",

        "reccontenttype=baiduapp/json",

        "snapshot=t4.inf",

    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",

    web_url("favicon.ico_2",

        "url=https://passport.baidu.com/favicon.ico",

        "reccontenttype=application/octet-stream",

        "snapshot=t5.inf",

    web_link("注冊",

        "text=注冊",

        "snapshot=t6.inf",

    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",

        "reccontenttype=text/xml",

        "snapshot=t7.inf",

        "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,

    web_url("api",

        "url=https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1362316491971&class=reg&callback=bd__cbs__c93h6w",

        "referer=https://passport.baidu.com/v2/?reg&regtype=1&tpl=mn&u=http%3a%2f%2fwww.baidu.com%2f",

        "snapshot=t8.inf",

        "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,

    web_url("api_2",

        "url=https://passport.baidu.com/v2/api/?getapi&tpl=mn&apiver=v3&tt=1362316491978&class=regphone&callback=bd__cbs__xs2rv5",

        "snapshot=t9.inf",

        "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,

    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("注冊");  //獲得消耗時間

lr_end_transaction("注冊",lr_auto);  //事務結束

..........

  感謝上面這段代碼很好幫助我們了解思考時間。

  備注:添加思考時間可以更真實的模拟使用者行為,但它同時降低了使用者并發。也就是說思考時間越長,對伺服器的壓力會越小。

====================================分割線================================

最新内容請見作者的github頁:http://qaseven.github.io/

繼續閱讀