You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Sk...@londen-insurance.com on 2006/11/08 00:52:13 UTC

creating new threads dynamically at run-time




I am trying to figure out how to dynamically add a new thread to a test
plan at run-time using beanshell ( I'm guessing beanshell will be the
easiest way to accomplish this ).  From what I can tell, I need to create a
new JMeterThread and add it to the test plan's thread group.  The problem
is I can't find out how to expose the test's HashTree through beanshell.
It appears that it should be accessible via the jmctx variable in the
beanshell pre/postprocessors, but this jmctx doesn't seem to exist, or is
not actually a JMeterContext object.  I have successfully added a new
thread dynamically ( a normal thread, not a JMeterThread ), and it appears
to be executing the test plan, but this caused problems because the
listeners/engine were not updated to expect results from the new threads.
As a result of which, the results from the dynamically executed threads do
not appear in the visualizers/listeners.  So, here are my questions:

1) How do I access the JMeterContext/JMeterEngine/TestHashTree  through
beanshell?

2) How do I properly add a new JMeterThread to the thread group at
run-time?

3) How do I update all listeners to let them know that there is a new
thread they should be monitoring?

I am using JMeter 2.2.  This is a complicated load test, and I have tried
to figure out a way to do this using the existing JMeter components, but
unfortunately, it doesn't seem possible.  The reason they threads have to
be generated dynamically is because the users are organized hierarchically,
and the top users actions will affect an unknown number of unknown users
(at start time), and each user will that was affected by a high user will
need to login and go through the same test plan (this may, in turn, require
other additional users/threads go through the test plan).  Hints on adding
user-defined variables to JMeterThreads at creation time would also be very
useful.  Any help would be greatly appreciated.

Thanks,

Skyler Bingham
skyler.bingham@londen-insurance.com
(602) 957-1650 x1139
This e-mail and files transmitted with it are confidential, and are
intended solely for the use of the individual or entity to whom this e-mail
is addressed.  If you are not the intended recipient, or the employee or
agent responsible to deliver it to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this
communication is strictly prohibited.  If you are not one of the named
recipient(s) or otherwise have reason to believe that you received this
message in error, please immediately notify security@londen-insurance.com
 by e-mail, and destroy the original message.  Thank You.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: creating new threads dynamically at run-time

Posted by Sk...@londen-insurance.com.



UPDATE:

The answer to question #1 is via the 'ctx' variable that is exposed in
beanshell pre/postprocessors.  This variable is incorrectly labeled 'jmctx'
in the GUI, but when I took a look at the BeanShell function code, it
clearly showed that it was saving it as 'ctx'.  Unfortunately, the problem
now is that ctx.getEngine() returns null (which means you can't use the
engine to access the Test HashTree either).  According to the source, the
setEngine() method is never called on a JMeterContext object.  So this
method will not allow you to access the StandardJMeterEngine.

The answers to #2 and #3 are a bit trickier.  The StandardJMeterEngine is
responsible for creating and all threads and for notifying listeners for a
test .  This is all done in the run() method.  This appears to be the only
place where threads are added.  It does appear, however, that you should be
able to add new threads, as long as you update the appropriate maps that
are used to store the threads.  One obstacle to this approach is that all
the objects you need for the JMeterThread constructor are private members
of the StandardJMeterEngine class.  I was thinking I might be able to use
the Reflection API to access the private methods/member variables that I
need, but can find a way to get a reference to the engine object.  Any
ideas?

I beginning to think it may not be possible to add new threads dynamically
at run-time with out some custom hacks to the source.  Does anyone else
think that being able to add new threads dynamically might be useful?

Any advice would be appreciated.

Skyler Bingham
skyler.bingham@londen-insurance.com
(602) 957-1650 x1139

Skyler.Bingham@londen-insurance.com wrote on 11/07/2006 04:52:13 PM:

> 1) How do I access the JMeterContext/JMeterEngine/TestHashTree  through
> beanshell?
>
> 2) How do I properly add a new JMeterThread to the thread group at
> run-time?
>
> 3) How do I update all listeners to let them know that there is a new
> thread they should be monitoring?

This e-mail and files transmitted with it are confidential, and are
intended solely for the use of the individual or entity to whom this e-mail
is addressed.  If you are not the intended recipient, or the employee or
agent responsible to deliver it to the intended recipient, you are hereby
notified that any dissemination, distribution or copying of this
communication is strictly prohibited.  If you are not one of the named
recipient(s) or otherwise have reason to believe that you received this
message in error, please immediately notify security@londen-insurance.com
 by e-mail, and destroy the original message.  Thank You.


---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org