From: Kevin B. <kb...@ca...> - 2001-09-20 21:07:45
|
Here's a little sample code. --- from threading import Thread from time import time class Job( Thread ): def run( self ): v = 0L for i in xrange( 1, 200000 ): v = v + i self.value = v def _test( n=1 ): jobs = [] for i in range( n ): jobs.append( Job() ) start = time() map( Job.start, jobs ) map( Job.join, jobs ) t = time() - start print "%d: %.3f/%.3f" % (n, t, n and t/n) map( _test, range( 5 )) --- Note that the example above doesn't get a speedup from multiple threads, even on a two CPU box. Of course, if your threads are blocking on a JDBC call, you'll see a speedup... :-) <ObDisc> These are microbenchmarks are thus not worth the electrons it takes to view them. </ObDisc> Although Jython doesn't appear to have a "global interpreter lock" a la CPython, my 2-CPU NT box shows 1 CPU utilized for 1 thread, both CPUs fully utilized for two or more threads, but the times look like: 0: 0.000/0.000 1: 0.719/0.719 2: 1.656/0.828 3: 2.485/0.828 4: 3.329/0.832 So, more threads use more CPU, but are slightly slower, even on a two-CPU box. If you just run the 'run' method of all the jobs, instead of starting a new thread for each of them, you get better times: 0: 0.000/0.000 1: 0.656/0.656 2: 1.297/0.648 3: 1.953/0.651 4: 2.594/0.648 FWIW, the numbers for CPython are much worse (thank that global interpreter lock): 0: 0.000/0.000 1: 0.703/0.703 2: 5.360/2.680 3: 10.969/3.656 4: 11.656/2.914 CPython only uses one CPU, but still incurs the overhead of thread switching - not a pretty picture. These results were obtained on: Jython 2.1a1 on java1.3.0 (JIT: null) Sun JDK 1.3.0 WinNT 4.0 SP 6a 2x PIII 600 kb R Datta wrote: > > Hi all, > > I am working on a program to simulate stress testing (large number of > users) on JDBC connections. I would like to multithread the JDBC operations. > > I would appreciate some input (samples, tips etc) with anyone that has > tried multithreading within jython scripts. > > Thanks > Raj > > Thanks > Raj Datta > Professional Services Direct : 408-530-4932 > CrossAccess Corp Cell : 408-316-5473 > 2900 Gordon Ave #100 Fax : 408-735-0328 > Santa Clara CA 95051 Email : rd...@cr... > > _______________________________________________ > Jython-users mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-users |