Re: How to record aggregate latency from concurrent threads?

Marc Holden <[email protected]> Wed, 31 Aug 2016 15:55:33 +0000
Newsgroups gmane.comp.java.grinder.user
Message-ID <CADV_OVUf-kbEZZvjxGJFOVZNEOSMLS8RTOKrkN6f6OWq=xWi7Q@mail.gmail.com>
--===============7805033742975059345==
Content-Type: multipart/alternative; boundary=94eb2c05566a405814053b602149

--94eb2c05566a405814053b602149
Content-Type: text/plain; charset=UTF-8

In order to this you can't use python threading.  Instead, you need to
start a grinder worker process with a TestRunner class that has __call__
implemented in it.

We have done things similar to below in the past to mimic async requests.

grinder.startWorkerThread(GenericTestRunner.TestRunner(request=registerReq,
path='registerVU&key='+self.key, verb="POST", params=None, withJson=False))

The __init__ method in the GenericTestRunner.TestRunning is below.  This
takes care of managing cookies that may be required by the server.  This
would need to be modified to suite your needs as well as the implementation
of the __call__ method.

Hope this helps.

-Marc

def __init__(self, request, path, params, cookies=None, verb='GET',
withJson = False):

        '''
        Constructor
        '''
        self.__request = request
        self.path = path
        self.__params = params

        if cookies != None:
            self.__cookies = cookies
        if cookies == None and __RUN_WORKER_IN_SEP_PROCESS:
            self.__cookies =
CookieModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext())
            self.__withJson = withJson
        self.__verb = verb
        self.isDone = False

        grinder.getProperties().setInt('grinder.runs',1)


On Tue, Aug 30, 2016 at 6:50 PM Ahmad Alnafoosi <[email protected]>
wrote:

>
> Hi
> I am trying to create a Grinder script that captures the following latency
>
>
> 1- Basic scenario is one Agent/ one thread ( Complex Scenario Multiple
> Agents and multiple threads )
> 2- Start Timer
> 3- For each of [Specific List of URLs] send concurrent requests
>        -HTTP GET of the URL
> 4- When all the URLs' GET commands completes  Stop Timer.
> 5- Capture the time as aggregate GET latency.
>
>
> I was not able to find any similar example in the Scripts examples
> http://grinder.sourceforge.net/g3/script-gallery.html
>
> So I attempted to use concurrency within a worker
> http://www.jython.org/jythonbook/en/1.0/Concurrency.html
>
> as follows:
>
> t1 = threading.Thread(target=lambda:ObjList[0].GET())
> t2 = threading.Thread(target=lambda:ObjList[1].GET())
> t1.start()
> t2.start()
>
>
> BUT It fails with the following error
> EngineException: net.grinder.engine.common.EngineException: Must be called
> from worker thread
>
> When I call the same method without the Thread it works sequentially
> (which I do not want)
>
> Is there a better way ??
>
> thanks
>
> Ahmad
>
> ------------------------------------------------------------------------------
> _______________________________________________
> grinder-use mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/grinder-use
>

--94eb2c05566a405814053b602149
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">In order to this you can&#39;t use python threading.=C2=A0=
 Instead, you need to start a grinder worker process with a TestRunner clas=
s that has __call__ implemented in it.<div><br></div><div>We have done thin=
gs similar to below in the past to mimic async requests.<br><div><br></div>=
<div><div>grinder.startWorkerThread(GenericTestRunner.TestRunner(request=3D=
registerReq, path=3D&#39;registerVU&amp;key=3D&#39;+self.key, verb=3D&quot;=
POST&quot;, params=3DNone, withJson=3DFalse))</div><div><br></div><div>The =
__init__ method in the GenericTestRunner.TestRunning is below.=C2=A0 This t=
akes care of managing cookies that may be required by the server.=C2=A0 Thi=
s would need to be modified to suite your needs as well as the implementati=
on of the __call__ method.</div><div><br></div><div>Hope this helps.</div><=
div><br></div><div>-Marc</div><div><br></div><div><div>def __init__(self, r=
equest, path, params, cookies=3DNone, verb=3D&#39;GET&#39;, withJson =3D Fa=
lse):</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 &#39;&#39;&#39;</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Constru=
ctor</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 &#39;&#39;&#39;</div><div>=C2=A0=
 =C2=A0 =C2=A0 =C2=A0 self.__request =3D request</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 self.path =3D path</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self=
.__params =3D params</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=
=C2=A0 =C2=A0 =C2=A0 =C2=A0 if cookies !=3D None:</div><div>=C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__cookies =3D cookies</div><div>=C2=A0 =C2=
=A0 =C2=A0 =C2=A0 if cookies =3D=3D None and __RUN_WORKER_IN_SEP_PROCESS:</=
div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__cookies =3D Cooki=
eModule.listAllCookies(HTTPPluginControl.getThreadHTTPClientContext())</div=
><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__withJson =3D withJso=
n</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__verb =3D verb</div><div>=C2=
=A0 =C2=A0 =C2=A0 =C2=A0 self.isDone =3D False</div><div>=C2=A0 =C2=A0 =C2=
=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 grinder.getPropertie=
s().setInt(&#39;grinder.runs&#39;,1)</div></div><div>=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0=C2=A0</div></div></div></div><br><div class=3D"gmail_q=
uote"><div dir=3D"ltr">On Tue, Aug 30, 2016 at 6:50 PM Ahmad Alnafoosi &lt;=
<a href=3D"mailto:[email protected]">[email protected]</a>&gt; wrote:=
<br></div><blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;bord=
er-left:1px #ccc solid;padding-left:1ex">


<div><div dir=3D"ltr"><div><br></div><div>Hi=C2=A0</div><div>I am trying to=
 create a Grinder script that captures the following latency</div><div><br>=
</div><div><br></div><div>1- Basic scenario is one Agent/ one thread ( Comp=
lex Scenario Multiple Agents and multiple threads )</div><div>2- Start Time=
r</div><div>3- For each of [Specific List of URLs] send concurrent requests=
</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0-HTTP GET of the URL</div><div>4- Whe=
n all the URLs&#39; GET commands completes =C2=A0Stop Timer.=C2=A0</div><di=
v>5- Capture the time as aggregate GET latency.=C2=A0</div><div><br></div><=
div><br></div><div>I was not able to find any similar example in the Script=
s examples <a href=3D"http://grinder.sourceforge.net/g3/script-gallery.html=
" target=3D"_blank">http://grinder.sourceforge.net/g3/script-gallery.html</=
a> =C2=A0</div><div><br></div><div>So I attempted to use concurrency within=
 a worker=C2=A0</div><div><a href=3D"http://www.jython.org/jythonbook/en/1.=
0/Concurrency.html" target=3D"_blank">http://www.jython.org/jythonbook/en/1=
.0/Concurrency.html</a> =C2=A0</div><div><br></div><div>as follows:=C2=A0</=
div><div><br></div><div><span style=3D"white-space:pre-wrap">	</span>t1 =3D=
 threading.Thread(target=3Dlambda:ObjList[0].GET())</div><div><span style=
=3D"white-space:pre-wrap">	</span>t2 =3D threading.Thread(target=3Dlambda:O=
bjList[1].GET())</div><div><span style=3D"white-space:pre-wrap">	</span>t1.=
start()</div><div><span style=3D"white-space:pre-wrap">	</span>t2.start()</=
div><div><br></div><div><br></div><div>BUT It fails with the following erro=
r</div><div>EngineException: net.grinder.engine.common.EngineException: Mus=
t be called from worker thread</div><div>=C2=A0</div><div>When I call the s=
ame method without the Thread it works sequentially (which I do not want)</=
div><div><br></div><div>Is there a better way ??</div><div><br></div><div>t=
hanks</div><div><br></div><div>Ahmad =C2=A0</div> 		 	   		  </div></div>
---------------------------------------------------------------------------=
---<br>
_______________________________________________<br>
grinder-use mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">grin=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D=
"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo=
/grinder-use</a><br>
</blockquote></div>

--94eb2c05566a405814053b602149--


--===============7805033742975059345==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============7805033742975059345==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use

--===============7805033742975059345==--