-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Performance optimization in CloseableThreadContext.closeMap() (#2292) #2296
Conversation
log4j-api/src/main/java/org/apache/logging/log4j/CloseableThreadContext.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jengebr, thanks so much! Would you mind adding a changelog entry (i.e., src/changelog/.2.x.x/improve_CloseableThreadContext_closeMap.xml
) too, please?
Thank you for your contribution. Personally I think there is an inherent problem in the way Since you pointed out that
This might require API changes, that I am more than willing to accept, but it should give better results: closing Unfortunately there are 3 implementations of
In order to work with all 3, |
@vy thanks for adding the finals! I've added the changelog entry under 2.24.0, which matches the milestone, hopefully that's correct. @ppkarwasz I like the garbage-free proposal but I don't think I'm up for that - not enough familiarity with the log4j codebase or designs. I am however able to performance test and profile such changes in a real-life, heavy-load environment, and am happy to help in that way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@jengebr, even if we manage to further optimize the process, your implementation gives us a better alternative to compete with.
src/changelog/2.24.0/improve_CloseableThreadContext_closeMap.xml
Outdated
Show resolved
Hide resolved
@jengebr, could you move the changelog file to |
@vy done, I think - and sorry, my IDE was hiding that folder and I misunderstood the intent. I kept the change you made (thanks for that!). |
@ppkarwasz - fyi, our conversation above sparked an idea for improving DefaultThreadContextMap. I opened #2319 to discuss further, including an implementation and benchmark. |
This substantially improves the performance of CloseableThreadContext.closeMap(), reducing the aggregate create/close cost by 40% or 20%, depending on the ThreadContext implementation in use. Further performance explanation is on the related issue,
#2292
Checklist
2.x
branch if you are targeting Log4j 2; usemain
otherwise./mvnw verify
succeeds (if it fails due to code formatting issues reported by Spotless, simply run./mvnw spotless:apply
and retry)src/changelog/.2.x.x
directory