jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1609915 - in /jmeter/trunk: src/functions/org/apache/jmeter/functions/Jexl2Function.java xdocs/changes.xml
Date Sat, 12 Jul 2014 13:30:52 GMT
Author: pmouawad
Date: Sat Jul 12 13:30:51 2014
New Revision: 1609915

URL: http://svn.apache.org/r1609915
Log:
Bug 56708 - __jexl2 doesn't scale with multiple CPU cores
Bugzilla Id: 56708

Modified:
    jmeter/trunk/src/functions/org/apache/jmeter/functions/Jexl2Function.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/functions/org/apache/jmeter/functions/Jexl2Function.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/functions/org/apache/jmeter/functions/Jexl2Function.java?rev=1609915&r1=1609914&r2=1609915&view=diff
==============================================================================
--- jmeter/trunk/src/functions/org/apache/jmeter/functions/Jexl2Function.java (original)
+++ jmeter/trunk/src/functions/org/apache/jmeter/functions/Jexl2Function.java Sat Jul 12 13:30:51
2014
@@ -24,10 +24,10 @@ import org.apache.commons.jexl2.Expressi
 import org.apache.commons.jexl2.JexlContext;
 import org.apache.commons.jexl2.JexlEngine;
 import org.apache.commons.jexl2.MapContext;
-
 import org.apache.jmeter.engine.util.CompoundVariable;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.testelement.ThreadListener;
 import org.apache.jmeter.threads.JMeterContext;
 import org.apache.jmeter.threads.JMeterContextService;
 import org.apache.jmeter.threads.JMeterVariables;
@@ -40,7 +40,7 @@ import org.apache.log.Logger;
  * @since 2.6
  */
 // For unit tests, see TestJexlFunction
-public class Jexl2Function extends AbstractFunction {
+public class Jexl2Function extends AbstractFunction implements ThreadListener {
 
     private static final Logger log = LoggingManager.getLoggerForClass();
 
@@ -48,13 +48,7 @@ public class Jexl2Function extends Abstr
 
     private static final List<String> desc = new LinkedList<String>();
 
-    // TODO should the engine be static?
-    private static final JexlEngine jexl = new JexlEngine();
-    static {
-       jexl.setCache(512);
-       jexl.setLenient(false);
-       jexl.setSilent(false);
-    }
+    private static final ThreadLocal<JexlEngine> threadLocalJexl = new ThreadLocal<JexlEngine>();
 
     static
     {
@@ -96,7 +90,7 @@ public class Jexl2Function extends Abstr
             jc.set("OUT", System.out);//$NON-NLS-1$
 
             // Now evaluate the script, getting the result
-            Expression e = jexl.createExpression( exp );
+            Expression e = getJexlEngine().createExpression( exp );
             Object o = e.evaluate(jc);
             if (o != null)
             {
@@ -113,6 +107,22 @@ public class Jexl2Function extends Abstr
         return str;
     }
 
+    /**
+     * Get JexlEngine from ThreadLocal
+     * @return JexlEngine
+     */
+    private static JexlEngine getJexlEngine() {
+        JexlEngine engine = threadLocalJexl.get();
+        if(engine == null) {
+            engine = new JexlEngine();
+            engine.setCache(512);
+            engine.setLenient(false);
+            engine.setSilent(false);
+            threadLocalJexl.set(engine);
+        }
+        return engine;
+    }
+    
     /** {@inheritDoc} */
     @Override
     public List<String> getArgumentDesc()
@@ -136,4 +146,17 @@ public class Jexl2Function extends Abstr
         values = parameters.toArray();
     }
 
+    @Override
+    public void threadStarted() {
+    }
+
+    @Override
+    public void threadFinished() {
+        JexlEngine engine = threadLocalJexl.get();
+        if(engine != null) {
+            engine.clearCache();
+            threadLocalJexl.remove();
+        }
+    }
+
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1609915&r1=1609914&r2=1609915&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml (original)
+++ jmeter/trunk/xdocs/changes.xml Sat Jul 12 13:30:51 2014
@@ -216,6 +216,7 @@ A workaround is to use a Java 7 update 4
 
 <h3>Functions</h3>
 <ul>
+<li><bugzilla>56708</bugzilla> - __jexl2 doesn't scale with multiple CPU
cores. Based on analysis and patch contributed by Mikhail Epikhin(epihin-m at yandex.ru)</li>
 </ul>
 
 <h3>I18N</h3>
@@ -249,6 +250,7 @@ A workaround is to use a Java 7 update 4
 <li>Emmanuel Bourg (ebourg at apache.org)</li>
 <li>Nicola Ambrosetti (ambrosetti.nicola at gmail.com)</li>
 <li><a href="http://ubikloadpack.com">Ubik Load Pack support</a></li>
+<li>Mikhail Epikhin (epihin-m at yandex.ru)</li>
 </ul>
 
 <br/>



Mime
View raw message