Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LogbackMDCAdapter Performance #812

Open
mosesn opened this issue May 6, 2024 · 1 comment
Open

LogbackMDCAdapter Performance #812

mosesn opened this issue May 6, 2024 · 1 comment

Comments

@mosesn
Copy link

mosesn commented May 6, 2024

Problem

We've been using LogbackMDCAdapter, but recently found that it's copying around a lot of hashmaps. We're currently trying out LogbackMDCAdapterSimple, and it seems better and we found that it does even more copying.

Question

Why does Logback provide both LogbackMDCAdapterSimple and LogbackMDCAdapter? Would you consider just consolidating on LogbackMDCAdapterSimple?

Proposed Improvement

Since LogbackMDCAdapterSimple uses a thread local, it doesn't seem like it actually needs to use copy-on-write semantics to keep the map safe. What about using a simple ThreadLocal<Map<String, String>> where the map is mutable and we update it directly?

Result

We require fewer intermediate data structures as we assemble MDC.

@ceki
Copy link
Member

ceki commented May 10, 2024

@mosesn The MDC map is copied into LoggingEvent instances which may be handed to different threads, e.g. AsyncAppender's dispatcher thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants