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

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

问题描述

我最近开始对我的网络应用进行负载测试.

我使用了 apache 访问日志采样器.我跟着这个教程.

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

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

编辑 1
使用您的问题和屏幕截图中的数据,一切看起来都正常.关于 JMeter 延迟的一些事情(使用计时器).
- JMeter 将在请求之后(而不是在它之前)添加一个延迟
- Jmeter 将在服务器完成响应后开始延迟.

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

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

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

的延迟

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

这是代码(把它放在 beanshell 计时器的脚本部分):

rtime = Integer.parseInt(String.valueOf(prev.getTime()));//在第一次运行时会引发警告延迟 = Integer.parseInt(vars.get("delay"));整数睡眠 = 延迟 - rtime;log.info("睡眠时间" + sleep.toString() + "毫秒");返回睡眠;

编辑 3
如果 response_time > desired_delay 会怎样?
如果睡眠计算小于零,则不会中断.它只会休眠零毫秒.

如果现有请求尚未完成,仅使用一个线程就无法发出额外请求.从技术上讲,当一个线程不足以保持确切的延迟时,应该可以让不同的线程开始发出请求,但这需要线程内通信,这会很快变得非常混乱并且需要编写 beanshell 脚本.

I recently started load testing my webapp.

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

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

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

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.

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

Is it possible.

EDIT

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:

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

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

Now i added constant timer as shown in image:

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

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

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.

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

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

I deleted constant timer and added below bean shell timer.

This is the results table:

These are the log lines:

解决方案

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

You have two options:

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 tutorial:
http://www.youtube.com/watch?v=aEJNc3TW-g8

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.

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

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.

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.

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.

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}

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.

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;  

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.

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天全站免登陆