You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rp...@apache.org on 2016/03/30 16:39:11 UTC

logging-log4j2 git commit: LOG4J2-1339 AsyncLogger performance optimization: avoid calling instanceof TimestampMessage in hot path

Repository: logging-log4j2
Updated Branches:
  refs/heads/master 86f9ae344 -> 102090f2b


LOG4J2-1339 AsyncLogger performance optimization: avoid calling instanceof TimestampMessage in hot path


Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/102090f2
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/102090f2
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/102090f2

Branch: refs/heads/master
Commit: 102090f2b79d52866d21d0e64f6d44f8ad3d237f
Parents: 86f9ae3
Author: rpopma <rp...@apache.org>
Authored: Wed Mar 30 23:39:12 2016 +0900
Committer: rpopma <rp...@apache.org>
Committed: Wed Mar 30 23:39:12 2016 +0900

----------------------------------------------------------------------
 .../logging/log4j/core/async/AsyncLogger.java       | 16 ++--------------
 .../log4j/core/async/RingBufferLogEvent.java        |  3 ++-
 src/changes/changes.xml                             |  3 +++
 3 files changed, 7 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/102090f2/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
index f661648..4c590c1 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/AsyncLogger.java
@@ -35,7 +35,6 @@ import org.apache.logging.log4j.core.util.NanoClock;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.MessageFactory;
 import org.apache.logging.log4j.message.ReusableMessage;
-import org.apache.logging.log4j.message.TimestampMessage;
 import org.apache.logging.log4j.status.StatusLogger;
 
 import com.lmax.disruptor.EventTranslatorVararg;
@@ -198,7 +197,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
                 ThreadContext.getImmutableStack(), //
                 // location (expensive to calculate)
                 calcLocationIfRequested(fqcn), //
-                eventTimeMillis(message), //
+                CLOCK.currentTimeMillis(), //
                 nanoClock.nanoTime() //
         );
     }
@@ -223,17 +222,6 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
         return includeLocation ? Log4jLogEvent.calcLocation(fqcn) : null;
     }
 
-    private long eventTimeMillis(final Message message) {
-        // Implementation note: this method is tuned for performance. MODIFY WITH CARE!
-
-        // System.currentTimeMillis());
-        // CoarseCachedClock: 20% faster than system clock, 16ms gaps
-        // CachedClock: 10% faster than system clock, smaller gaps
-        // LOG4J2-744 avoid calling clock altogether if message has the timestamp
-        return message instanceof TimestampMessage ? ((TimestampMessage) message).getTimestamp() : CLOCK
-                .currentTimeMillis();
-    }
-
     /**
      * Enqueues the specified log event data for logging in a background thread.
      * <p>
@@ -290,7 +278,7 @@ public class AsyncLogger extends Logger implements EventTranslatorVararg<RingBuf
         final String threadName = THREAD_NAME_CACHING_STRATEGY.getThreadName();
         event.setValues(asyncLogger, asyncLogger.getName(), marker, fqcn, level, message, thrown, contextMap,
                 contextStack, currentThread.getId(), threadName, currentThread.getPriority(), location,
-                eventTimeMillis(message), nanoClock.nanoTime());
+                CLOCK.currentTimeMillis(), nanoClock.nanoTime());
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/102090f2/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
----------------------------------------------------------------------
diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
index 399c7a5..f3ad22f 100644
--- a/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
+++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/async/RingBufferLogEvent.java
@@ -32,6 +32,7 @@ import org.apache.logging.log4j.core.util.Constants;
 import org.apache.logging.log4j.message.Message;
 import org.apache.logging.log4j.message.ReusableMessage;
 import org.apache.logging.log4j.message.SimpleMessage;
+import org.apache.logging.log4j.message.TimestampMessage;
 import org.apache.logging.log4j.util.PropertiesUtil;
 import org.apache.logging.log4j.util.Strings;
 
@@ -299,7 +300,7 @@ public class RingBufferLogEvent implements LogEvent, ReusableMessage {
 
     @Override
     public long getTimeMillis() {
-        return currentTimeMillis;
+        return message instanceof TimestampMessage ? ((TimestampMessage) message).getTimestamp() :currentTimeMillis;
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/102090f2/src/changes/changes.xml
----------------------------------------------------------------------
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 2279cbe..eb204e4 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -24,6 +24,9 @@
   </properties>
   <body>
     <release version="2.6" date="2016-MM-DD" description="GA Release 2.6">
+      <action issue="LOG4J2-1339" dev="rpopma" type="fix">
+        AsyncLogger performance optimization: avoid calling instanceof TimestampMessage in hot path.
+      </action>
       <action issue="LOG4J2-1324" dev="rpopma" type="fix">
         Improve error handling in the Async Logger background thread: the new default exception handler no longer rethrows the error.
       </action>