Backend Development 8 min read

Performance Comparison of Logback and Log4j2 Synchronous vs Asynchronous Logging

This article revisits a previous logback configuration test, expands the sample size and repeats the measurements using JMeter, JProfile, and New Relic APM to compare synchronous and asynchronous logging in Logback and Log4j2, revealing that asynchronous logging reduces log latency but only marginally improves overall TPS, while Log4j2’s async implementation can boost TPS up to six times.

Architecture Digest
Architecture Digest
Architecture Digest
Performance Comparison of Logback and Log4j2 Synchronous vs Asynchronous Logging

Preface

Earlier I published an article titled "Logback configuration file written this way, TPS increased 10×" which received many comments from readers.

Below are some of the opinions (images omitted for brevity).

Logback performance test shows little difference between synchronous and asynchronous TPS.

Logback is still being used in 2022.

After reviewing the feedback, I conducted another round of testing and research.

Server Hardware

CPU: six cores

Memory: 8 GB

Testing Tools

JMeter

JProfile

APM (New Relic)

Logback Synchronous vs Asynchronous Test

The previous test had several shortcomings:

Too few samples (only 100 threads with a single loop, total 100 requests).

Only one test run, making results prone to randomness.

Inconsistent sample sizes between runs, causing pollution.

In the new test, the thread count was increased to 200, each thread looped 100 times (total 20 000 requests), and the test was repeated five times. The results are shown in the following chart:

The new data indicate that the TPS difference between synchronous and asynchronous logging in Logback is minimal.

However, I expected asynchronous logging to free API‑handling threads and thus noticeably increase TPS. To verify this, I monitored the requests with APM while using the same JMeter settings ( JMeter threads=100, ramp‑up=0, loops=100):

APM monitoring showed an average TPS of 378 rpm for asynchronous logging over five minutes.

For synchronous logging, the average TPS was 333 rpm, still not a dramatic difference.

The reason TPS does not change significantly is that TPS measures the total number of transactions per second, each consisting of three stages:

User request to the server

Server's internal processing (database access, business logic, logging)

Server response back to the user

Logging accounts for only about 5.3 % of the total request time, so reducing log latency has little impact on overall TPS, though it does shorten the logging portion.

Recommendation to Use Log4j2 Instead of Logback

Log4j2, the successor to Log4j 1.x, incorporates many of Logback’s good designs and adds major improvements, especially in asynchronous logging. It offers two async models: AsyncAppender (similar to Logback’s async) and AsyncLogger, which is built on the LMAX Disruptor library for high‑performance logging.

In this test, the AsyncLogger implementation was used. The test parameters matched the Logback test (200 threads, 100 loops, 5 repetitions) and the Log4j2 configuration mirrored the Logback async settings, providing:

Console output

Categorized log files

Daily rolling

Identical log format

When the results are plotted, TPS increased by roughly six times, and the time spent on logging became negligible.

TPS improved sixfold! Official benchmark reports also confirm that Log4j2 outperforms Logback by a large margin.

Conclusion

If you continue using Logback, enable asynchronous logging.

For the best performance, switch to Log4j2.

Recommended Reading

TCP Three‑Way Handshake and Four‑Way Teardown Explained

Three MySQL Large‑Table Optimization Strategies

Query Speed Up 200× with ClickHouse

Why Redis Is More Popular Than Memcached

Step‑by‑Step Guide to Building High‑Performance Services with OpenResty

Javaperformance testingLogbacklog4j2asynchronous logging
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.