Re: How to record aggregate latency from concurrent threads?
Darren Ball <[email protected]> Wed, 31 Aug 2016 15:21:53 -0400
| Newsgroups | gmane.comp.java.grinder.user |
|---|---|
| Message-ID | <CA+YPNhc445JY3VdQWZVE+UbHC5BXTkBvqo7VxXiZJyjR+ng=qw@mail.gmail.com> |
--===============6212968986273608389== Content-Type: multipart/alternative; boundary=001a114a9622b857c1053b630373 --001a114a9622b857c1053b630373 Content-Type: text/plain; charset=UTF-8 Would be really interesting to see a full working version of this script Marc. Maybe you could add something like this to the script gallery? On Wed, Aug 31, 2016 at 11:55 AM, Marc Holden <[email protected]> wrote: > 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 >> > > ------------------------------------------------------------ > ------------------ > > _______________________________________________ > grinder-use mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/grinder-use > > --001a114a9622b857c1053b630373 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr">Would be really interesting to see a full working version = of this script Marc.=C2=A0 Maybe you could add something like this to the s= cript gallery?</div><div class=3D"gmail_extra"><br><div class=3D"gmail_quot= e">On Wed, Aug 31, 2016 at 11:55 AM, Marc Holden <span dir=3D"ltr"><<a h= ref=3D"mailto:[email protected]" target=3D"_blank">[email protected]<= /a>></span> wrote:<br><blockquote class=3D"gmail_quote" style=3D"margin:= 0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir=3D"ltr">In= order to this you can't use python threading.=C2=A0 Instead, you need = to start a grinder worker process with a TestRunner class that has __call__= implemented in it.<div><br></div><div>We have done things similar to below= in the past to mimic async requests.<br><div><br></div><div><div>grinder.s= tartWorkerThread(<wbr>GenericTestRunner.TestRunner(<wbr>request=3DregisterR= eq, path=3D'registerVU&key=3D'+self.<wbr>key, verb=3D"POST= ", params=3DNone, withJson=3DFalse))</div><div><br></div><div>The __in= it__ method in the GenericTestRunner.TestRunning is below.=C2=A0 This takes= care of managing cookies that may be required by the server.=C2=A0 This wo= uld need to be modified to suite your needs as well as the implementation o= f 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, reque= st, path, params, cookies=3DNone, verb=3D'GET', withJson =3D False)= :</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0=C2=A0</div><div>=C2=A0 =C2=A0 =C2= =A0 =C2=A0 '''</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 Constructo= r</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 '''</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 CookieMo= dule.listAllCookies(<wbr>HTTPPluginControl.<wbr>getThreadHTTPClientContext(= ))</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__withJson =3D = withJson</div><div>=C2=A0 =C2=A0 =C2=A0 =C2=A0 self.__verb =3D verb</div><d= iv>=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.getPr= operties().<wbr>setInt('grinder.runs',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_quote"><div><div class=3D"h5"><div dir=3D"ltr">On Tue, Aug 30, 20= 16 at 6:50 PM Ahmad Alnafoosi <<a href=3D"mailto:[email protected]" t= arget=3D"_blank">[email protected]</a>> wrote:<br></div></div></div><= blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1px= #ccc solid;padding-left:1ex"><div><div class=3D"h5"> <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' 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.<wbr>net/g3/script-gallery.h= tml</a> =C2=A0</div><div><br></div><div>So I attempted to use concurrency w= ithin 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/<wbr>jytho= nbook/en/1.0/Concurrency.<wbr>html</a> =C2=A0</div><div><br></div><div>as f= ollows:=C2=A0</div><div><br></div><div><span style=3D"white-space:pre-wrap"= > </span>t1 =3D threading.Thread(target=3D<wbr>lambda:ObjList[0].GET())</di= v><div><span style=3D"white-space:pre-wrap"> </span>t2 =3D threading.Thread= (target=3D<wbr>lambda:ObjList[1].GET())</div><div><span style=3D"white-spac= e:pre-wrap"> </span>t1.start()</div><div><span style=3D"white-space:pre-wra= p"> </span>t2.start()</div><div><br></div><div><br></div><div>BUT It fails = with the following error</div><div>EngineException: net.grinder.engine.comm= on.<wbr>EngineException: Must be called from worker thread</div><div>=C2=A0= </div><div>When I call the same method without the Thread it works sequenti= ally (which I do not want)</div><div><br></div><div>Is there a better way ?= ?</div><div><br></div><div>thanks</div><div><br></div><div>Ahmad =C2=A0</di= v> </div></div></div></div> ------------------------------<wbr>------------------------------<wbr>-----= -------------<br> ______________________________<wbr>_________________<br> grinder-use mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">grin= [email protected]<wbr>net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D= "noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists/lis= tinfo/grinder-use</a><br> </blockquote></div> <br>------------------------------<wbr>------------------------------<wbr>-= -----------------<br> <br>______________________________<wbr>_________________<br> grinder-use mailing list<br> <a href=3D"mailto:[email protected]">[email protected]= ceforge.<wbr>net</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/grinder-use" rel=3D= "noreferrer" target=3D"_blank">https://lists.sourceforge.net/<wbr>lists/lis= tinfo/grinder-use</a><br> <br></blockquote></div><br></div> --001a114a9622b857c1053b630373-- --===============6212968986273608389== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------------ --===============6212968986273608389== 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 --===============6212968986273608389==--