gpt4 book ai didi

java - 使用 JMSAppender log4j2 每秒发送 2000 条消息

转载 作者:行者123 更新时间:2023-12-01 09:08:58 25 4
gpt4 key购买 nike

我正在尝试使用 JMSAppender log4j2 将日志发送到 ActivMQ。

我已经完成了以下配置

<?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[AsyncContext@14dad5dc]1" - Thread t@27
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。这导致了一些阻塞问题并降低了我的性能。

非常感谢:)

最佳答案

从 Log4j 2.7 开始,我不知道使用 JMS 附加程序进行日志记录的任何性能基准。大多数已发布的基准测试都是针对文件日志记录的。 Log4j2 可以将 800K 消息/秒持续同步记录到文件中,即使在多线程应用程序中也是如此。异步日志记录可以以数倍的速度处理突发。

相比之下,2000 条消息/秒似乎并不是一个很高的数字。我猜这将取决于 JMS 实现库的吞吐量。

关于java - 使用 JMSAppender log4j2 每秒发送 2000 条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41044602/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com