Skip to content

Is the Garbage-free mode enabled by default? #3375

@lushi516

Description

@lushi516

I reviewed the garbagefree documentation, and it states that the Garbage-free mode requires additional configuration and activation. However, when I tested the logback-perf code, I noticed that even with the default configuration and extensive logging output, it did not trigger any GC (Garbage Collection).

perf result

Benchmark                                                           Mode  Cnt    Score   Error   Units
AsyncWithFileAppenderBenchmark.log4j2AsyncFile                     thrpt    2  170.888          ops/ms
AsyncWithFileAppenderBenchmark.log4j2AsyncFile:gc.alloc.rate       thrpt    2   ≈ 10??          MB/sec
AsyncWithFileAppenderBenchmark.log4j2AsyncFile:gc.alloc.rate.norm  thrpt    2    0.002            B/op
AsyncWithFileAppenderBenchmark.log4j2AsyncFile:gc.count            thrpt    2      ≈ 0          counts
AsyncWithFileAppenderBenchmark.logbackFile                         thrpt    2  209.157          ops/ms
AsyncWithFileAppenderBenchmark.logbackFile:gc.alloc.rate           thrpt    2  181.193          MB/sec
AsyncWithFileAppenderBenchmark.logbackFile:gc.alloc.rate.norm      thrpt    2  908.393            B/op
AsyncWithFileAppenderBenchmark.logbackFile:gc.count                thrpt    2   36.000          counts
AsyncWithFileAppenderBenchmark.logbackFile:gc.time                 thrpt    2   44.000              ms
FileAppenderBenchmark.log4j2File                                   thrpt    2  126.649          ops/ms
FileAppenderBenchmark.log4j2File:gc.alloc.rate                     thrpt    2   ≈ 10??          MB/sec
FileAppenderBenchmark.log4j2File:gc.alloc.rate.norm                thrpt    2    0.003            B/op
FileAppenderBenchmark.log4j2File:gc.count                          thrpt    2      ≈ 0          counts
FileAppenderBenchmark.logbackFile                                  thrpt    2  121.266          ops/ms
FileAppenderBenchmark.logbackFile:gc.alloc.rate                    thrpt    2   94.102          MB/sec
FileAppenderBenchmark.logbackFile:gc.alloc.rate.norm               thrpt    2  813.717            B/op
FileAppenderBenchmark.logbackFile:gc.count                         thrpt    2   19.000          counts
FileAppenderBenchmark.logbackFile:gc.time                          thrpt    2   26.000              ms

Is the Garbage-free mode activated by default? Is it possible to inspect through Log4j2's own logs?

PS:

(1) jdk and log4j2 verison is 1.8.171 and 2.24.3

(2)log4j2.xml

<Configuration name="log4j2PerfTest" status="trace">

	<Appenders>

		<File name="RandomAccessFile"
			fileName="target/test-output/log4j2-perf.log" immediateFlush="false"
			append="false" bufferSize="262144">
			<PatternLayout>
				<Pattern>%d %p [%t] %logger - %m%n</Pattern>
			</PatternLayout>
		</File>


	</Appenders>

	<Loggers>
		<Root level="debug">
			<AppenderRef ref="RandomAccessFile" />
		</Root>
	</Loggers>
</Configuration>

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions