jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1418666 - /jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java
Date Sat, 08 Dec 2012 13:03:33 GMT
Author: pmouawad
Date: Sat Dec  8 13:03:30 2012
New Revision: 1418666

URL: http://svn.apache.org/viewvc?rev=1418666&view=rev
Log:
Bug 54268 - Improve memory usage

Bugzilla Id: 54268

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java?rev=1418666&r1=1418665&r2=1418666&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/extractor/RegexExtractor.java Sat Dec  8
13:03:30 2012
@@ -110,11 +110,11 @@ public class RegexExtractor extends Abst
         if (defaultValue.length() > 0){// Only replace default if it is provided
             vars.put(refName, defaultValue);
         }
-
-
+        Perl5Matcher matcher = JMeterUtils.getMatcher();
         String regex = getRegex();
+        Pattern pattern = JMeterUtils.getPatternCache().getPattern(regex, Perl5Compiler.READ_ONLY_MASK);
         try {
-            List<MatchResult> matches = processMatches(regex, previousResult, matchNumber,
vars);
+            List<MatchResult> matches = processMatches(pattern, regex, previousResult,
matchNumber, vars);
             int prevCount = 0;
             String prevString = vars.get(refName + REF_MATCH_NR);
             if (prevString != null) {
@@ -162,6 +162,22 @@ public class RegexExtractor extends Abst
             }
         } catch (MalformedCachePatternException e) {
             log.warn("Error in pattern: " + regex);
+        } finally {
+            clearMatcherMemory(matcher, pattern);
+        }
+    }
+
+    /**
+     * Hack to make matcher clean the two internal buffers it keeps in memory which size
is equivalent to 
+     * the unzipped page size
+     * @param matcher {@link Perl5Matcher}
+     * @param pattern Pattern
+     */
+    private final void clearMatcherMemory(Perl5Matcher matcher, Pattern pattern) {
+        try {
+            matcher.matches("", pattern); // $NON-NLS-1$
+        } catch (Exception e) {
+            // NOOP
         }
     }
 
@@ -180,13 +196,12 @@ public class RegexExtractor extends Abst
        return inputString;
     }
 
-    private List<MatchResult> processMatches(String regex, SampleResult result, int
matchNumber, JMeterVariables vars) {
+    private List<MatchResult> processMatches(Pattern pattern, String regex, SampleResult
result, int matchNumber, JMeterVariables vars) {
         if (log.isDebugEnabled()) {
             log.debug("Regex = " + regex);
         }
 
         Perl5Matcher matcher = JMeterUtils.getMatcher();
-        Pattern pattern = JMeterUtils.getPatternCache().getPattern(regex, Perl5Compiler.READ_ONLY_MASK);
         List<MatchResult> matches = new ArrayList<MatchResult>();
         int found = 0;
 



Mime
View raw message