如何根据访问日志行中存在的时间戳使jmeter执行日志重播 [英] How to make jmeter do log replay based on time stamps present in access log lines

查看:112
本文介绍了如何根据访问日志行中存在的时间戳使jmeter执行日志重播的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近开始对Web应用程序进行负载测试.

I recently started load testing my webapp.

我使用了apache访问日志采样器.我遵循了本教程.

I used apache access log sampler. I followed this tutorial.

https://jmeter.apache.org/usermanual/jmeter_accesslog_sampler_step_by_step.pdf

我能够使它工作.但是现在问题出在不到10分钟的时间内,我重播了所有的get请求.

I am able to make it work. But now the problem i replayed all the get requests in less than 10 mins.

我希望jmeter根据发布获取请求的时间戳来运行获取请求.

I want jmeter to run the get requests based on the time stamp at which the get request is posted.

我无法在线找到任何此类配置.

I am not able to find any such configuration online.

我可以编写脚本以在那个特定的时间戳卷曲获取请求.但是我想使用jmeter.

I can write script to curl the get request at that particular timestamp. But i want to use jmeter.

有可能.

编辑

我用以下几行创建了一个示例csv文件:

I created a sample csv file with below lines:

0,/myAPP/home
5000,/myAPP/home
5000,/myAPP/home

首先,我创建了一个线程组,如图所示:

First i created a thread group as shown in image:

在这里,我永远选择循环计数.如果未选中,则仅csv文件中的第一行正在运行.其余各行未运行.

Here i selected loop count forever. If not selected only first line in csv file is running.rest of the lines are not running.

现在我添加了csv数据集配置,如图所示:

Now i added csv data set config as shown in image:

现在我添加了常量计时器,如图所示:

Now i added constant timer as shown in image:

现在我添加了HTTP请求,如图所示: 我添加了视图结果树侦听器,然后单击播放按钮.

Now i added HTTP request as shown in image: I added view results tree listener and hit the play button.

当我看到每个样本的样本从视图开始在结果树中时,延迟与csv文件中存在的延迟不符.我在做什么错了.

When i see the sample start in view result tree for each of the samples, the delay is not according to the delay present in csv file. What am i doing wrong.

EDIT2 我将常量计时器设置为HTTP请求的子级.请在下面的屏幕快照中找到请求的时间.你看到什么地方了吗?

EDIT2 I made the constant timer as child of the HTTP request. Please find the timings of the requests in the below screen shot. Do you see anything wrong .

EDIT3

我遵循了bean shell timre方法,并且当延迟大于先前的响应时间时,它可以很好地工作.但是当先前的响应时间大于延迟时,它无法正常工作.

I followed bean shell timre approach and it worked fine when the delay is greater than previous response time. But it didnt work properly when previous response time is greater than delay.

我修改了csv文件如下(将延迟减少到100毫秒)

I modified the csv file as below ( reduced delay to 100 msec)

0,/myAPP/home
100,/myAPP/home
100,/myAPP/home

我删除了常量计时器,并在bean shell计时器下面添加了

I deleted constant timer and added below bean shell timer.

这是结果表:

以下是日志行:

推荐答案

开箱即用的访问日志采样器不适用于您要执行的操作.

The out of the box access log sampler won't work for what you're trying to do.

您有两个选择:

1-完成Jmeter之外的所有处理工作,并创建一个包含两个字段的CSV文件:URL和Delay,然后使用CSV数据集配置.

1 - Do all of the processing work outside of Jmeter and create a CSV file with two fields: URL and Delay and then use the CSV data set config.

Youtube JMeter CSV教程:
http://www.youtube.com/watch?v=aEJNc3TW-g8

Youtube JMeter CSV tutorial:
http://www.youtube.com/watch?v=aEJNc3TW-g8

2-在JMeter中进行处理.如果您是Java开发人员,则可以编写一个bean脚本来读取文件,并解析URL和时间戳并计算延迟.

2 - Do the processing within JMeter. If you're a Java developer you can write a beanshell script to read the file and parse out the URL and timestamp and calculate the delay.

这里是一个例子:
如何从.csv文件中读取字符串以及分开吗?

Here is an example:
How to read a string from .csv file and split it?

编辑1
使用问题和屏幕截图中的数据,一切看起来都很好. 关于JMeter延迟的两件事(使用计时器).
-JMeter将在请求之后添加延迟(不是在请求之前)
-服务器完成响应后,Jmeter将启动延迟.

EDIT 1
Using the data from your question and screenshot everything looks like it's working fine. A couple of things about JMeter delays (using timers).
- JMeter will add a delay AFTER the request (not before it)
- Jmeter will start the delay AFTER the server is done responding.

您的情况(我四舍五入到最接近的秒数):
最初的请求时间是12:59:53
+请求花了24.5秒
+ 0秒延迟
=下一个请求应该在13:00:18发生,这确实是下一个请求发生的时间.

In your case (I'm rounding to the nearest second):
Initial request at 12:59:53
+ Request took 24.5 seconds
+ 0 second delay
= next request should be at 13:00:18 which is indeed when the next request happened.

在13:00:18的第二个请求
+请求花费了1.8秒
+ 5秒延迟
=下一个请求应该在13:00:25,这实际上是下一个请求发生的时间.

Second request at 13:00:18
+ Request took 1.8 seconds
+ 5 second delay
= next request should be at 13:00:25 which is indeed when the next request happened.

我认为您想要的是下一个请求将不考虑响应时间.临时而言,您需要创建$ {delay}-$ {responseTime}

I think what you want is that the next request will NOT factor in the response time. Offhand, you'd need to create a delay of ${delay} - ${responseTime}

编辑2
为了创建一个会影响响应时间的延迟,您需要使用beanshell计时器而不是常量计时器.

EDIT 2
In order to create a delay that will factor in the response time you need to use the beanshell timer and not the constant timer.

这是代码(将其放入beanshell计时器的脚本部分):

Here is the code (put this in the script section of the beanshell timer):

rtime = Integer.parseInt(String.valueOf(prev.getTime())); // on first run will raise warning
delay = Integer.parseInt(vars.get("delay"));    

Integer sleep = delay - rtime;

log.info( "Sleep for " + sleep.toString() + " milli-seconds" );
return sleep;  

编辑3
如果response_time> required_delay怎么办?
如果睡眠计算小于零,则不会中断任何操作.它只会睡零毫秒.

EDIT 3
What if response_time > desired_delay?
If the sleep calculation is less than zero, nothing will break. It will just sleep for zero milliseconds.

只有一个线程,如果现有请求尚未完成,则无法发出其他请求.从技术上讲,当一个线程不足以保持确切的延迟时,应该有一个不同的线程开始发出请求,但这将需要线程内通信,这可能会很快变得非常混乱,并且需要bean脚本.

With just one thread there is no way to make an additional request if the existing request hasn't completed. Technically it should be possible to have a different thread start making requests when one thread isn't enough to keep the exact delays, but this would require intra-thread communication which can get very messy very quickly and requires beanshell scripting.

这篇关于如何根据访问日志行中存在的时间戳使jmeter执行日志重播的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆