目录
8)Loadrunner报错“Too many local variablesAction.c”解决方法
9)LoadRunner中获取Request、Response
1.背景
记录一些在LR使用中遇到的问题,或者容易忘记的性能测试的概念。记录了一段时间,积攒了一些问题。后面会持续更新
2. 问题
1) 为什么LR录制时间比浏览器看到的时间更长
参考:https://www.cnblogs.com/wuyepiaoxue/p/5661181.html
2)对时间的解释
- DNS Resolution:浏览访问一个网站的时候,一般用的是域名,需要DNS服务器把域名解析为IP地址,这个过程就是域名解析时间。
- Connection:解析出WebServer的IP地址后,浏览器请求被发送到了一个Web Server,然后浏览器和Web Server 之间需要建立一个初始化的HTTP连接,服务器端需要做两件事:一个是接收请求,二是分配进程。建立该连接的过程就是Connection
- First Buffer:建立连接后,从Web Server发出第一个数据包,进过网络传输到客户端,浏览器成功接收第一个字节的时间就是First Buffer。
- Receive:从浏览器接收第一个字节起,直到成功收到最后一个字节,下载完成为止。
- Client Time:请求在客户端浏览器延迟的时间。
3)什么是TTFB呢?
- TTFB (Time To First Byte),是最初的网络请求被发起到从服务器接收到第一个字节这段时间,它包含了 TCP连接时间,发送HTTP请求时间和获得响应消息第一个字节的时间。注意:网页重定向越多,TTFB越高,所以要减少重定向
- TTFB优化的方法有:
- 减少DNS查询
- 使用CDN
- 提早Flush
- 添加周期头
4)LR中获取当前系统时间的方法
参考: https://www.cnblogs.com/yezhaohui/p/3448618.html
5)思考时间
- 测试中应该尽量与用户场景接近,因此需要添加思考时间
- LR执行场景时,出现这样的场景:随着创建的记录增加,系统性能问题导致曾经能够通过的事务,因为超时而失败的情况。这里,采用增加think time的方式来避免这种情况发生。但这里只是解决了事务的通过,还是应该对这种超时做进一步分析和优化。
6)性能测试基本的一些概念
参考:https://www.jianshu.com/p/c6546679ecdc
7)LR破解失败
参考:https://www.cnblogs.com/fengfengyue/p/11677472.html
8)Loadrunner报错“Too many local variablesAction.c”解决方法
原因:由于Action中代码的变量个数超出了规定的范围,导致报错。一般不能超过50个变量声明。
解决方法:在VuGen中改变局部变量可以分配的最大内存(缺省为64K)
方法一:定义为全局变量
char body[100000];
Actions()
{
return 0;
}
方法二:使用malloc()来分配内存,但一定要记得free。
Actions()
{
char *body = (char *) malloc(100000);
free(body);
return 0;
}
如果在录制脚本后进行回放时报错,可以按照下面步骤进行配置:
If you have this problem replaying a large database script in LoadRunner 7.8 or above, immediately after recording.
a. Go to Tools -> Regenerate Vusers...
b. Click on 'Options...' to edit the recording options
c. Under General:
1. Script section, enable the option for "Split action section to functions by event".By default, this is not enabled and it has a value of "500". This option is useful for when the action section is rather large
2. Script and select "Maximum number of lines in action file", change the value to 30000 and regenerate again
参考:https://www.cnblogs.com/qmfsun/p/4488720.html
9)LoadRunner中获取Request、Response
Action(){
web_set_max_html_param_len("262144"); // 默认最大长度为256
web_reg_save_param("ResponseBody",
"LB=",
"RB=",
"Search=Body",
LAST);
web_save_header(REQUEST, "RequestHeader");// REQUEST为内置变量,保存请求的头信息,需在发送URL请求前注册使用
web_save_header(RESPONSE, "ResponseHeader");// RESPONSE保存响应的头信息
web_url("foo",
"URL=<foo>", // 请求的URL
"Resource=0",
"RecContentType=text/html",
"Mode=HTTP",
LAST);
lr_output_message("# 请求头信息:\n %s", lr_eval_string("{RequestHeader}"));
lr_output_message("# 响应头信息:\n %s", lr_eval_string("{ResponseHeader}"));
lr_output_message("# 响应内容体:\n %s", lr_eval_string("{ResponseBody}"));
}
获取响应体:
{
// ......
web_reg_save_param("response",
"LB=",
"RB=",
"Search=Body",
LAST);
web_url("foo",
"URL=<url>", // 这里填写请求
"TargetFrame=",
"Resource=0",
"Mode=HTML",
LAST);
// ......
lr_output_message("response: %s", lr_eval_string("{response}"));
}
参考:http://www.51testing.com/html/87/n-857587.html
10)发送XML请求
{
// ......
web_custom_request("foo",
"URL=<url>", // 这里填写请求
"Method=<method>" // 方法
"TargetFrame=",
"Resource=0",
"RecContentType=application/xml;charset=utf-8",
"Mode=HTML",
"EncType=application/xml",
"Body=<xml>"
"<id>{id}</id>"
"<name>{name}</name>"
"</xml>",
LAST);
// ......
}
11)在Win12上使用LR测试数据库时报错
在Win12上使用LR11测试ORACLE,录制脚本时选择“Windows32 Application”,脚本录制和回放时OK,但在controller中运行时,出现错误。
报错内容:“Error (-81024): LR_VUG: The 'JDBC' type is not supported on 'WIN32' platforms”
解决方法:进入<LR安装目录>\HP\LoadRunner\bin,找到Wlrun.exe,点击 右键; 选择 属性;
勾选上“以兼容模式运行这个程序”,选择Windows7 or Windows XP,点击确定,重启LR。
https://blog.youkuaiyun.com/amy821551478/article/details/78058332/
12)运行JDBC测试时事务数显示为0
问题:在Win7上使用LR11测试ORACLE,录制脚本正常,场景中运行也正常,但右侧“通过事务数”显示为0。
解决方法:Run-time Settings-->General-->Miscellaneous->Automatic Transactions。选中“Define each action as a transaction”
https://blog.youkuaiyun.com/liangfengchang/article/details/45025055