incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [4/8] git commit: Fixing a memory leak when large arguments are logged in request response logs.
Date Thu, 29 May 2014 21:16:14 GMT
Fixing a memory leak when large arguments are logged in request response logs.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/eed70bb6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/eed70bb6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/eed70bb6

Branch: refs/heads/console-v2
Commit: eed70bb6fc12265a3cd1754dd35e12f612190faf
Parents: 4090977
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu May 22 20:54:53 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu May 22 20:54:53 2014 -0400

----------------------------------------------------------------------
 .../java/org/apache/blur/utils/BlurUtil.java    | 27 +++++++++++++++++---
 1 file changed, 23 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eed70bb6/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
index 9a3cf78..a6eda0f 100644
--- a/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
+++ b/blur-core/src/main/java/org/apache/blur/utils/BlurUtil.java
@@ -159,14 +159,30 @@ public class BlurUtil {
   public static final Term PRIME_DOC_TERM = new Term(BlurConstants.PRIME_DOC, BlurConstants.PRIME_DOC_VALUE);
 
   static class LoggerArgsState {
-    public LoggerArgsState(int size) {
-      _buffer = new ResetableTMemoryBuffer(size);
-      _tjsonProtocol = new TJSONProtocol(_buffer);
-    }
+
+    private static final int MAX_BUFFER_SIZE = 16384;
+    private static final int MAX_BUILDER_SIZE = 16384;
 
     TJSONProtocol _tjsonProtocol;
     ResetableTMemoryBuffer _buffer;
     StringBuilder _builder = new StringBuilder();
+    final int _size;
+
+    LoggerArgsState(int size) {
+      _size = size;
+      _buffer = new ResetableTMemoryBuffer(_size);
+      _tjsonProtocol = new TJSONProtocol(_buffer);
+    }
+
+    void reset() {
+      if (_buffer.getArray().length >= MAX_BUFFER_SIZE) {
+        _buffer = new ResetableTMemoryBuffer(_size);
+        _tjsonProtocol = new TJSONProtocol(_buffer);
+      }
+      if (_builder.length() >= MAX_BUILDER_SIZE) {
+        _builder = new StringBuilder();
+      }
+    }
   }
 
   @SuppressWarnings("unchecked")
@@ -276,6 +292,9 @@ public class BlurUtil {
           }
           Histogram histogram = histogramMap.get(name);
           histogram.update((end - start) / 1000);
+          if (loggerArgsState != null) {
+            loggerArgsState.reset();
+          }
         }
       }
 


Mime
View raw message