Discussion:
measuring time in "while" loop
BOLB (Bohdan L Bodnar)
2012-12-07 20:58:13 UTC
Permalink
Greetings!



Here is the problem:



I've HTTP-based API calls to a particular system. The system returns an error code that is either negative (for success) or greater than zero (indicating the requested operation has been started).

In the event the return code is greater than zero, I poll the system using a "while" loop. In one of the calls, I'm using the following in the "while" controller: ${__javaScript(${DEL_CAT1_STATUS} > 0)}. The portion of the script looks as follows:



WHILE CONTROLLER

HTTP REQUEST (this is the API call)

REGULAR EXPRESSION EXTRACTOR (to get "DEL_CAT1_STATUS")

DELAY



I want to measure the total time spent in this "while" loop (this is for statistical analysis). High accuracy isn't all that important - the loop will spin at least a dozen or so times and the delay probably swamp measurement error.



Any suggestions?



Thanks,



Bo




[LearnAboutUPI-icons-notrademrks]<http://www.panduit.com/upi>
[Panduit-logo-w-bp-notrademrks]<http://www.panduit.com/>
sebb
2012-12-08 01:23:54 UTC
Permalink
Post by BOLB (Bohdan L Bodnar)
Greetings!
I've HTTP-based API calls to a particular system. The system returns an error code that is either negative (for success) or greater than zero (indicating the requested operation has been started).
START = ${__time}
Post by BOLB (Bohdan L Bodnar)
WHILE CONTROLLER
HTTP REQUEST (this is the API call)
REGULAR EXPRESSION EXTRACTOR (to get “DEL_CAT1_STATUS”)
DELAY
ELAPSED = ${__longSum($__time,-${START})}
Post by BOLB (Bohdan L Bodnar)
I want to measure the total time spent in this “while” loop (this is for statistical analysis). High accuracy isn’t all that important – the loop will spin at least a dozen or so times and the delay probably swamp measurement error.
Any suggestions?
See above.

You could then log it using the log function or use it in a Java Sampler.

Or of course you could enclose the entire loop in a Transaction Controller.
BOLB (Bohdan L Bodnar)
2012-12-11 15:36:39 UTC
Permalink
Thank you, Sebb!

One more question: I want to store these times with timestamp (e.g., via the simple data writer). I don't see a way of doing this (this could be lack of my knowledge of jmeter's features). For example, if the loop spins X times, I want to store the starting time of the loop, the total time spent in the loop, and a predetermined label name for this loop. Any advice on how to do this is greatly appreciated.

Thank you, again,

Bo


-----Original Message-----
From: sebb [mailto:***@gmail.com]
Sent: Friday, December 07, 2012 7:24 PM
To: JMeter Users List
Subject: Re: measuring time in "while" loop
Post by BOLB (Bohdan L Bodnar)
Greetings!
I've HTTP-based API calls to a particular system. The system returns an error code that is either negative (for success) or greater than zero (indicating the requested operation has been started).
START = ${__time}
Post by BOLB (Bohdan L Bodnar)
WHILE CONTROLLER
HTTP REQUEST (this is the API call)
REGULAR EXPRESSION EXTRACTOR (to get "DEL_CAT1_STATUS")
DELAY
ELAPSED = ${__longSum($__time,-${START})}
Post by BOLB (Bohdan L Bodnar)
I want to measure the total time spent in this "while" loop (this is for statistical analysis). High accuracy isn't all that important - the loop will spin at least a dozen or so times and the delay probably swamp measurement error.
Any suggestions?
See above.

You could then log it using the log function or use it in a Java Sampler.

Or of course you could enclose the entire loop in a Transaction Controller.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@jmeter.apache.org
For additional commands, e-mail: user-***@jmeter.apache.org
sebb
2012-12-11 20:01:22 UTC
Permalink
Post by sebb
use it in a Java Sampler.
BOLB (Bohdan L Bodnar)
2012-12-11 23:27:59 UTC
Permalink
I'm doing something incorrectly, but I cannot figure out what:

1). A "User Parameter" block is used to assign the system to variable "START" using ${__time(,)} at the beginning of the loop and the same is done to variable "END" at the end of the loop.

2). A Beanshell Sampler is used to write to a file; the sample code is:

${__longSum(${END},-${START},output1)};
f = new FileOutputStream("c:\\file1.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(output1);

Upon execution, the following error message is received:

Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``0; f = new FileOutputStream("c:\file1.txt"); p = new PrintStream(f); this.interp . . . '' : Object constructor


What, if anything, am I doing incorrectly (btw, this is jmeter 2.8)?

Thanks,

Bo

-----Original Message-----
From: sebb [mailto:***@gmail.com]
Sent: Tuesday, December 11, 2012 2:01 PM
To: JMeter Users List
Subject: Re: measuring time in "while" loop
Post by sebb
use it in a Java Sampler.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@jmeter.apache.org
For additional commands, e-mail: user-***@jmeter.apache.org
sebb
2012-12-11 23:52:52 UTC
Permalink
Post by BOLB (Bohdan L Bodnar)
1). A "User Parameter" block is used to assign the system to variable "START" using ${__time(,)} at the beginning of the loop and the same is done to variable "END" at the end of the loop.
${__longSum(${END},-${START},output1)};
f = new FileOutputStream("c:\\file1.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(output1);
Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``0; f = new FileOutputStream("c:\file1.txt"); p = new PrintStream(f); this.interp . . . '' : Object constructor
What, if anything, am I doing incorrectly (btw, this is jmeter 2.8)?
Try using the Java sampler instead; it's much simpler.
Just reference the variable in the sample data or the label and it
will appear in the sample results.

Alternatively, see:

http://jmeter.apache.org/usermanual/listeners.html#sample_variables

which is simpler still
Post by BOLB (Bohdan L Bodnar)
Thanks,
Bo
-----Original Message-----
Sent: Tuesday, December 11, 2012 2:01 PM
To: JMeter Users List
Subject: Re: measuring time in "while" loop
Post by sebb
use it in a Java Sampler.
---------------------------------------------------------------------
---------------------------------------------------------------------
BOLB (Bohdan L Bodnar)
2012-12-12 15:29:13 UTC
Permalink
Thank you VERY much for your kind assistance, Sebb. I ended using the Transaction Controller suggestion - this resulted in a very simple mechanism for recording total time spent in the loop.

Best regards,

Bo


-----Original Message-----
From: sebb [mailto:***@gmail.com]
Sent: Tuesday, December 11, 2012 5:53 PM
To: JMeter Users List
Subject: Re: measuring time in "while" loop
Post by BOLB (Bohdan L Bodnar)
1). A "User Parameter" block is used to assign the system to variable "START" using ${__time(,)} at the beginning of the loop and the same is done to variable "END" at the end of the loop.
${__longSum(${END},-${START},output1)};
f = new FileOutputStream("c:\\file1.txt");
p = new PrintStream(f);
this.interpreter.setOut(p);
print(output1);
Response code: 500
Response message: org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``0; f = new FileOutputStream("c:\file1.txt"); p = new PrintStream(f); this.interp . . . '' : Object constructor
What, if anything, am I doing incorrectly (btw, this is jmeter 2.8)?
Try using the Java sampler instead; it's much simpler.
Just reference the variable in the sample data or the label and it will appear in the sample results.

Alternatively, see:

http://jmeter.apache.org/usermanual/listeners.html#sample_variables

which is simpler still
Post by BOLB (Bohdan L Bodnar)
Thanks,
Bo
-----Original Message-----
Sent: Tuesday, December 11, 2012 2:01 PM
To: JMeter Users List
Subject: Re: measuring time in "while" loop
Post by sebb
use it in a Java Sampler.
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: user-***@jmeter.apache.org
For additional commands, e-mail: user-***@jmeter.apache.org

Loading...