<br><font size=2 face="sans-serif">Hi,</font>
<br><font size=2 face="sans-serif">To achieve Parallel Batch / Query Execution,
we need to give execution tasks to separate threads.</font>
<br><font size=2 face="sans-serif">We could think of 2 options to achieve
it. Both of them have their pros and cons in terms of performance and ThreadLocal
variable management.</font>
<br>
<br><font size=2 face="sans-serif">1) New Thread Creation:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Pros:
We change the thread local variable to inheritable thread local and the
child thread automatically get the thread local values of the parent thread.</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Cons:
Creating new threads is not a good idea. Too many threads running in a
system should not be a problem though, as we can limit the number of Threads
created using java.util.concurrent.Semaphore/BigInteger etc.</font>
<br><font size=2 face="sans-serif">2) Thread Pool:</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Pros:
It would be faster (It looks like a valid assumption.)</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp; Cons:
&nbsp;We will have to do some manipulation to pass the thread local variables
to worker threads of Thread Pool. All ThreadLocal variables of a Thread
are stored in a ThreadLocalMap. Thread class does not provide getter/setter
for ThreadLocalMap. We could still get/set the ThreadLocalMap using reflection.
This solution is working fine.</font>
<br>
<br><font size=2 face="sans-serif">Is there any other option? If not, which
one of the above looks better approach to you?</font>
<br>
<br><font size=2 face="sans-serif">Please let us know your thoughts.</font>
<br><font size=2 face="sans-serif">Thanks and regards,</font>
<br><font size=2 face="sans-serif">Tushar</font>
<br><font size=2 face="sans-serif">&nbsp; </font>
<br>
<br>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>Tushar Apshankar &lt;tapshank@thoughtworks.com&gt;</b>
</font>
<br><font size=1 face="sans-serif">Sent by: mondrian-bounces@pentaho.org</font>
<p><font size=1 face="sans-serif">04/25/2007 06:27 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
Mondrian developer mailing list &lt;mondrian@pentaho.org&gt;</font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td><font size=1 face="sans-serif">Mondrian developer mailing list &lt;mondrian@pentaho.org&gt;</font>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td>
<tr valign=top>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td><font size=1 face="sans-serif">Re : [Mondrian] Multithreading, Parallel
Batch / Query Execution</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=2 face="sans-serif"><br>
Hi,</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
To improve performance, we started looking at ReentrantReadWriteLock and
ConcurrentHashMap (from java.util.concurrent) package.</font><font size=3>
</font><font size=2 face="sans-serif"><br>
We are also looking at ThreadPoolExecutor and related classes to implment
parallel query / batch execution (most of these classes are also available
in java.util.concurrent as well as backport jar).</font><font size=3> </font><font size=2 face="sans-serif"><br>
Since compatibility with Java 1.4 is essential, we started looking at the
build script retroweave target that uses Retroweaver 1.2.4.</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
Retroweaver without our changes works fine. We ran into problems while
using the current retroweaver version and build target after our changes.
</font><font size=3><br>
</font><font size=2 face="sans-serif"><br>
We have a simple class LockTest to reproduce the problem:</font><font size=3>
</font><font size=2 face="sans-serif"><br>
=============================================================================================</font><font size=3>
</font><font size=2 face="sans-serif"><br>
package mondrian;</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
import java.util.concurrent.ConcurrentHashMap;</font><font size=3> </font><font size=2 face="sans-serif"><br>
import java.util.concurrent.locks.ReentrantReadWriteLock;</font><font size=3>
</font><font size=2 face="sans-serif"><br>
import java.util.concurrent.locks.Lock;</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
public class LockTest {</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;ConcurrentHashMap&lt;String, String&gt; cache = new ConcurrentHashMap&lt;String,
String&gt;();</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;ReentrantReadWriteLock lock;</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;Lock r ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; &nbsp; &nbsp; <br>
 &nbsp; &nbsp;Lock w ;</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;public LockTest()</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;{</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;cache = new ConcurrentHashMap();</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;lock = new ReentrantReadWriteLock();</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;Before lock = &quot;
+ lock);</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;w = lock.writeLock();</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;r = lock.readLock();</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;After lock = &quot;
+ lock);</font><font size=3> </font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;}</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;public static void main(String[] args) {</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;LockTest lt = new LockTest();</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;System.out.println(&quot;i am inside main method&quot;);</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp;}</font><font size=3> </font><font size=2 face="sans-serif"><br>
}</font><font size=3> </font><font size=2 face="sans-serif"><br>
=============================================================================================</font><font size=3>
</font><font size=2 face="sans-serif"><br>
When we retroweave it with retroweaver 1.2.4 (using ANT as well as retroweaver
UI) and run the weaved class using Java 1.4.2, we get java.lang.NoSuchMethodError.
Stack is:</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
java.lang.NoSuchMethodError: edu.emory.mathcs.backport.java.util.concurrent.locks.ReentrantReadWriteLock.writeLock()</font><font size=3>
</font><font size=2 face="sans-serif"><br>
Ledu/emory/mathcs/backport/java/util/concurrent/locks/ReentrantReadWriteLock$WriteLock;</font><font size=3>
</font><font size=2 face="sans-serif"><br>
[Loaded java.lang.StackTraceElement from C:\j2sdk1.4.2_14\jre\lib\rt.jar]</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at mondrian.LockTest.&lt;init&gt;(LockTest.java:26)</font><font size=3>
</font><font size=2 face="sans-serif"><br>
 &nbsp; &nbsp; &nbsp; &nbsp;at mondrian.LockTest.main(LockTest.java:34):</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
We have backport jar in our class path (please note that we are NOT getting
ClassNotFoundExcecption).</font><font size=3> </font><font size=2 face="sans-serif"><br>
Did someone face this issue earlier? Please let us know if we are missing
something here.</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
We also tried out retroweaver 2.0 without success.</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
As an alternative, we tried Retrotranslator(http://retrotranslator.sourceforge.net)
and everything worked in first attempt. We propose to create a new target
for Retrotranslator and add the related libraries. Please let us know your
thoughts on this</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
Thanks and regards,</font><font size=3> </font><font size=2 face="sans-serif"><br>
Tushar, Ajit</font><font size=3> <br>
</font><font size=2><tt>_______________________________________________<br>
Mondrian mailing list<br>
Mondrian@pentaho.org<br>
http://lists.pentaho.org/mailman/listinfo/mondrian<br>
</tt></font>
<br>