flume appender问题:当flume代理在大量日志记录期间关闭时,应用程序线程被卡住

enxuqcxy  于 2021-06-04  发布在  Flume
关注(0)|答案(1)|浏览(642)

我们目前使用的是低于log4j的jar
log4j-core-2.6.2、log4j-flume-ng-2.6.2

<Flume name="aggregatorApp" compress="false" type="Avro"
ignoreExceptions="true" batchSize="10" blocking="false" >
<Agent host="${flumeHostPrimary}" port="${flumePortPrimary}" />
<Agent host="${flumeHostSecondary}" port="${flumePortSecondary}" />
<FlumeEventFactory logType="APPLICATION"/>
<PatternLayout header="app" pattern="[%-5p] %d %c %X{correlationId} - %m" />

<AsyncLogger name="com.xyz.abc" level="debug"
additivity="false" blocking="false">
<AppenderRef ref="IDRESTSERVICELOG" />
<AppenderRef ref="aggregatorApp" level="INFO" />
<AppenderRef ref="CONSOLE" level="INFO"/>
</AsyncLogger>

当flume代理启动并运行时,应用程序运行平稳,日志事件成功发布到flume代理
如果flume代理停止运行一段时间,应用程序线程就会出现以下异常
 

Exception in thread "elasticsearch[_client_][generic][T#3]" java.lang.OutOfMemoryError: GC overhead limit exceeded
2019-02-01 07:43:23,618 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] WARN  org.apache.catalina.valves.StuckThreadDetectionValve- Thread "http-apr-8080-exec-7" (id=167) has been active for 20,392 milliseconds (since 2/1/19 7:42 AM) to serve the same request for htpps://xyz//directories/v1.0/search and may be stuck (configured threshold for this StuckThreadDetectionValve is 20 seconds). There is/are 1 thread(s) in total that are monitored by this Valve and may be stuck.
2019-02-01 07:46:18,619 [ContainerBackgroundProcessor[StandardEngine[Catalina]]] ERROR org.apache.catalina.core.ContainerBase- Unexpected death of background thread ContainerBackgroundProcessor[StandardEngine[Catalina]]
java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "http-apr-8080-exec-42" java.lang.OutOfMemoryError: GC overhead limit exceeded
Exception in thread "http-apr-8080-exec-50" Exception in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]" Exception in thread "I/O dispatcher 23" 
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "ContainerBackgroundProcessor[StandardEngine[Catalina]]"
Exception in thread "http-apr-8080-exec-38" Exception in thread "http-apr-8080-exec-46" Exception in thread "http-apr-8080-exec-53" Exception in thread "I/O dispatcher 17" 
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "http-apr-8080-exec-31"

以上异常在重载期间发生(每个请求记录1mb日志)注意:我们正在进行负载测试
由于应用程序日志记录量很大,但flume appender不能以同样的速度使用。我们怀疑log4j环缓冲区已满,这会阻塞应用程序线程并产生内存不足异常。
考虑到log4j appenders有问题,我们尝试了几次行动,
-dlog4j2.asyncqueuefullpolicy=discard-dlog4j2.enable.threadlocals=true-dlog4j2.enable.direct.encoders=true
但上述系统属性没有任何用处。我们错过什么了吗?

jvidinwx

jvidinwx1#

我同意asynclogger的ringbuffer导致内存不足。环形缓冲区的默认大小是256k个条目。jvm的堆大小是多少?
另一种方法是使用flumeappender的嵌入或持久变体。这些将在转发到flume代理之前在本地文件通道中缓存事件。这将允许您通过调整可用磁盘空间的大小来控制服务器能够承受停机的时间。您仍将获得异步记录器的优势,但可以避免中断。

相关问题