使用IP欺騙Loadrunner並發測試小結


測試要求:
 
在本次測試中,我需要並發50個User,每一個User占用一個獨立的IP,並且只執行一次腳本。腳本中發起兩個請求,其中第一次請求返回200后才執行第二個請求。使用win7 OS。
 
前置及Generator設置:
我的Run-time Settings這樣設定:
Run Logic: Number of Iterations: 1 (保證只執行一次腳本)
Log: Enable Log. Always send messages.(不是只在出錯時發送log。我需要通過log來驗證我的測試要求是否達到)
Think Time: Ignore think time (我不要思考時間,我想第二個請求緊跟第一個請求后執行)
其他不變。
 
為了在同一台機器上跑50個IP,我使用IP Spoofing
在開始菜單,找到Loadruner所在文件夾,進去找到Tools,里面有一個IP Wizard(IP欺騙)
在創建新的IP之前,可以CMD查看ipconfig, 查看自己所在IP區間。使用IP欺騙時,需要使用空閑IP,為確保不影響公司網絡,建議使用一個路由器搭建獨立的IP區間。
我使用的IP區間為:
LAN Subnet : 192.168.32.0 / 23 (空閑IP區段:192.168.32.4 ~ 192.168.33.254)
Gateway : 192.168.32.1
到增加IP地址對話框時,注意配置是否正確。我的配置如下圖。
 
 
完成之后可以將剛才的IP地址保存為“IP Address File(*.ips)”文件。(這一操作我沒有做,還好Loadrunner已經非常智能,在Load Generators只增加localhost就可以搞定)
好了,在CMD查看ipconfig /all 是不是多了50個IP。
 
注意,IP Wizard不支持DHCP,需要本機配置為固定IP地址。
 
接下來寫腳本。
我的腳本如下:
 
 1 Action()  
 2 {  
 3 
 4     int status;  
 5     int HttpRetCode;
 6     char *ip;
 7     ip = lr_get_vuser_ip();
 8 //檢查Loadrunner Controller有沒有Enable IP Spoofing
 9     if(ip)
10         lr_output_message("The IP address is %s", ip);
11     else
12         lr_output_message("IP spoofing disabled");
13 //設置集合點,讓50個vuser一起發起第一個請求
14     lr_rendezvous("letusgo");
15 //開始第一個事務(請求)
16     lr_start_transaction("1stReq");  
17   
18     web_url("RCS_Initial_HTTP_Req",   
19 //這里有一個參數化,我要每一次傳遞給該參數一個唯一的msisdn號碼,並且只執行一次。
20 //我在參數屬性對話框里設置:Select next row -> Unique  
21 //                                          Update value on -> Once
22 "URL= http://xxx.yyy.com/self?x-forwarding-msisdn={NewParam}", 23 "TargetFrame=Main", 24 "Resource=0", 25 "RecContentType=text/html", 26 "Mode=http", 27 LAST ); 28 //打印第一個請求的返回碼 29 HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); 30 lr_output_message("Response code:%d",HttpRetCode); 31 //檢查返回碼是否是200 32 if(HttpRetCode == 200){ 33 lr_end_transaction("1stReq", LR_PASS); 34 sleep(2000); 35 //開始第二個事務(請求) 36 lr_start_transaction("2ndReq"); 37 web_url("RCS_Initial_HTTP_Req", 38 "URL= https://xxx.yyy.com/self?vers=1&IMSI=1&rcs_version=1&rcs_profile=1&client_vendor=1&client_version=1&terminal_vendor=1&terminal_model=1&terminal_sw_version=1&IMEI=1&mock_scheme=HTTPS", 39 "TargetFrame=Main", 40 "Resource=0", 41 "RecContentType=text/html", 42 "Mode=http", 43 LAST ); 44 //打印第二個請求的返回碼 45 HttpRetCode = web_get_int_property(HTTP_INFO_RETURN_CODE); 46 lr_output_message("Response code:%d",HttpRetCode); 47 //檢查返回碼是否是200 48 //結束第二個事務(請求) 49 if(HttpRetCode == 200){ 50 lr_end_transaction("2ndReq", LR_PASS); 51 }else{ 52 lr_end_transaction("2ndReq", LR_FAIL); 53 } 54 55 return 0; }else{ 56 //結束第一個事務(請求) 57 lr_end_transaction("1stReq", LR_FAIL); 58 return 0; 59 } 60 } 61

 

 

場景設置:

 
 
 
添加Load Generator
Name: localhost
Platform: windows
添加這一條就可以了。
然后將狀態開啟為Ready
 
 
 

一定要注意每一個Vuser的IP是否是唯一的。雙擊下圖Scenario Groups里面的Group Name行可以打開每一個Vuser對應的Generator,查看其IP。

 

 
要監控一些服務器資源的資源如cpu,memory,disk,需要在controller里加入增加監控Unix Resources, 加入服務器地址。可以一次添加多個服務器。
 
前提:
需要關閉防火牆
需要在要監控的服務器上安裝rstatd組件
 
[ root@ ~]# service rstatd 
Usage: /etc/init.d/rstatd {start|stop|status|restart|reload|force-reload} 
[ root@~]# service rstatd status 
rpc.rstatd (pid 2650) is running... 
[ root@~]#
 
可能報的錯:
lr UNIX Resources. Cannot initialize the monitoring -47190
無法連接該服務器,請找公司OPS部門解決。我在測試中需要連接公司VPN服務器,在沒有連接之前就會報這個錯。
 
開始Run之前,別忘了log保存位置放到指定位置。在Results下面設置。
 
 
關於Result :
 
Graphs 右鍵 Add new items -> Add New Graph增加想要的圖表結果
Reports -> HTML Report.. 生成html報告
 
小心Scale陷阱 
要乘以前面的Scale值,才是真實結果。
 
結果分析參考:
UNIX counter Windows Counter Description
Average Load* N/A The sum of the number of processes waiting in the run queue plus the number currently executing.
Collision rate N/A The total number of network collisions/sec
Context switch rate System – Context Switches/sec The rate at which processors switch from executing one thread to another. High switch rates can indicate performance problems as servers juggle multiple running applications.
CPU utilisation %Processor Time The percentage of elapsed time that the process spends executing non-idle threads.
Disk traffic %Disk time The percentage of elapsed time that the disk(s) are  busy servicing read or write requests.
Incoming packets error rate Packets received errors The number of packets received containing errors that precvent them from being delivered to a higher OSI layer protocol.
Incoming packets rate Packets received/sec The number of packets received on the network interface
Interrupt rate Interrupts/sec Average rate at which the processor receives and services hardware interrupts. Processes generate an interrupt when they finish a task and need to report that fact to the CPU.
Outgoing packets error rate Packets outbound errors The number of packets that can’t be transmitted due to errors
Outgoing packets rate Packets sent / sec The rate at which packets are sent on the network interface
Page-in rate Pages Input/sec The rate at which pages are read from disk to resolve hard page faults. Hard page faults occur when a process refers to a page in virtual memory which is not in it’s working set or available elsewhere in physical memory and has to be read from disk.
Page-out rate Pages Output/sec The rate at which memory pages are written to disk to free up space in physical memory.
Paging rate Paging rate The rate at which pages are read from disk or written to disk.  This is the sum of Pages Input/sec and Pages Output/sec.
Swap-in rate N/A The number of pages read into memory per second
Swap-out rate N/A The number of pages written out of memory per second
System mode CPU utilization Processor – %Priviledged time The percentage of elapsed time that the processor spends executing user threads (i.e. running applications)
User mode CPU utilization Processor – %User time The percentage or elapsed time that the processor spends executing priviledged or system mode threads.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM