spring-attic / spring-native

Spring Native is now superseded by Spring Boot 3 official native support
https://docs.spring.io/spring-boot/docs/current/reference/html/native-image.html
Apache License 2.0
2.74k stars 355 forks source link

Add Hints for Lmax Disruptor #1691

Closed thekalinga closed 2 years ago

thekalinga commented 2 years ago

In reactive world, when dealing with log4j2, lmax disruptor library is recommended to ensure the logging doesnt affect event loop threads.

Async logging is typically have log4j2.xml of this format (for file appending).

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
    <Properties>
        <Property name="LOG_EXCEPTION_CONVERSION_WORD">%xwEx</Property>
        <Property name="LOG_LEVEL_PATTERN">%5p</Property>
        <Property name="LOG_DATEFORMAT_PATTERN">yyyy-MM-dd HH:mm:ss.SSS</Property>
        <Property name="CONSOLE_LOG_PATTERN">%clr{%d{${LOG_DATEFORMAT_PATTERN}}}{faint} %clr{${LOG_LEVEL_PATTERN}} %clr{%pid}{magenta} %clr{---}{faint} %clr{[%15.15t]}{faint} %clr{%-40.40c{1.}}{cyan} %clr{:}{faint} %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
        <Property name="FILE_LOG_PATTERN">%d{${LOG_DATEFORMAT_PATTERN}} ${LOG_LEVEL_PATTERN} %pid --- [%t] %-40.40c{1.} : %m%n${sys:LOG_EXCEPTION_CONVERSION_WORD}</Property>
    </Properties>
    <Appenders>
        <Console name="Console" target="SYSTEM_OUT" follow="true">
            <PatternLayout pattern="${sys:CONSOLE_LOG_PATTERN}" />
        </Console>
        <RollingRandomAccessFile name="RollingRandomAccessFile" fileName="logs/app.log"
                                 filePattern="logs/$${date:yyyy-MM}/app-%d{MM-dd-yyyy}-%i.log.gz"
                                 immediateFlush="false">
            <Policies>
                <SizeBasedTriggeringPolicy size="10 MB"/>
            </Policies>
            <DefaultRolloverStrategy max="10"/>
            <PatternLayout pattern="${sys:FILE_LOG_PATTERN}" />
        </RollingRandomAccessFile>
    </Appenders>
    <Loggers>
        <AsyncLogger name="com.acme" level="info" additivity="false">
            <AppenderRef ref="Console" />
            <AppenderRef ref="RollingRandomAccessFile"/>
        </AsyncLogger>
        <AsyncRoot level="info">
            <AppenderRef ref="Console" />
            <AppenderRef ref="RollingRandomAccessFile"/>
        </AsyncRoot>
    </Loggers>
</Configuration>

with following dependency

implementation("com.lmax:disruptor:3.4.4")

It would be nice if the spring native automatically adds appropriate graal hints so that user's experience can be smooth when using disruptor.

thekalinga commented 2 years ago

I believe graal vm has an unresolved issue wrt RandomAccessFile. Altho, that should affect only file appenders, I believe it should not affect disruptor.

sdeleuze commented 2 years ago

I dropped a comment on this issue to ask current status since it is not clear.

Lmax disruptor support should be contributed to https://github.com/oracle/graalvm-reachability-metadata in order to be available via Native Build Tools 0.9.13+ (usable with Spring Native) and upcoming native support in Spring Boot 3.