51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 1357|回复: 0
打印 上一主题 下一主题

LoadRunner:Dynamically calculated Think Time

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2006-10-30 14:23:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Description

      a technique to pad a scripts execution time to a fixed duration


Solution

      Recently in order to meet a contractual requirement I had to execute a scenario in such a way that it was of fixed duration regardless of load. I couldn抰 find any obvious way to achieve this in LoadRunner and neither could the support desk, this forced me to get a little creative with the load runner function calls. Thought I抎 post my solution here in case it抯 of use to anyone else.

With this technique I couldn抰 randomize think time using the run time settings so I also had to generate this as well. With this code the mean script execution time was typically within 15ms of the target time.

double maxStepThinkTime = 5.000;
double minStepThinkTime = 2.500;
double target_time = 180.000;
double think_time;
double time_elapsed;
merc_timer_handle_t timer;
double wasted_time;
merc_timer_handle_t waste;


Script
{
/*
* Body of script wrapped in a timer as follows:
*/

timer = lr_start_timer();

Application抯 transactions go here?

/*
* Add some random think time.
*
* Time how long it takes to calculate the think time
* this is the recorded as wasted time.
*/
waste = lr_start_timer();

/*
* Compute think-time in the range minStepThinkTime to
* maxStepThinkTime, granularity is 1000th the difference
* between max & min values
*/

think_time = (minStepThinkTime + ((maxStepThinkTime - minStepThinkTime) * (rand() % 1000) / 1000));

/*
* Compute time taken to do above and record as wasted
* time
*/
wasted_time = lr_end_timer(waste);
lr_wasted_time(1000 * wasted_time);

/*
* Wait the determined amount of time.
*/
lr_think_time(think_time);
More Application transactions go here?

/*
* Pad transaction to fixed duration specified
* by target time.
*/

time_elapsed = lr_end_timer(timer);
think_time = target_time - time_elapsed;

lr_start_transaction("Padding");
if(think_time > 0)
{
lr_think_time(think_time);
}
lr_end_transaction("Padding", LR_AUTO);
I
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-24 05:29 , Processed in 0.062852 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表