2016-12-08 104 views
0

我正在嘗試使用JMSAppender log4j2向ActivMQ發送日誌。使用JMSAppender發送2000條消息log4j2

我做了以下的conf

<?xml version="1.0" encoding="UTF-8"?> 
<Configuration monitorInterval="5"> 
    <Appenders> 
     <Console name="STDOUT" target="SYSTEM_OUT"> 
      <PatternLayout 
       pattern="%d{HH:mm:ss.SSS} %highlight{[%-5p] %c{1.} - %m} %style{(%t)}{Cyan}%n" /> 
     </Console> 
     <RollingFile name="fish" fileName="E:/fish/log/fish.server/fish.log" 
      filePattern="/log/fish.server/fish-%-d{yyyy-MM-dd-HH}.log"> 
      <PatternLayout pattern="%-d{yyyy-MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n" /> 
      <Policies> 
       <TimeBasedTriggeringPolicy /> 
      </Policies> 
     </RollingFile> 

     <JMS name="jmsQueue" destinationBindingName="logQueue" 
      factoryName="org.apache.activemq.jndi.ActiveMQInitialContextFactory" 
      factoryBindingName="ConnectionFactory" providerURL="tcp://xxxxxx:61616"> 
      <PatternLayout pattern="%-d{yyyy-MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n" /> 
     </JMS> 

    </Appenders> 
    <Loggers> 

     <Logger name="jmsLogger" level="warn"> 
      <AppenderRef ref="jmsQueue" /> 
     </Logger> 

     <Root level="warn"> 
      <!-- <AppenderRef ref="STDOUT" /> --> 
      <AppenderRef ref="fish" /> 
     </Root> 
    </Loggers> 
</Configuration> 

在那之後,我有32個線程streamExecutor其中做了一些工作人員,然後使用jmsLogger.warn(XXXX)的。

我曾經做過一個線程轉儲我的應用程序,我注意到以下阻斷工作人員:?

"Log4j2-AsyncLogger[[email protected]]1" - Thread [email protected] 
    java.lang.Thread.State: WAITING 
    at sun.misc.Unsafe.park(Native Method) 
    - parking to wait for <324492ea> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject) 
    at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) 
    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039) 
    at java.util.concurrent.ArrayBlockingQueue.take(ArrayBlockingQueue.java:403) 
    at org.apache.activemq.transport.FutureResponse.getResult(FutureResponse.java:40) 
    at org.apache.activemq.transport.ResponseCorrelator.request(ResponseCorrelator.java:87) 
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1366) 
    at org.apache.activemq.ActiveMQConnection.syncSendPacket(ActiveMQConnection.java:1305) 
    at org.apache.activemq.ActiveMQSession.send(ActiveMQSession.java:1795) 
    - locked <1af6596a> (a java.lang.Object) 
    at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:277) 
    at org.apache.activemq.ActiveMQMessageProducer.send(ActiveMQMessageProducer.java:212) 
    at org.apache.activemq.ActiveMQMessageProducerSupport.send(ActiveMQMessageProducerSupport.java:241) 
    at org.apache.logging.log4j.core.appender.mom.JmsAppender.append(JmsAppender.java:65) 
    at org.apache.logging.log4j.core.config.AppenderControl.tryCallAppender(AppenderControl.java:155) 
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender0(AppenderControl.java:128) 
    at org.apache.logging.log4j.core.config.AppenderControl.callAppenderPreventRecursion(AppenderControl.java:119) 
    at org.apache.logging.log4j.core.config.AppenderControl.callAppender(AppenderControl.java:84) 
    at org.apache.logging.log4j.core.config.LoggerConfig.callAppenders(LoggerConfig.java:390) 
    at org.apache.logging.log4j.core.config.LoggerConfig.processLogEvent(LoggerConfig.java:375) 
    at org.apache.logging.log4j.core.config.LoggerConfig.log(LoggerConfig.java:359) 
    at org.apache.logging.log4j.core.config.AwaitCompletionReliabilityStrategy.log(AwaitCompletionReliabilityStrategy.java:79) 
    at org.apache.logging.log4j.core.async.AsyncLogger.actualAsyncLog(AsyncLogger.java:310) 
    at org.apache.logging.log4j.core.async.RingBufferLogEvent.execute(RingBufferLogEvent.java:149) 
    at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:45) 
    at org.apache.logging.log4j.core.async.RingBufferLogEventHandler.onEvent(RingBufferLogEventHandler.java:29) 
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:129) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 
    at java.lang.Thread.run(Thread.java:745) 

所以現在的問題是,爲什麼在發送模式時線org.apache.activemq.ActiveMQConnection.syncSendPacket 。這造成了一些阻塞問題,並降低了我的表現。

Thnks很多:)

回答

1

由於Log4j的2.7的,我不知道有任何性能基準測試使用JMS的appender記錄。大部分已發佈的基準測試都是針對文件日誌。即使在多線程應用程序中,Log4j2也可以同步記錄800K msg/sec到一個文件,持續,。異步日誌可以快多倍地處理突發事件。

相比之下,2000 msg/sec似乎不是一個非常高的數字。我猜這取決於JMS實現庫的吞吐量。

+0

是的,我試圖使用log4j 2.6實現JMSAppender。性能看起來非常好,因爲lo4j 2.6使用最新的分銷商庫。我可以在0.125ms內發送25K msg。所以這是對我的問題的迴應。我剛剛錯過了一些配置。此實現的目標是避免寫入文件並將此部分委託給其他進程(logstash elasticsearch kibana)的成本。 Thnks爲答案 – user3021914