flume-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bes...@apache.org
Subject flume git commit: FLUME-3020. Improve HDFS Sink escape sequence substitution
Date Wed, 09 Nov 2016 23:51:33 GMT
Repository: flume
Updated Branches:
  refs/heads/trunk f581f6ed0 -> 9868c4231


FLUME-3020. Improve HDFS Sink escape sequence substitution

When using escape sequences, the current code will call InetAddress
for every event which results in a huge impact to performance.

This patch fixes that issue by caching the local host in a static variable.
We can do this because there is zero chance the local host will change for a life of a JVM.

Reviewers: Hari Shreedharan, Jeff Holoman, Bessenyei Balázs Donát

(Theodore michael Malaska via Bessenyei Balázs Donát)


Project: http://git-wip-us.apache.org/repos/asf/flume/repo
Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/9868c423
Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/9868c423
Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/9868c423

Branch: refs/heads/trunk
Commit: 9868c4231362e5568a1675a604288d60cbadd7fe
Parents: f581f6e
Author: Theodore michael Malaska <ted.malaska@gmail.com>
Authored: Wed Nov 9 23:37:23 2016 +0000
Committer: Bessenyei Balázs Donát <bessbd@apache.org>
Committed: Wed Nov 9 23:37:23 2016 +0000

----------------------------------------------------------------------
 .../flume/formatter/output/BucketPath.java      | 50 ++++++++++++--------
 1 file changed, 31 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/flume/blob/9868c423/flume-ng-core/src/main/java/org/apache/flume/formatter/output/BucketPath.java
----------------------------------------------------------------------
diff --git a/flume-ng-core/src/main/java/org/apache/flume/formatter/output/BucketPath.java
b/flume-ng-core/src/main/java/org/apache/flume/formatter/output/BucketPath.java
index cf0fbb0..88a9166 100644
--- a/flume-ng-core/src/main/java/org/apache/flume/formatter/output/BucketPath.java
+++ b/flume-ng-core/src/main/java/org/apache/flume/formatter/output/BucketPath.java
@@ -218,25 +218,20 @@ public class BucketPath {
   @VisibleForTesting
   protected static String replaceStaticString(String key) {
     String replacementString = "";
-    try {
-      InetAddress addr = InetAddress.getLocalHost();
-      switch (key.toLowerCase()) {
-        case "localhost":
-          replacementString = addr.getHostName();
-          break;
-        case "ip":
-          replacementString = addr.getHostAddress();
-          break;
-        case "fqdn":
-          replacementString = addr.getCanonicalHostName();
-          break;
-        default:
-          throw new RuntimeException("The static escape string '" + key + "'"
-                  + " was provided but does not match any of (localhost,IP,FQDN)");
-      }
-    } catch (UnknownHostException e) {
-      throw new RuntimeException("Flume wasn't able to parse the static escape "
-              + " sequence '" + key + "' due to UnkownHostException.", e);
+    
+    switch (key.toLowerCase()) {
+      case "localhost":
+        replacementString = InetAddressCache.hostName;
+        break;
+      case "ip":
+        replacementString = InetAddressCache.hostAddress;
+        break;
+      case "fqdn":
+        replacementString = InetAddressCache.canonicalHostName;
+        break;
+      default:
+        throw new RuntimeException("The static escape string '" + key + "'"
+                + " was provided but does not match any of (localhost,IP,FQDN)");
     }
     return replacementString;
   }
@@ -548,5 +543,22 @@ public class BucketPath {
   public static Clock getClock() {
     return clock;
   }
+
+  private static final class InetAddressCache {
+    static String hostName = null;
+    static String hostAddress = null;
+    static String canonicalHostName = null;
+
+    static {
+      try {
+        InetAddress addr = InetAddress.getLocalHost();
+        hostName = addr.getHostName();
+        hostAddress = addr.getHostAddress();
+        canonicalHostName = addr.getCanonicalHostName();
+      } catch (UnknownHostException e) {
+        throw new RuntimeException("Unable to get localhost", e);
+      }
+    }
+  }
 }
 


Mime
View raw message